diff --git a/src/View/Helper/FormHelper.php b/src/View/Helper/FormHelper.php index 0df40c00..de58517e 100644 --- a/src/View/Helper/FormHelper.php +++ b/src/View/Helper/FormHelper.php @@ -70,7 +70,7 @@ class FormHelper extends CoreFormHelper * * @var array */ - public const ALIGN_TYPES = ['default', 'horizontal', 'inline']; + public const ALIGN_TYPES = [self::ALIGN_DEFAULT, self::ALIGN_HORIZONTAL, self::ALIGN_INLINE]; /** * Default alignment. @@ -353,7 +353,7 @@ class FormHelper extends CoreFormHelper public function __construct(View $View, array $config = []) { $this->_defaultConfig = [ - 'align' => 'default', + 'align' => static::ALIGN_DEFAULT, 'errorClass' => 'is-invalid', 'grid' => [ static::GRID_COLUMN_ONE => 2, @@ -1298,7 +1298,7 @@ protected function _processFormOptions(array $options): array $options['templates'] = (new PhpConfig())->read($options['templates']); } - if ($this->_align === 'default') { + if ($this->_align === static::ALIGN_DEFAULT) { $options['templates'] += $templates; return $options; @@ -1306,7 +1306,7 @@ protected function _processFormOptions(array $options): array $options = $this->injectClasses('form-' . $this->_align, $options); - if ($this->_align === 'inline') { + if ($this->_align === static::ALIGN_INLINE) { $options = $this->injectClasses( [ 'row', diff --git a/src/View/Helper/OptionsAwareTrait.php b/src/View/Helper/OptionsAwareTrait.php index 941e8bc0..c4966391 100644 --- a/src/View/Helper/OptionsAwareTrait.php +++ b/src/View/Helper/OptionsAwareTrait.php @@ -91,7 +91,10 @@ public function injectClasses(array|string $classes, array $options): array $classes = $this->_toClassArray($classes); foreach ($classes as $class) { - if (!in_array($class, $options['class']) && !in_array($class, $options['skip'])) { + if ( + !in_array($class, $options['class']) && + !in_array($class, $options['skip']) + ) { array_push($options['class'], $class); } } diff --git a/src/View/Widget/DateTimeWidget.php b/src/View/Widget/DateTimeWidget.php index 10cf30d0..02ca58ec 100644 --- a/src/View/Widget/DateTimeWidget.php +++ b/src/View/Widget/DateTimeWidget.php @@ -11,74 +11,24 @@ class DateTimeWidget extends CoreDateTimeWidget use InputGroupTrait; /** - * Render a select box form input. - * - * Render a select box input given a set of data. Supported keys - * are: - * - * - `name` - Set the input name. - * - `options` - An array of options. - * - `disabled` - Either true or an array of options to disable. - * When true, the select element will be disabled. - * - `val` - Either a string or an array of options to mark as selected. - * - `empty` - Set to true to add an empty option at the top of the - * option elements. Set to a string to define the display text of the - * empty option. If an array is used the key will set the value of the empty - * option while, the value will set the display text. - * - `escape` - Set to false to disable HTML escaping. - * - * ### Options format - * - * The options option can take a variety of data format depending on - * the complexity of HTML you want generated. - * - * You can generate simple options using a basic associative array: - * - * ``` - * 'options' => ['elk' => 'Elk', 'beaver' => 'Beaver'] - * ``` - * - * If you need to define additional attributes on your option elements - * you can use the complex form for options: - * - * ``` - * 'options' => [ - * ['value' => 'elk', 'text' => 'Elk', 'data-foo' => 'bar'], - * ] - * ``` - * - * This form **requires** that both the `value` and `text` keys be defined. - * If either is not set options will not be generated correctly. - * - * If you need to define option groups you can do those using nested arrays: - * - * ``` - * 'options' => [ - * 'Mammals' => [ - * 'elk' => 'Elk', - * 'beaver' => 'Beaver' - * ] - * ] - * ``` - * - * And finally, if you need to put attributes on your optgroup elements you - * can do that with a more complex nested array form: - * - * ``` - * 'options' => [ - * [ - * 'text' => 'Mammals', - * 'data-id' => 1, - * 'options' => [ - * 'elk' => 'Elk', - * 'beaver' => 'Beaver' - * ] - * ], - * ] - * ``` - * - * You are free to mix each of the forms in the same option set, and - * nest complex types as required. + * Render a date / time form widget. + * + * Data supports the following keys: + * + * - `name` The name attribute. + * - `val` The value attribute. + * - `escape` Set to false to disable escaping on all attributes. + * - `type` A valid HTML date/time input type. Defaults to "datetime-local". + * - `timezone` The timezone the input value should be converted to. + * - `step` The "step" attribute. Defaults to `1` for "time" and "datetime-local" type inputs. + * You can set it to `null` or `false` to prevent explicit step attribute being added in HTML. + * - `format` A `date()` function compatible datetime format string. + * By default, the widget will use a suitable format based on the input type and + * database type for the context. If an explicit format is provided, then no + * default value will be set for the `step` attribute, and it needs to be + * explicitly set if required. + * + * All other keys will be converted into HTML attributes. * * @param array $data Data to render with. * @param \Cake\View\Form\ContextInterface $context The current form context.