Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code cleanup #413

Merged
merged 1 commit into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/View/Helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1298,15 +1298,15 @@ 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;
}

$options = $this->injectClasses('form-' . $this->_align, $options);

if ($this->_align === 'inline') {
if ($this->_align === static::ALIGN_INLINE) {
$options = $this->injectClasses(
[
'row',
Expand Down
5 changes: 4 additions & 1 deletion src/View/Helper/OptionsAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
86 changes: 18 additions & 68 deletions src/View/Widget/DateTimeWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down