Skip to content

Commit 177e9a4

Browse files
authored
Merge pull request #421 from FriendsOfCake/cake-5.2-deprecation
Fix deprecation warning on CakePHP 5.2
2 parents d8b265a + 0b4fccf commit 177e9a4

18 files changed

+95
-83
lines changed

src/Command/BootstrapCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption
6868
return $parser
6969
->setDescription(
7070
'The BootstrapUI console provides commands for installing dependencies ' .
71-
'and samples, and for modifying your application to use BootstrapUI.'
71+
'and samples, and for modifying your application to use BootstrapUI.',
7272
);
7373
}
7474
}

src/Command/CopyLayoutsCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption
6969
{
7070
return $parser
7171
->setDescription(
72-
'Copies the sample layouts into the application\'s layout templates folder.'
72+
'Copies the sample layouts into the application\'s layout templates folder.',
7373
)
7474
->addArgument('target', [
7575
'help' => sprintf(
7676
'The target path into which to copy the layout files. Defaults to `%s`.',
77-
$this->_getDefaultTargetPath()
77+
$this->_getDefaultTargetPath(),
7878
),
7979
'required' => false,
8080
]);

src/Command/InstallCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ protected function _bufferPackageAssets(ConsoleIo $io): bool
303303
preg_match(
304304
"/{$DS}font{$DS}(?P<subdirs>.+{$DS})?.+\\.(css|woff|woff2)$/",
305305
$file->getPathname(),
306-
$matches
306+
$matches,
307307
)
308308
) {
309309
$assetPath = $fontPath;
@@ -376,7 +376,7 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption
376376
{
377377
return $parser
378378
->setDescription(
379-
'Installs Bootstrap dependencies and links the assets to the application\'s webroot.'
379+
'Installs Bootstrap dependencies and links the assets to the application\'s webroot.',
380380
)
381381
->addOption('latest', [
382382
'help' => 'To install the latest minor versions of required assets.',

src/Command/ModifyViewCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ protected function _modifyView(string $filePath): bool
5555
$content = str_replace(
5656
'use Cake\\View\\View',
5757
'use BootstrapUI\\View\\UIView',
58-
$content
58+
$content,
5959
);
6060
$content = str_replace(
6161
'class AppView extends View',
6262
'class AppView extends UIView',
63-
$content
63+
$content,
6464
);
6565
$content = str_replace(
6666
" public function initialize(): void\n {\n",
6767
" public function initialize(): void\n {\n parent::initialize();\n",
68-
$content
68+
$content,
6969
);
7070

7171
return $this->_writeFile($filePath, $content);
@@ -122,17 +122,17 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption
122122
{
123123
return $parser
124124
->setDescription(
125-
'Modifies `AppView.php` to extend this plugin\'s `UIView` class.'
125+
'Modifies `AppView.php` to extend this plugin\'s `UIView` class.',
126126
)
127127
->addArgument('file', [
128128
'help' => sprintf(
129129
'The path of the `AppView.php` file. Defaults to `%s`.',
130-
$this->_getDefaultFilePath()
130+
$this->_getDefaultFilePath(),
131131
),
132132
'required' => false,
133133
])
134134
->setEpilog(
135-
'<warning>Don\'t run this command if you have a already modified the `AppView` class!</warning>'
135+
'<warning>Don\'t run this command if you have a already modified the `AppView` class!</warning>',
136136
);
137137
}
138138
}

src/View/Helper/BreadcrumbsHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ protected function _clearActiveCrumb(): void
142142

143143
unset(
144144
$this->crumbs[$key]['options']['innerAttrs']['aria-current'],
145-
$this->crumbs[$key]['options']['aria-current']
145+
$this->crumbs[$key]['options']['aria-current'],
146146
);
147147
}
148148
}

src/View/Helper/FlashHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function render(string $key = 'flash', array $options = []): ?string
5858
if (!is_array($stack)) {
5959
throw new UnexpectedValueException(sprintf(
6060
'Value for flash setting key "%s" must be an array.',
61-
$key
61+
$key,
6262
));
6363
}
6464

src/View/Helper/FormHelper.php

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace BootstrapUI\View\Helper;
55

6+
use Cake\Core\Configure;
67
use Cake\Core\Configure\Engine\PhpConfig;
78
use Cake\Utility\Hash;
89
use Cake\Utility\Inflector;
@@ -214,6 +215,7 @@ class FormHelper extends CoreFormHelper
214215
'{{hidden}}<label{{attrs}}>{{input}}{{text}}{{tooltip}}</label>',
215216
'submitContainer' =>
216217
'<div{{containerAttrs}} class="{{containerClass}}submit">{{content}}</div>',
218+
'errorClass' => 'is-invalid',
217219
];
218220

219221
/**
@@ -342,7 +344,7 @@ public function __construct(View $View, array $config = [])
342344
{
343345
$this->_defaultConfig = [
344346
'align' => static::ALIGN_DEFAULT,
345-
'errorClass' => 'is-invalid',
347+
'errorClass' => version_compare(Configure::version(), '5.2.0', '<') ? 'is-invalid' : null,
346348
'grid' => [
347349
static::GRID_COLUMN_ONE => 2,
348350
static::GRID_COLUMN_TWO => 10,
@@ -380,6 +382,11 @@ public function create(mixed $context = null, array $options = []): string
380382
'spacing' => null,
381383
];
382384

385+
// This is only for backwards compatibility with CakePHP < 5.2
386+
if ($this->getConfig('errorClass')) {
387+
$this->setConfig('templates.errorClass', $this->getConfig('errorClass'));
388+
}
389+
383390
return parent::create($context, $this->_processFormOptions($options));
384391
}
385392

@@ -498,7 +505,7 @@ public function control(string $fieldName, array $options = []): string
498505
isset($options['append']) ||
499506
isset($options['prepend'])
500507
) {
501-
$options['injectErrorClass'] = $this->_config['errorClass'];
508+
$options['injectErrorClass'] = $this->getConfig('templates.errorClass');
502509
}
503510

504511
unset(
@@ -507,7 +514,7 @@ public function control(string $fieldName, array $options = []): string
507514
$options['spacing'],
508515
$options['inline'],
509516
$options['nestedInput'],
510-
$options['switch']
517+
$options['switch'],
511518
);
512519

513520
$result = parent::control($fieldName, $options);
@@ -542,7 +549,7 @@ protected function _spacingOptions(string $fieldName, array $options): array
542549
$options['templates'] += [
543550
'multicheckboxWrapper' => sprintf(
544551
$this->templater()->getConfig('multicheckboxWrapper'),
545-
$options['spacing']
552+
$options['spacing'],
546553
),
547554
];
548555
}
@@ -997,7 +1004,7 @@ protected function _tooltipOptions(string $fieldName, array $options): array
9971004
) {
9981005
$tooltip = $this->templater()->format(
9991006
'tooltip',
1000-
['content' => $options['tooltip']]
1007+
['content' => $options['tooltip']],
10011008
);
10021009
$options['label']['templateVars']['tooltip'] = ' ' . $tooltip;
10031010
}
@@ -1134,7 +1141,7 @@ public function staticControl(string $fieldName, array $options = []): string
11341141

11351142
$options = $this->_initInputField(
11361143
$fieldName,
1137-
['secure' => static::SECURE_SKIP] + $options
1144+
['secure' => static::SECURE_SKIP] + $options,
11381145
);
11391146

11401147
$content = $options['escape'] ? h($options['val']) : $options['val'];
@@ -1151,7 +1158,7 @@ public function staticControl(string $fieldName, array $options = []): string
11511158
$this->formProtector->addField(
11521159
$options['name'],
11531160
true,
1154-
(string)$options['val']
1161+
(string)$options['val'],
11551162
);
11561163
}
11571164

@@ -1246,7 +1253,7 @@ protected function _processFormOptions(array $options): array
12461253

12471254
if (!in_array($options['align'], static::ALIGN_TYPES)) {
12481255
throw new InvalidArgumentException(
1249-
'Invalid valid for `align` option. Valid values are: ' . implode(', ', static::ALIGN_TYPES)
1256+
'Invalid valid for `align` option. Valid values are: ' . implode(', ', static::ALIGN_TYPES),
12501257
);
12511258
}
12521259

@@ -1278,7 +1285,7 @@ protected function _processFormOptions(array $options): array
12781285
$this->_spacing,
12791286
'align-items-center',
12801287
],
1281-
$options
1288+
$options,
12821289
);
12831290
$options['templates'] += $templates;
12841291

@@ -1287,19 +1294,19 @@ protected function _processFormOptions(array $options): array
12871294

12881295
$templates['label'] = sprintf(
12891296
$templates['label'],
1290-
$this->_gridClass(static::GRID_COLUMN_ONE)
1297+
$this->_gridClass(static::GRID_COLUMN_ONE),
12911298
);
12921299
$templates['radioLabel'] = sprintf(
12931300
$templates['radioLabel'],
1294-
$this->_gridClass(static::GRID_COLUMN_ONE)
1301+
$this->_gridClass(static::GRID_COLUMN_ONE),
12951302
);
12961303
$templates['multicheckboxLabel'] = sprintf(
12971304
$templates['multicheckboxLabel'],
1298-
$this->_gridClass(static::GRID_COLUMN_ONE)
1305+
$this->_gridClass(static::GRID_COLUMN_ONE),
12991306
);
13001307
$templates['formGroup'] = sprintf(
13011308
$templates['formGroup'],
1302-
$this->_gridClass(static::GRID_COLUMN_TWO)
1309+
$this->_gridClass(static::GRID_COLUMN_TWO),
13031310
);
13041311

13051312
$offsetGridClass = implode(' ', [

src/View/Helper/HtmlHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function icon(string $name, array $options = []): string
101101
'tag' => $options['tag'],
102102
'attrs' => $this->templater()->formatAttributes(
103103
$options,
104-
['tag', 'namespace', 'prefix', 'size']
104+
['tag', 'namespace', 'prefix', 'size'],
105105
),
106106
]);
107107
}

src/View/Widget/InputGroupTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ protected function _processOptions(array $attachment, array $attrs): array
174174

175175
unset(
176176
$attachment['options']['size'],
177-
$attachment['options']['class']
177+
$attachment['options']['class'],
178178
);
179179

180180
$attrs += $attachment['options'];

tests/TestCase/Command/BootstrapCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function testEntry()
1717
$this->assertOutputEmpty();
1818
$this->assertEquals(
1919
['<warning>No command provided. Run `bootstrap --help` to get a list of commands.</warning>'],
20-
$this->_err->messages()
20+
$this->_err->messages(),
2121
);
2222
}
2323

@@ -40,7 +40,7 @@ public function testHelp()
4040
'To get help on a specific command, type <info>`bootstrap command_name --help`</info>',
4141
'',
4242
],
43-
$this->_out->messages()
43+
$this->_out->messages(),
4444
);
4545
$this->assertErrorEmpty();
4646
}

0 commit comments

Comments
 (0)