Skip to content

Commit 54a2961

Browse files
authored
Merge pull request #413 from FriendsOfCake/chore/cleanup
code cleanup
2 parents 22ddde4 + b4b508f commit 54a2961

File tree

3 files changed

+26
-73
lines changed

3 files changed

+26
-73
lines changed

src/View/Helper/FormHelper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class FormHelper extends CoreFormHelper
7070
*
7171
* @var array
7272
*/
73-
public const ALIGN_TYPES = ['default', 'horizontal', 'inline'];
73+
public const ALIGN_TYPES = [self::ALIGN_DEFAULT, self::ALIGN_HORIZONTAL, self::ALIGN_INLINE];
7474

7575
/**
7676
* Default alignment.
@@ -353,7 +353,7 @@ class FormHelper extends CoreFormHelper
353353
public function __construct(View $View, array $config = [])
354354
{
355355
$this->_defaultConfig = [
356-
'align' => 'default',
356+
'align' => static::ALIGN_DEFAULT,
357357
'errorClass' => 'is-invalid',
358358
'grid' => [
359359
static::GRID_COLUMN_ONE => 2,
@@ -1298,15 +1298,15 @@ protected function _processFormOptions(array $options): array
12981298
$options['templates'] = (new PhpConfig())->read($options['templates']);
12991299
}
13001300

1301-
if ($this->_align === 'default') {
1301+
if ($this->_align === static::ALIGN_DEFAULT) {
13021302
$options['templates'] += $templates;
13031303

13041304
return $options;
13051305
}
13061306

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

1309-
if ($this->_align === 'inline') {
1309+
if ($this->_align === static::ALIGN_INLINE) {
13101310
$options = $this->injectClasses(
13111311
[
13121312
'row',

src/View/Helper/OptionsAwareTrait.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ public function injectClasses(array|string $classes, array $options): array
9191
$classes = $this->_toClassArray($classes);
9292

9393
foreach ($classes as $class) {
94-
if (!in_array($class, $options['class']) && !in_array($class, $options['skip'])) {
94+
if (
95+
!in_array($class, $options['class']) &&
96+
!in_array($class, $options['skip'])
97+
) {
9598
array_push($options['class'], $class);
9699
}
97100
}

src/View/Widget/DateTimeWidget.php

Lines changed: 18 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -11,74 +11,24 @@ class DateTimeWidget extends CoreDateTimeWidget
1111
use InputGroupTrait;
1212

1313
/**
14-
* Render a select box form input.
15-
*
16-
* Render a select box input given a set of data. Supported keys
17-
* are:
18-
*
19-
* - `name` - Set the input name.
20-
* - `options` - An array of options.
21-
* - `disabled` - Either true or an array of options to disable.
22-
* When true, the select element will be disabled.
23-
* - `val` - Either a string or an array of options to mark as selected.
24-
* - `empty` - Set to true to add an empty option at the top of the
25-
* option elements. Set to a string to define the display text of the
26-
* empty option. If an array is used the key will set the value of the empty
27-
* option while, the value will set the display text.
28-
* - `escape` - Set to false to disable HTML escaping.
29-
*
30-
* ### Options format
31-
*
32-
* The options option can take a variety of data format depending on
33-
* the complexity of HTML you want generated.
34-
*
35-
* You can generate simple options using a basic associative array:
36-
*
37-
* ```
38-
* 'options' => ['elk' => 'Elk', 'beaver' => 'Beaver']
39-
* ```
40-
*
41-
* If you need to define additional attributes on your option elements
42-
* you can use the complex form for options:
43-
*
44-
* ```
45-
* 'options' => [
46-
* ['value' => 'elk', 'text' => 'Elk', 'data-foo' => 'bar'],
47-
* ]
48-
* ```
49-
*
50-
* This form **requires** that both the `value` and `text` keys be defined.
51-
* If either is not set options will not be generated correctly.
52-
*
53-
* If you need to define option groups you can do those using nested arrays:
54-
*
55-
* ```
56-
* 'options' => [
57-
* 'Mammals' => [
58-
* 'elk' => 'Elk',
59-
* 'beaver' => 'Beaver'
60-
* ]
61-
* ]
62-
* ```
63-
*
64-
* And finally, if you need to put attributes on your optgroup elements you
65-
* can do that with a more complex nested array form:
66-
*
67-
* ```
68-
* 'options' => [
69-
* [
70-
* 'text' => 'Mammals',
71-
* 'data-id' => 1,
72-
* 'options' => [
73-
* 'elk' => 'Elk',
74-
* 'beaver' => 'Beaver'
75-
* ]
76-
* ],
77-
* ]
78-
* ```
79-
*
80-
* You are free to mix each of the forms in the same option set, and
81-
* nest complex types as required.
14+
* Render a date / time form widget.
15+
*
16+
* Data supports the following keys:
17+
*
18+
* - `name` The name attribute.
19+
* - `val` The value attribute.
20+
* - `escape` Set to false to disable escaping on all attributes.
21+
* - `type` A valid HTML date/time input type. Defaults to "datetime-local".
22+
* - `timezone` The timezone the input value should be converted to.
23+
* - `step` The "step" attribute. Defaults to `1` for "time" and "datetime-local" type inputs.
24+
* You can set it to `null` or `false` to prevent explicit step attribute being added in HTML.
25+
* - `format` A `date()` function compatible datetime format string.
26+
* By default, the widget will use a suitable format based on the input type and
27+
* database type for the context. If an explicit format is provided, then no
28+
* default value will be set for the `step` attribute, and it needs to be
29+
* explicitly set if required.
30+
*
31+
* All other keys will be converted into HTML attributes.
8232
*
8333
* @param array $data Data to render with.
8434
* @param \Cake\View\Form\ContextInterface $context The current form context.

0 commit comments

Comments
 (0)