PageRenderTime 68ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/src/View/Helper/FormHelper.php

https://github.com/binondord/cakephp
PHP | 2575 lines | 1385 code | 216 blank | 974 comment | 236 complexity | 88c3f729081cad2b3d1db5f86806f282 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 0.10.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\View\Helper;
  16. use Cake\Collection\Collection;
  17. use Cake\Core\Configure;
  18. use Cake\Core\Exception\Exception;
  19. use Cake\Form\Form;
  20. use Cake\ORM\Entity;
  21. use Cake\Routing\Router;
  22. use Cake\Utility\Hash;
  23. use Cake\Utility\Inflector;
  24. use Cake\Utility\Security;
  25. use Cake\View\Form\ArrayContext;
  26. use Cake\View\Form\ContextInterface;
  27. use Cake\View\Form\EntityContext;
  28. use Cake\View\Form\FormContext;
  29. use Cake\View\Form\NullContext;
  30. use Cake\View\Helper;
  31. use Cake\View\Helper\IdGeneratorTrait;
  32. use Cake\View\StringTemplateTrait;
  33. use Cake\View\View;
  34. use Cake\View\Widget\WidgetRegistry;
  35. use DateTime;
  36. use RuntimeException;
  37. use Traversable;
  38. /**
  39. * Form helper library.
  40. *
  41. * Automatic generation of HTML FORMs from given data.
  42. *
  43. * @property HtmlHelper $Html
  44. * @link http://book.cakephp.org/3.0/en/views/helpers/form.html
  45. */
  46. class FormHelper extends Helper
  47. {
  48. use IdGeneratorTrait;
  49. use StringTemplateTrait;
  50. /**
  51. * Other helpers used by FormHelper
  52. *
  53. * @var array
  54. */
  55. public $helpers = ['Url', 'Html'];
  56. /**
  57. * The various pickers that make up a datetime picker.
  58. *
  59. * @var array
  60. */
  61. protected $_datetimeParts = ['year', 'month', 'day', 'hour', 'minute', 'second', 'meridian'];
  62. /**
  63. * Special options used for datetime inputs.
  64. *
  65. * @var array
  66. */
  67. protected $_datetimeOptions = [
  68. 'interval', 'round', 'monthNames', 'minYear', 'maxYear',
  69. 'orderYear', 'timeFormat', 'second'
  70. ];
  71. /**
  72. * Default config for the helper.
  73. *
  74. * @var array
  75. */
  76. protected $_defaultConfig = [
  77. 'idPrefix' => null,
  78. 'errorClass' => 'form-error',
  79. 'typeMap' => [
  80. 'string' => 'text', 'datetime' => 'datetime', 'boolean' => 'checkbox',
  81. 'timestamp' => 'datetime', 'text' => 'textarea', 'time' => 'time',
  82. 'date' => 'date', 'float' => 'number', 'integer' => 'number',
  83. 'decimal' => 'number', 'binary' => 'file', 'uuid' => 'string'
  84. ],
  85. 'templates' => [
  86. 'button' => '<button{{attrs}}>{{text}}</button>',
  87. 'checkbox' => '<input type="checkbox" name="{{name}}" value="{{value}}"{{attrs}}>',
  88. 'checkboxFormGroup' => '{{label}}',
  89. 'checkboxWrapper' => '<div class="checkbox">{{label}}</div>',
  90. 'dateWidget' => '{{year}}{{month}}{{day}}{{hour}}{{minute}}{{second}}{{meridian}}',
  91. 'error' => '<div class="error-message">{{content}}</div>',
  92. 'errorList' => '<ul>{{content}}</ul>',
  93. 'errorItem' => '<li>{{text}}</li>',
  94. 'file' => '<input type="file" name="{{name}}"{{attrs}}>',
  95. 'fieldset' => '<fieldset{{attrs}}>{{content}}</fieldset>',
  96. 'formStart' => '<form{{attrs}}>',
  97. 'formEnd' => '</form>',
  98. 'formGroup' => '{{label}}{{input}}',
  99. 'hiddenBlock' => '<div style="display:none;">{{content}}</div>',
  100. 'input' => '<input type="{{type}}" name="{{name}}"{{attrs}}>',
  101. 'inputSubmit' => '<input type="{{type}}"{{attrs}}>',
  102. 'inputContainer' => '<div class="input {{type}}{{required}}">{{content}}</div>',
  103. 'inputContainerError' => '<div class="input {{type}}{{required}} error">{{content}}{{error}}</div>',
  104. 'label' => '<label{{attrs}}>{{text}}</label>',
  105. 'nestingLabel' => '{{hidden}}<label{{attrs}}>{{input}}{{text}}</label>',
  106. 'legend' => '<legend>{{text}}</legend>',
  107. 'option' => '<option value="{{value}}"{{attrs}}>{{text}}</option>',
  108. 'optgroup' => '<optgroup label="{{label}}"{{attrs}}>{{content}}</optgroup>',
  109. 'select' => '<select name="{{name}}"{{attrs}}>{{content}}</select>',
  110. 'selectMultiple' => '<select name="{{name}}[]" multiple="multiple"{{attrs}}>{{content}}</select>',
  111. 'radio' => '<input type="radio" name="{{name}}" value="{{value}}"{{attrs}}>',
  112. 'radioWrapper' => '{{label}}',
  113. 'textarea' => '<textarea name="{{name}}"{{attrs}}>{{value}}</textarea>',
  114. 'submitContainer' => '<div class="submit">{{content}}</div>',
  115. ]
  116. ];
  117. /**
  118. * Default widgets
  119. *
  120. * @var array
  121. */
  122. protected $_defaultWidgets = [
  123. 'button' => ['Cake\View\Widget\ButtonWidget'],
  124. 'checkbox' => ['Cake\View\Widget\CheckboxWidget'],
  125. 'file' => ['Cake\View\Widget\FileWidget'],
  126. 'label' => ['Cake\View\Widget\LabelWidget'],
  127. 'nestingLabel' => ['Cake\View\Widget\NestingLabelWidget'],
  128. 'multicheckbox' => ['Cake\View\Widget\MultiCheckboxWidget', 'nestingLabel'],
  129. 'radio' => ['Cake\View\Widget\RadioWidget', 'nestingLabel'],
  130. 'select' => ['Cake\View\Widget\SelectBoxWidget'],
  131. 'textarea' => ['Cake\View\Widget\TextareaWidget'],
  132. 'datetime' => ['Cake\View\Widget\DateTimeWidget', 'select'],
  133. '_default' => ['Cake\View\Widget\BasicWidget'],
  134. ];
  135. /**
  136. * List of fields created, used with secure forms.
  137. *
  138. * @var array
  139. */
  140. public $fields = [];
  141. /**
  142. * Constant used internally to skip the securing process,
  143. * and neither add the field to the hash or to the unlocked fields.
  144. *
  145. * @var string
  146. */
  147. const SECURE_SKIP = 'skip';
  148. /**
  149. * Defines the type of form being created. Set by FormHelper::create().
  150. *
  151. * @var string
  152. */
  153. public $requestType = null;
  154. /**
  155. * An array of field names that have been excluded from
  156. * the Token hash used by SecurityComponent's validatePost method
  157. *
  158. * @see FormHelper::_secure()
  159. * @see SecurityComponent::validatePost()
  160. * @var array
  161. */
  162. protected $_unlockedFields = [];
  163. /**
  164. * Registry for input widgets.
  165. *
  166. * @var \Cake\View\Widget\WidgetRegistry
  167. */
  168. protected $_registry;
  169. /**
  170. * Context for the current form.
  171. *
  172. * @var \Cake\View\Form\ContextInterface
  173. */
  174. protected $_context;
  175. /**
  176. * Context provider methods.
  177. *
  178. * @var array
  179. * @see addContextProvider
  180. */
  181. protected $_contextProviders = [];
  182. /**
  183. * The action attribute value of the last created form.
  184. * Used to make form/request specific hashes for SecurityComponent.
  185. *
  186. * @var string
  187. */
  188. protected $_lastAction = '';
  189. /**
  190. * Construct the widgets and binds the default context providers
  191. *
  192. * @param \Cake\View\View $View The View this helper is being attached to.
  193. * @param array $config Configuration settings for the helper.
  194. */
  195. public function __construct(View $View, array $config = [])
  196. {
  197. $registry = null;
  198. $widgets = $this->_defaultWidgets;
  199. if (isset($config['registry'])) {
  200. $registry = $config['registry'];
  201. unset($config['registry']);
  202. }
  203. if (isset($config['widgets'])) {
  204. if (is_string($config['widgets'])) {
  205. $config['widgets'] = (array)$config['widgets'];
  206. }
  207. $widgets = $config['widgets'] + $widgets;
  208. unset($config['widgets']);
  209. }
  210. parent::__construct($View, $config);
  211. $this->widgetRegistry($registry, $widgets);
  212. $this->_addDefaultContextProviders();
  213. $this->_idPrefix = $this->config('idPrefix');
  214. }
  215. /**
  216. * Set the widget registry the helper will use.
  217. *
  218. * @param \Cake\View\Widget\WidgetRegistry $instance The registry instance to set.
  219. * @param array $widgets An array of widgets
  220. * @return \Cake\View\Widget\WidgetRegistry
  221. */
  222. public function widgetRegistry(WidgetRegistry $instance = null, $widgets = [])
  223. {
  224. if ($instance === null) {
  225. if ($this->_registry === null) {
  226. $this->_registry = new WidgetRegistry($this->templater(), $this->_View, $widgets);
  227. }
  228. return $this->_registry;
  229. }
  230. $this->_registry = $instance;
  231. return $this->_registry;
  232. }
  233. /**
  234. * Add the default suite of context providers provided by CakePHP.
  235. *
  236. * @return void
  237. */
  238. protected function _addDefaultContextProviders()
  239. {
  240. $this->addContextProvider('orm', function ($request, $data) {
  241. if (is_array($data['entity']) || $data['entity'] instanceof Traversable) {
  242. $pass = (new Collection($data['entity']))->first() !== null;
  243. if ($pass) {
  244. return new EntityContext($request, $data);
  245. }
  246. }
  247. if ($data['entity'] instanceof Entity) {
  248. return new EntityContext($request, $data);
  249. }
  250. if (is_array($data['entity']) && empty($data['entity']['schema'])) {
  251. return new EntityContext($request, $data);
  252. }
  253. });
  254. $this->addContextProvider('form', function ($request, $data) {
  255. if ($data['entity'] instanceof Form) {
  256. return new FormContext($request, $data);
  257. }
  258. });
  259. $this->addContextProvider('array', function ($request, $data) {
  260. if (is_array($data['entity']) && isset($data['entity']['schema'])) {
  261. return new ArrayContext($request, $data['entity']);
  262. }
  263. });
  264. }
  265. /**
  266. * Returns if a field is required to be filled based on validation properties from the validating object.
  267. *
  268. * @param \Cake\Validation\ValidationSet $validationRules Validation rules set.
  269. * @return bool true if field is required to be filled, false otherwise
  270. */
  271. protected function _isRequiredField($validationRules)
  272. {
  273. if (empty($validationRules) || count($validationRules) === 0) {
  274. return false;
  275. }
  276. $validationRules->isUpdate($this->requestType === 'put');
  277. foreach ($validationRules as $rule) {
  278. if ($rule->skip()) {
  279. continue;
  280. }
  281. return !$validationRules->isEmptyAllowed();
  282. }
  283. return false;
  284. }
  285. /**
  286. * Returns an HTML FORM element.
  287. *
  288. * ### Options:
  289. *
  290. * - `type` Form method defaults to autodetecting based on the form context. If
  291. * the form context's isCreate() method returns false, a PUT request will be done.
  292. * - `action` The controller action the form submits to, (optional). Use this option if you
  293. * don't need to change the controller from the current request's controller.
  294. * - `url` The URL the form submits to. Can be a string or a URL array. If you use 'url'
  295. * you should leave 'action' undefined.
  296. * - `encoding` Set the accept-charset encoding for the form. Defaults to `Configure::read('App.encoding')`
  297. * - `templates` The templates you want to use for this form. Any templates will be merged on top of
  298. * the already loaded templates. This option can either be a filename in /config that contains
  299. * the templates you want to load, or an array of templates to use.
  300. * - `context` Additional options for the context class. For example the EntityContext accepts a 'table'
  301. * option that allows you to set the specific Table class the form should be based on.
  302. * - `idPrefix` Prefix for generated ID attributes.
  303. *
  304. * @param mixed $model The context for which the form is being defined. Can
  305. * be an ORM entity, ORM resultset, or an array of meta data. You can use false or null
  306. * to make a model-less form.
  307. * @param array $options An array of html attributes and options.
  308. * @return string An formatted opening FORM tag.
  309. * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#Cake\View\Helper\FormHelper::create
  310. */
  311. public function create($model = null, array $options = [])
  312. {
  313. $append = '';
  314. if (empty($options['context'])) {
  315. $options['context'] = [];
  316. }
  317. $options['context']['entity'] = $model;
  318. $context = $this->_getContext($options['context']);
  319. unset($options['context']);
  320. $isCreate = $context->isCreate();
  321. $options += [
  322. 'type' => $isCreate ? 'post' : 'put',
  323. 'action' => null,
  324. 'url' => null,
  325. 'encoding' => strtolower(Configure::read('App.encoding')),
  326. 'templates' => null,
  327. 'idPrefix' => null,
  328. ];
  329. if ($options['idPrefix'] !== null) {
  330. $this->_idPrefix = $options['idPrefix'];
  331. }
  332. $templater = $this->templater();
  333. if (!empty($options['templates'])) {
  334. $templater->push();
  335. $method = is_string($options['templates']) ? 'load' : 'add';
  336. $templater->{$method}($options['templates']);
  337. }
  338. unset($options['templates']);
  339. if ($options['action'] === false || $options['url'] === false) {
  340. $url = $this->request->here(false);
  341. $action = null;
  342. } else {
  343. $url = $this->_formUrl($context, $options);
  344. $action = $this->Url->build($url);
  345. }
  346. $this->_lastAction($url);
  347. unset($options['url'], $options['action'], $options['idPrefix']);
  348. $htmlAttributes = [];
  349. switch (strtolower($options['type'])) {
  350. case 'get':
  351. $htmlAttributes['method'] = 'get';
  352. break;
  353. // Set enctype for form
  354. case 'file':
  355. $htmlAttributes['enctype'] = 'multipart/form-data';
  356. $options['type'] = ($isCreate) ? 'post' : 'put';
  357. // Move on
  358. case 'post':
  359. // Move on
  360. case 'put':
  361. // Move on
  362. case 'delete':
  363. // Set patch method
  364. case 'patch':
  365. $append .= $this->hidden('_method', [
  366. 'name' => '_method',
  367. 'value' => strtoupper($options['type']),
  368. 'secure' => static::SECURE_SKIP
  369. ]);
  370. // Default to post method
  371. default:
  372. $htmlAttributes['method'] = 'post';
  373. }
  374. $this->requestType = strtolower($options['type']);
  375. if (!empty($options['encoding'])) {
  376. $htmlAttributes['accept-charset'] = $options['encoding'];
  377. }
  378. unset($options['type'], $options['encoding']);
  379. $htmlAttributes += $options;
  380. $this->fields = [];
  381. if ($this->requestType !== 'get') {
  382. $append .= $this->_csrfField();
  383. }
  384. if (!empty($append)) {
  385. $append = $templater->format('hiddenBlock', ['content' => $append]);
  386. }
  387. $actionAttr = $templater->formatAttributes(['action' => $action, 'escape' => false]);
  388. return $templater->format('formStart', [
  389. 'attrs' => $templater->formatAttributes($htmlAttributes) . $actionAttr
  390. ]) . $append;
  391. }
  392. /**
  393. * Create the URL for a form based on the options.
  394. *
  395. * @param \Cake\View\Form\ContextInterface $context The context object to use.
  396. * @param array $options An array of options from create()
  397. * @return string The action attribute for the form.
  398. */
  399. protected function _formUrl($context, $options)
  400. {
  401. if ($options['action'] === null && $options['url'] === null) {
  402. return $this->request->here(false);
  403. }
  404. if (is_string($options['url']) ||
  405. (is_array($options['url']) && isset($options['url']['_name']))
  406. ) {
  407. return $options['url'];
  408. }
  409. if (isset($options['action']) && empty($options['url']['action'])) {
  410. $options['url']['action'] = $options['action'];
  411. }
  412. $actionDefaults = [
  413. 'plugin' => $this->plugin,
  414. 'controller' => $this->request->params['controller'],
  415. 'action' => $this->request->params['action'],
  416. ];
  417. $action = (array)$options['url'] + $actionDefaults;
  418. $pk = $context->primaryKey();
  419. if (count($pk)) {
  420. $id = $context->val($pk[0]);
  421. }
  422. if (empty($action[0]) && isset($id)) {
  423. $action[0] = $id;
  424. }
  425. return $action;
  426. }
  427. /**
  428. * Correctly store the last created form action URL.
  429. *
  430. * @param string|array $url The URL of the last form.
  431. * @return void
  432. */
  433. protected function _lastAction($url)
  434. {
  435. $action = Router::url($url, true);
  436. $query = parse_url($action, PHP_URL_QUERY);
  437. $query = $query ? '?' . $query : '';
  438. $this->_lastAction = parse_url($action, PHP_URL_PATH) . $query;
  439. }
  440. /**
  441. * Return a CSRF input if the request data is present.
  442. * Used to secure forms in conjunction with CsrfComponent &
  443. * SecurityComponent
  444. *
  445. * @return string
  446. */
  447. protected function _csrfField()
  448. {
  449. if (!empty($this->request['_Token']['unlockedFields'])) {
  450. foreach ((array)$this->request['_Token']['unlockedFields'] as $unlocked) {
  451. $this->_unlockedFields[] = $unlocked;
  452. }
  453. }
  454. if (empty($this->request->params['_csrfToken'])) {
  455. return '';
  456. }
  457. return $this->hidden('_csrfToken', [
  458. 'value' => $this->request->params['_csrfToken'],
  459. 'secure' => static::SECURE_SKIP
  460. ]);
  461. }
  462. /**
  463. * Closes an HTML form, cleans up values set by FormHelper::create(), and writes hidden
  464. * input fields where appropriate.
  465. *
  466. * @param array $secureAttributes Secure attibutes which will be passed as HTML attributes
  467. * into the hidden input elements generated for the Security Component.
  468. * @return string A closing FORM tag.
  469. * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#closing-the-form
  470. */
  471. public function end(array $secureAttributes = [])
  472. {
  473. $out = '';
  474. if ($this->requestType !== 'get' &&
  475. !empty($this->request['_Token'])
  476. ) {
  477. $out .= $this->secure($this->fields, $secureAttributes);
  478. $this->fields = [];
  479. }
  480. $templater = $this->templater();
  481. $out .= $templater->format('formEnd', []);
  482. $templater->pop();
  483. $this->requestType = null;
  484. $this->_context = null;
  485. $this->_idPrefix = $this->config('idPrefix');
  486. return $out;
  487. }
  488. /**
  489. * Generates a hidden field with a security hash based on the fields used in
  490. * the form.
  491. *
  492. * If $secureAttributes is set, these HTML attributes will be merged into
  493. * the hidden input tags generated for the Security Component. This is
  494. * especially useful to set HTML5 attributes like 'form'.
  495. *
  496. * @param array $fields If set specifies the list of fields to use when
  497. * generating the hash, else $this->fields is being used.
  498. * @param array $secureAttributes will be passed as HTML attributes into the hidden
  499. * input elements generated for the Security Component.
  500. * @return void|string A hidden input field with a security hash
  501. */
  502. public function secure(array $fields = [], array $secureAttributes = [])
  503. {
  504. if (empty($this->request['_Token'])) {
  505. return;
  506. }
  507. $locked = [];
  508. $unlockedFields = $this->_unlockedFields;
  509. foreach ($fields as $key => $value) {
  510. if (is_numeric($value)) {
  511. $value = (string)$value;
  512. }
  513. if (!is_int($key)) {
  514. $locked[$key] = $value;
  515. unset($fields[$key]);
  516. }
  517. }
  518. sort($unlockedFields, SORT_STRING);
  519. sort($fields, SORT_STRING);
  520. ksort($locked, SORT_STRING);
  521. $fields += $locked;
  522. $locked = implode(array_keys($locked), '|');
  523. $unlocked = implode($unlockedFields, '|');
  524. $hashParts = [
  525. $this->_lastAction,
  526. serialize($fields),
  527. $unlocked,
  528. Security::salt()
  529. ];
  530. $fields = Security::hash(implode('', $hashParts), 'sha1');
  531. $tokenFields = array_merge($secureAttributes, [
  532. 'value' => urlencode($fields . ':' . $locked),
  533. ]);
  534. $out = $this->hidden('_Token.fields', $tokenFields);
  535. $tokenUnlocked = array_merge($secureAttributes, [
  536. 'value' => urlencode($unlocked),
  537. ]);
  538. $out .= $this->hidden('_Token.unlocked', $tokenUnlocked);
  539. return $this->formatTemplate('hiddenBlock', ['content' => $out]);
  540. }
  541. /**
  542. * Add to or get the list of fields that are currently unlocked.
  543. * Unlocked fields are not included in the field hash used by SecurityComponent
  544. * unlocking a field once its been added to the list of secured fields will remove
  545. * it from the list of fields.
  546. *
  547. * @param string|null $name The dot separated name for the field.
  548. * @return mixed Either null, or the list of fields.
  549. * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#working-with-securitycomponent
  550. */
  551. public function unlockField($name = null)
  552. {
  553. if ($name === null) {
  554. return $this->_unlockedFields;
  555. }
  556. if (!in_array($name, $this->_unlockedFields)) {
  557. $this->_unlockedFields[] = $name;
  558. }
  559. $index = array_search($name, $this->fields);
  560. if ($index !== false) {
  561. unset($this->fields[$index]);
  562. }
  563. unset($this->fields[$name]);
  564. }
  565. /**
  566. * Determine which fields of a form should be used for hash.
  567. * Populates $this->fields
  568. *
  569. * @param bool $lock Whether this field should be part of the validation
  570. * or excluded as part of the unlockedFields.
  571. * @param string|array $field Reference to field to be secured. Can be dot
  572. * separated string to indicate nesting or array of fieldname parts.
  573. * @param mixed $value Field value, if value should not be tampered with.
  574. * @return void
  575. */
  576. protected function _secure($lock, $field, $value = null)
  577. {
  578. if (empty($field) && $field !== '0') {
  579. return;
  580. }
  581. if (is_string($field)) {
  582. $field = Hash::filter(explode('.', $field));
  583. }
  584. foreach ($this->_unlockedFields as $unlockField) {
  585. $unlockParts = explode('.', $unlockField);
  586. if (array_values(array_intersect($field, $unlockParts)) === $unlockParts) {
  587. return;
  588. }
  589. }
  590. $field = implode('.', $field);
  591. $field = preg_replace('/(\.\d+)+$/', '', $field);
  592. if ($lock) {
  593. if (!in_array($field, $this->fields)) {
  594. if ($value !== null) {
  595. return $this->fields[$field] = $value;
  596. }
  597. $this->fields[] = $field;
  598. }
  599. } else {
  600. $this->unlockField($field);
  601. }
  602. }
  603. /**
  604. * Returns true if there is an error for the given field, otherwise false
  605. *
  606. * @param string $field This should be "modelname.fieldname"
  607. * @return bool If there are errors this method returns true, else false.
  608. * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#displaying-and-checking-errors
  609. */
  610. public function isFieldError($field)
  611. {
  612. return $this->_getContext()->hasError($field);
  613. }
  614. /**
  615. * Returns a formatted error message for given form field, '' if no errors.
  616. *
  617. * Uses the `error`, `errorList` and `errorItem` templates. The `errorList` and
  618. * `errorItem` templates are used to format multiple error messages per field.
  619. *
  620. * ### Options:
  621. *
  622. * - `escape` boolean - Whether or not to html escape the contents of the error.
  623. *
  624. * @param string $field A field name, like "modelname.fieldname"
  625. * @param string|array $text Error message as string or array of messages. If an array,
  626. * it should be a hash of key names => messages.
  627. * @param array $options See above.
  628. * @return string Formatted errors or ''.
  629. * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#displaying-and-checking-errors
  630. */
  631. public function error($field, $text = null, array $options = [])
  632. {
  633. if (substr($field, -5) === '._ids') {
  634. $field = substr($field, 0, -5);
  635. }
  636. $options += ['escape' => true];
  637. $context = $this->_getContext();
  638. if (!$context->hasError($field)) {
  639. return '';
  640. }
  641. $error = (array)$context->error($field);
  642. if (is_array($text)) {
  643. $tmp = [];
  644. foreach ($error as $e) {
  645. if (isset($text[$e])) {
  646. $tmp[] = $text[$e];
  647. } else {
  648. $tmp[] = $e;
  649. }
  650. }
  651. $text = $tmp;
  652. }
  653. if ($text !== null) {
  654. $error = $text;
  655. }
  656. if ($options['escape']) {
  657. $error = h($error);
  658. unset($options['escape']);
  659. }
  660. if (is_array($error)) {
  661. if (count($error) > 1) {
  662. $errorText = [];
  663. foreach ($error as $err) {
  664. $errorText[] = $this->formatTemplate('errorItem', ['text' => $err]);
  665. }
  666. $error = $this->formatTemplate('errorList', [
  667. 'content' => implode('', $errorText)
  668. ]);
  669. } else {
  670. $error = array_pop($error);
  671. }
  672. }
  673. return $this->formatTemplate('error', ['content' => $error]);
  674. }
  675. /**
  676. * Returns a formatted LABEL element for HTML forms.
  677. *
  678. * Will automatically generate a `for` attribute if one is not provided.
  679. *
  680. * ### Options
  681. *
  682. * - `for` - Set the for attribute, if its not defined the for attribute
  683. * will be generated from the $fieldName parameter using
  684. * FormHelper::_domId().
  685. *
  686. * Examples:
  687. *
  688. * The text and for attribute are generated off of the fieldname
  689. *
  690. * ```
  691. * echo $this->Form->label('published');
  692. * <label for="PostPublished">Published</label>
  693. * ```
  694. *
  695. * Custom text:
  696. *
  697. * ```
  698. * echo $this->Form->label('published', 'Publish');
  699. * <label for="published">Publish</label>
  700. * ```
  701. *
  702. * Custom attributes:
  703. *
  704. * ```
  705. * echo $this->Form->label('published', 'Publish', [
  706. * 'for' => 'post-publish'
  707. * ]);
  708. * <label for="post-publish">Publish</label>
  709. * ```
  710. *
  711. * Nesting an input tag:
  712. *
  713. * ```
  714. * echo $this->Form->label('published', 'Publish', [
  715. * 'for' => 'published',
  716. * 'input' => $this->text('published'),
  717. * ]);
  718. * <label for="post-publish">Publish <input type="text" name="published"></label>
  719. * ```
  720. *
  721. * If you want to nest inputs in the labels, you will need to modify the default templates.
  722. *
  723. * @param string $fieldName This should be "modelname.fieldname"
  724. * @param string $text Text that will appear in the label field. If
  725. * $text is left undefined the text will be inflected from the
  726. * fieldName.
  727. * @param array $options An array of HTML attributes.
  728. * @return string The formatted LABEL element
  729. * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#creating-labels
  730. */
  731. public function label($fieldName, $text = null, array $options = [])
  732. {
  733. if ($text === null) {
  734. $text = $fieldName;
  735. if (substr($text, -5) === '._ids') {
  736. $text = substr($text, 0, -5);
  737. }
  738. if (strpos($text, '.') !== false) {
  739. $fieldElements = explode('.', $text);
  740. $text = array_pop($fieldElements);
  741. }
  742. if (substr($text, -3) === '_id') {
  743. $text = substr($text, 0, -3);
  744. }
  745. $text = __(Inflector::humanize(Inflector::underscore($text)));
  746. }
  747. if (isset($options['for'])) {
  748. $labelFor = $options['for'];
  749. unset($options['for']);
  750. } else {
  751. $labelFor = $this->_domId($fieldName);
  752. }
  753. $attrs = $options + [
  754. 'for' => $labelFor,
  755. 'text' => $text,
  756. ];
  757. if (isset($options['input'])) {
  758. if (is_array($options['input'])) {
  759. $attrs = $options['input'] + $attrs;
  760. }
  761. return $this->widget('nestingLabel', $attrs);
  762. }
  763. return $this->widget('label', $attrs);
  764. }
  765. /**
  766. * Generate a set of inputs for `$fields`. If $fields is empty the fields of current model
  767. * will be used.
  768. *
  769. * You can customize individual inputs through `$fields`.
  770. * ```
  771. * $this->Form->allInputs([
  772. * 'name' => ['label' => 'custom label']
  773. * ]);
  774. * ```
  775. *
  776. * You can exclude fields by specifying them as false:
  777. *
  778. * ```
  779. * $this->Form->allInputs(['title' => false]);
  780. * ```
  781. *
  782. * In the above example, no field would be generated for the title field.
  783. *
  784. * @param array $fields An array of customizations for the fields that will be
  785. * generated. This array allows you to set custom types, labels, or other options.
  786. * @param array $options Options array. Valid keys are:
  787. * - `fieldset` Set to false to disable the fieldset. You can also pass an array of params to be
  788. * applied as HTML attributes to the fieldset tag. If you pass an empty array, the fieldset will
  789. * be enabled
  790. * - `legend` Set to false to disable the legend for the generated input set. Or supply a string
  791. * to customize the legend text.
  792. * @return string Completed form inputs.
  793. * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#generating-entire-forms
  794. */
  795. public function allInputs(array $fields = [], array $options = [])
  796. {
  797. $context = $this->_getContext();
  798. $modelFields = $context->fieldNames();
  799. $fields = array_merge(
  800. Hash::normalize($modelFields),
  801. Hash::normalize($fields)
  802. );
  803. return $this->inputs($fields, $options);
  804. }
  805. /**
  806. * Generate a set of inputs for `$fields` wrapped in a fieldset element.
  807. *
  808. * You can customize individual inputs through `$fields`.
  809. * ```
  810. * $this->Form->inputs([
  811. * 'name' => ['label' => 'custom label'],
  812. * 'email'
  813. * ]);
  814. * ```
  815. *
  816. * @param array $fields An array of the fields to generate. This array allows you to set custom
  817. * types, labels, or other options.
  818. * @param array $options Options array. Valid keys are:
  819. * - `fieldset` Set to false to disable the fieldset. You can also pass an array of params to be
  820. * applied as HTML attributes to the fieldset tag. If you pass an empty array, the fieldset will
  821. * be enabled
  822. * - `legend` Set to false to disable the legend for the generated input set. Or supply a string
  823. * to customize the legend text.
  824. * @return string Completed form inputs.
  825. * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#generating-entire-forms
  826. */
  827. public function inputs(array $fields, array $options = [])
  828. {
  829. $fields = Hash::normalize($fields);
  830. $out = '';
  831. foreach ($fields as $name => $opts) {
  832. if ($opts === false) {
  833. continue;
  834. }
  835. $out .= $this->input($name, (array)$opts);
  836. }
  837. return $this->fieldset($out, $options);
  838. }
  839. /**
  840. * Wrap a set of inputs in a fieldset
  841. *
  842. * @param string $fields the form inputs to wrap in a fieldset
  843. * @param array $options Options array. Valid keys are:
  844. * - `fieldset` Set to false to disable the fieldset. You can also pass an array of params to be
  845. * applied as HTML attributes to the fieldset tag. If you pass an empty array, the fieldset will
  846. * be enabled
  847. * - `legend` Set to false to disable the legend for the generated input set. Or supply a string
  848. * to customize the legend text.
  849. * @return string Completed form inputs.
  850. */
  851. public function fieldset($fields = '', array $options = [])
  852. {
  853. $fieldset = $legend = true;
  854. $context = $this->_getContext();
  855. $out = $fields;
  856. if (isset($options['legend'])) {
  857. $legend = $options['legend'];
  858. }
  859. if (isset($options['fieldset'])) {
  860. $fieldset = $options['fieldset'];
  861. }
  862. if ($legend === true) {
  863. $actionName = __d('cake', 'New %s');
  864. $isCreate = $context->isCreate();
  865. if (!$isCreate) {
  866. $actionName = __d('cake', 'Edit %s');
  867. }
  868. $modelName = Inflector::humanize(Inflector::singularize($this->request->params['controller']));
  869. $legend = sprintf($actionName, $modelName);
  870. }
  871. if ($fieldset !== false) {
  872. if ($legend) {
  873. $out = $this->formatTemplate('legend', ['text' => $legend]) . $out;
  874. }
  875. $fieldsetParams = ['content' => $out, 'attrs' => ''];
  876. if (is_array($fieldset) && !empty($fieldset)) {
  877. $fieldsetParams['attrs'] = $this->templater()->formatAttributes($fieldset);
  878. }
  879. $out = $this->formatTemplate('fieldset', $fieldsetParams);
  880. }
  881. return $out;
  882. }
  883. /**
  884. * Generates a form input element complete with label and wrapper div
  885. *
  886. * ### Options
  887. *
  888. * See each field type method for more information. Any options that are part of
  889. * $attributes or $options for the different **type** methods can be included in `$options` for input().
  890. * Additionally, any unknown keys that are not in the list below, or part of the selected type's options
  891. * will be treated as a regular HTML attribute for the generated input.
  892. *
  893. * - `type` - Force the type of widget you want. e.g. `type => 'select'`
  894. * - `label` - Either a string label, or an array of options for the label. See FormHelper::label().
  895. * - `options` - For widgets that take options e.g. radio, select.
  896. * - `error` - Control the error message that is produced. Set to `false` to disable any kind of error reporting (field
  897. * error and error messages).
  898. * - `empty` - String or boolean to enable empty select box options.
  899. * - `nestedInput` - Used with checkbox and radio inputs. Set to false to render inputs outside of label
  900. * elements. Can be set to true on any input to force the input inside the label. If you
  901. * enable this option for radio buttons you will also need to modify the default `radioWrapper` template.
  902. * - `templates` - The templates you want to use for this input. Any templates will be merged on top of
  903. * the already loaded templates. This option can either be a filename in /config that contains
  904. * the templates you want to load, or an array of templates to use.
  905. *
  906. * @param string $fieldName This should be "modelname.fieldname"
  907. * @param array $options Each type of input takes different options.
  908. * @return string Completed form widget.
  909. * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#creating-form-inputs
  910. */
  911. public function input($fieldName, array $options = [])
  912. {
  913. $options += [
  914. 'type' => null,
  915. 'label' => null,
  916. 'error' => null,
  917. 'required' => null,
  918. 'options' => null,
  919. 'templates' => [],
  920. ];
  921. $options = $this->_parseOptions($fieldName, $options);
  922. $options += ['id' => $this->_domId($fieldName)];
  923. $templater = $this->templater();
  924. $newTemplates = $options['templates'];
  925. if ($newTemplates) {
  926. $templater->push();
  927. $templateMethod = is_string($options['templates']) ? 'load' : 'add';
  928. $templater->{$templateMethod}($options['templates']);
  929. }
  930. unset($options['templates']);
  931. $error = null;
  932. $errorSuffix = '';
  933. if ($options['type'] !== 'hidden' && $options['error'] !== false) {
  934. $error = $this->error($fieldName, $options['error']);
  935. $errorSuffix = empty($error) ? '' : 'Error';
  936. unset($options['error']);
  937. }
  938. $label = $options['label'];
  939. unset($options['label']);
  940. $nestedInput = false;
  941. if ($options['type'] === 'checkbox') {
  942. $nestedInput = true;
  943. }
  944. $nestedInput = isset($options['nestedInput']) ? $options['nestedInput'] : $nestedInput;
  945. if ($nestedInput === true && $options['type'] === 'checkbox' && !array_key_exists('hiddenField', $options) && $label !== false) {
  946. $options['hiddenField'] = '_split';
  947. }
  948. $input = $this->_getInput($fieldName, $options);
  949. if ($options['type'] === 'hidden' || $options['type'] === 'submit') {
  950. if ($newTemplates) {
  951. $templater->pop();
  952. }
  953. return $input;
  954. }
  955. $label = $this->_getLabel($fieldName, compact('input', 'label', 'error', 'nestedInput') + $options);
  956. $result = $this->_groupTemplate(compact('input', 'label', 'error', 'options'));
  957. $result = $this->_inputContainerTemplate([
  958. 'content' => $result,
  959. 'error' => $error,
  960. 'errorSuffix' => $errorSuffix,
  961. 'options' => $options
  962. ]);
  963. if ($newTemplates) {
  964. $templater->pop();
  965. }
  966. return $result;
  967. }
  968. /**
  969. * Generates an group template element
  970. *
  971. * @param array $options The options for group template
  972. * @return string The generated group template
  973. */
  974. protected function _groupTemplate($options)
  975. {
  976. $groupTemplate = $options['options']['type'] . 'FormGroup';
  977. if (!$this->templater()->get($groupTemplate)) {
  978. $groupTemplate = 'formGroup';
  979. }
  980. return $this->templater()->format($groupTemplate, [
  981. 'input' => $options['input'],
  982. 'label' => $options['label'],
  983. 'error' => $options['error']
  984. ]);
  985. }
  986. /**
  987. * Generates an input container template
  988. *
  989. * @param array $options The options for input container template
  990. * @return string The generated input container template
  991. */
  992. protected function _inputContainerTemplate($options)
  993. {
  994. $inputContainerTemplate = $options['options']['type'] . 'Container' . $options['errorSuffix'];
  995. if (!$this->templater()->get($inputContainerTemplate)) {
  996. $inputContainerTemplate = 'inputContainer' . $options['errorSuffix'];
  997. }
  998. return $this->templater()->format($inputContainerTemplate, [
  999. 'content' => $options['content'],
  1000. 'error' => $options['error'],
  1001. 'required' => $options['options']['required'] ? ' required' : '',
  1002. 'type' => $options['options']['type']
  1003. ]);
  1004. }
  1005. /**
  1006. * Generates an input element
  1007. *
  1008. * @param string $fieldName the field name
  1009. * @param array $options The options for the input element
  1010. * @return string The generated input element
  1011. */
  1012. protected function _getInput($fieldName, $options)
  1013. {
  1014. switch ($options['type']) {
  1015. case 'select':
  1016. $opts = $options['options'];
  1017. unset($options['options']);
  1018. return $this->select($fieldName, $opts, $options);
  1019. case 'radio':
  1020. $opts = $options['options'];
  1021. unset($options['options']);
  1022. return $this->radio($fieldName, $opts, $options);
  1023. case 'multicheckbox':
  1024. $opts = $options['options'];
  1025. unset($options['options']);
  1026. return $this->multicheckbox($fieldName, $opts, $options);
  1027. case 'url':
  1028. $options = $this->_initInputField($fieldName, $options);
  1029. return $this->widget($options['type'], $options);
  1030. default:
  1031. return $this->{$options['type']}($fieldName, $options);
  1032. }
  1033. }
  1034. /**
  1035. * Generates input options array
  1036. *
  1037. * @param string $fieldName The name of the field to parse options for.
  1038. * @param array $options Options list.
  1039. * @return array Options
  1040. */
  1041. protected function _parseOptions($fieldName, $options)
  1042. {
  1043. $needsMagicType = false;
  1044. if (empty($options['type'])) {
  1045. $needsMagicType = true;
  1046. $options['type'] = $this->_inputType($fieldName, $options);
  1047. }
  1048. $options = $this->_magicOptions($fieldName, $options, $needsMagicType);
  1049. return $options;
  1050. }
  1051. /**
  1052. * Returns the input type that was guessed for the provided fieldName,
  1053. * based on the internal type it is associated too, its name and the
  1054. * variables that can be found in the view template
  1055. *
  1056. * @param string $fieldName the name of the field to guess a type for
  1057. * @param array $options the options passed to the input method
  1058. * @return string
  1059. */
  1060. protected function _inputType($fieldName, $options)
  1061. {
  1062. $context = $this->_getContext();
  1063. if ($context->isPrimaryKey($fieldName)) {
  1064. return 'hidden';
  1065. }
  1066. if (substr($fieldName, -3) === '_id') {
  1067. return 'select';
  1068. }
  1069. $internalType = $context->type($fieldName);
  1070. $map = $this->_config['typeMap'];
  1071. $type = isset($map[$internalType]) ? $map[$internalType] : 'text';
  1072. $fieldName = array_slice(explode('.', $fieldName), -1)[0];
  1073. switch (true) {
  1074. case isset($options['checked']):
  1075. return 'checkbox';
  1076. case isset($options['options']):
  1077. return 'select';
  1078. case in_array($fieldName, ['passwd', 'password']):
  1079. return 'password';
  1080. case in_array($fieldName, ['tel', 'telephone', 'phone']):
  1081. return 'tel';
  1082. case $fieldName === 'email':
  1083. return 'email';
  1084. case isset($options['rows']) || isset($options['cols']):
  1085. return 'textarea';
  1086. }
  1087. return $type;
  1088. }
  1089. /**
  1090. * Selects the variable containing the options for a select field if present,
  1091. * and sets the value to the 'options' key in the options array.
  1092. *
  1093. * @param string $fieldName The name of the field to find options for.
  1094. * @param array $options Options list.
  1095. * @return array
  1096. */
  1097. protected function _optionsOptions($fieldName, $options)
  1098. {
  1099. if (isset($options['options'])) {
  1100. return $options;
  1101. }
  1102. $pluralize = true;
  1103. if (substr($fieldName, -5) === '._ids') {
  1104. $fieldName = substr($fieldName, 0, -5);
  1105. $pluralize = false;
  1106. } elseif (substr($fieldName, -3) === '_id') {
  1107. $fieldName = substr($fieldName, 0, -3);
  1108. }
  1109. $fieldName = array_slice(explode('.', $fieldName), -1)[0];
  1110. $varName = Inflector::variable(
  1111. $pluralize ? Inflector::pluralize($fieldName) : $fieldName
  1112. );
  1113. $varOptions = $this->_View->get($varName);
  1114. if (!is_array($varOptions) && !($varOptions instanceof Traversable)) {
  1115. return $options;
  1116. }
  1117. if ($options['type'] !== 'radio') {
  1118. $options['type'] = 'select';
  1119. }
  1120. $options['options'] = $varOptions;
  1121. return $options;
  1122. }
  1123. /**
  1124. * Magically set option type and corresponding options
  1125. *
  1126. * @param string $fieldName The name of the field to generate options for.
  1127. * @param array $options Options list.
  1128. * @param bool $allowOverride Whether or not it is allowed for this method to
  1129. * overwrite the 'type' key in options.
  1130. * @return array
  1131. */
  1132. protected function _magicOptions($fieldName, $options, $allowOverride)
  1133. {
  1134. $context = $this->_getContext();
  1135. if (!isset($options['required']) && $options['type'] !== 'hidden') {
  1136. $options['required'] = $context->isRequired($fieldName);
  1137. }
  1138. $type = $context->type($fieldName);
  1139. $fieldDef = $context->attributes($fieldName);
  1140. if ($options['type'] === 'number' && !isset($options['step'])) {
  1141. if ($type === 'decimal' && isset($fieldDef['precision'])) {
  1142. $decimalPlaces = $fieldDef['precision'];
  1143. $options['step'] = sprintf('%.' . $decimalPlaces . 'F', pow(10, -1 * $decimalPlaces));
  1144. } elseif ($type === 'float') {
  1145. $options['step'] = 'any';
  1146. }
  1147. }
  1148. $typesWithOptions = ['text', 'number', 'radio', 'select'];
  1149. $magicOptions = (in_array($options['type'], ['radio', 'select']) || $allowOverride);
  1150. if ($magicOptions && in_array($options['type'], $typesWithOptions)) {
  1151. $options = $this->_optionsOptions($fieldName, $options);
  1152. }
  1153. if ($allowOverride && substr($fieldName, -5) === '._ids') {
  1154. $options['type'] = 'select';
  1155. if (empty($options['multiple'])) {
  1156. $options['multiple'] = true;
  1157. }
  1158. }
  1159. if ($options['type'] === 'select' && array_key_exists('step', $options)) {
  1160. unset($options['step']);
  1161. }
  1162. $autoLength = !array_key_exists('maxlength', $options)
  1163. && !empty($fieldDef['length'])
  1164. && $options['type'] !== 'select';
  1165. $allowedTypes = ['text', 'textarea', 'email', 'tel', 'url', 'search'];
  1166. if ($autoLength && in_array($options['type'], $allowedTypes)) {
  1167. $options['maxlength'] = min($fieldDef['length'], 100000);
  1168. }
  1169. if (in_array($options['type'], ['datetime', 'date', 'time', 'select'])) {
  1170. $options += ['empty' => false];
  1171. }
  1172. return $options;
  1173. }
  1174. /**
  1175. * Generate label for input
  1176. *
  1177. * @param string $fieldName The name of the field to generate label for.
  1178. * @param array $options Options list.
  1179. * @return bool|string false or Generated label element
  1180. */
  1181. protected function _getLabel($fieldName, $options)
  1182. {
  1183. if ($options['type'] === 'hidden') {
  1184. return false;
  1185. }
  1186. $label = null;
  1187. if (isset($options['label'])) {
  1188. $label = $options['label'];
  1189. }
  1190. if ($label === false && $options['type'] === 'checkbox') {
  1191. return $options['input'];
  1192. }
  1193. if ($label === false) {
  1194. return false;
  1195. }
  1196. return $this->_inputLabel($fieldName, $label, $options);
  1197. }
  1198. /**
  1199. * Extracts a single option from an options array.
  1200. *
  1201. * @param string $name The name of the option to pull out.
  1202. * @param array $options The array of options you want to extract.
  1203. * @param mixed $default The default option value
  1204. * @return mixed the contents of the option or default
  1205. */
  1206. protected function _extractOption($name, $options, $default = null)
  1207. {
  1208. if (array_key_exists($name, $options)) {
  1209. return $options[$name];
  1210. }
  1211. return $default;
  1212. }
  1213. /**
  1214. * Generate a label for an input() call.
  1215. *
  1216. * $options can contain a hash of id overrides. These overrides will be
  1217. * used instead of the generated values if present.
  1218. *
  1219. * @param string $fieldName The name of the field to generate label for.
  1220. * @param string $label Label text.
  1221. * @param array $options Options for the label element.
  1222. * @return string Generated label element
  1223. */
  1224. protected function _inputLabel($fieldName, $label, $options)
  1225. {
  1226. $labelAttributes = [];
  1227. if (is_array($label)) {
  1228. $labelText = null;
  1229. if (isset($label['text'])) {
  1230. $labelText = $label['text'];
  1231. unset($label['text']);
  1232. }
  1233. $labelAttributes = array_merge($labelAttributes, $label);
  1234. } else {
  1235. $labelText = $label;
  1236. }
  1237. $options += ['id' => null, 'input' => null, 'nestedInput' => false];
  1238. $labelAttributes['for'] = $options['id'];
  1239. $groupTypes = ['radio', 'multicheckbox', 'date', 'time', 'datetime'];
  1240. if (in_array($options['type'], $groupTypes, true)) {
  1241. $labelAttributes['for'] = false;
  1242. }
  1243. if ($options['nestedInput']) {
  1244. $labelAttributes['input'] = $options['input'];
  1245. }
  1246. return $this->label($fieldName, $labelText, $labelAttributes);
  1247. }
  1248. /**
  1249. * Creates a checkbox input widget.
  1250. *
  1251. * ### Options:
  1252. *
  1253. * - `value` - the value of the checkbox
  1254. * - `checked` - boolean indicate that this checkbox is checked.
  1255. * - `hiddenField` - boolean to indicate if you want the results of checkbox() to include
  1256. * a hidden input with a value of ''.
  1257. * - `disabled` - create a disabled input.
  1258. * - `default` - Set the default value for the checkbox. This allows you to start checkboxes
  1259. * as checked, without having to check the POST data. A matching POST data value, will overwrite
  1260. * the default value.
  1261. *
  1262. * @param string $fieldName Name of a field, like this "modelname.fieldname"
  1263. * @param array $options Array of HTML attributes.
  1264. * @return string|array An HTML text input element.
  1265. * @link http://book.cakephp.org/3.0/en/views/helpers/form.html#creating-checkboxes
  1266. */
  1267. public function checkbox($fieldName, array $options = [])
  1268. {
  1269. $opti

Large files files are truncated, but you can click here to view the full file