Skip to content

Commit 07761b6

Browse files
committed
Fix deprecation warning on CakePHP 5.2
1 parent 667efc1 commit 07761b6

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/View/Helper/FormHelper.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ class FormHelper extends CoreFormHelper
214214
'{{hidden}}<label{{attrs}}>{{input}}{{text}}{{tooltip}}</label>',
215215
'submitContainer' =>
216216
'<div{{containerAttrs}} class="{{containerClass}}submit">{{content}}</div>',
217+
'errorClass' => 'is-invalid',
217218
];
218219

219220
/**
@@ -342,7 +343,6 @@ public function __construct(View $View, array $config = [])
342343
{
343344
$this->_defaultConfig = [
344345
'align' => static::ALIGN_DEFAULT,
345-
'errorClass' => 'is-invalid',
346346
'grid' => [
347347
static::GRID_COLUMN_ONE => 2,
348348
static::GRID_COLUMN_TWO => 10,
@@ -380,6 +380,11 @@ public function create(mixed $context = null, array $options = []): string
380380
'spacing' => null,
381381
];
382382

383+
// This is only for backwards compatibility with CakePHP < 5.2
384+
if ($this->getConfig('errorClass')) {
385+
$this->setConfig('templates.errorClass', $this->getConfig('errorClass'));
386+
}
387+
383388
return parent::create($context, $this->_processFormOptions($options));
384389
}
385390

@@ -498,7 +503,7 @@ public function control(string $fieldName, array $options = []): string
498503
isset($options['append']) ||
499504
isset($options['prepend'])
500505
) {
501-
$options['injectErrorClass'] = $this->_config['errorClass'];
506+
$options['injectErrorClass'] = $this->getConfig('templates.errorClass');
502507
}
503508

504509
unset(

tests/bootstrap.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@
7575
]);
7676

7777
Cache::setConfig([
78+
'_cake_translations_' => [
79+
'engine' => 'File',
80+
'prefix' => 'cake_translations_',
81+
'serialize' => true,
82+
],
7883
'_cake_core_' => [
7984
'engine' => 'File',
8085
'prefix' => 'cake_core_',

0 commit comments

Comments
 (0)