Skip to content

Commit 0b4fccf

Browse files
committed
Fix deprecation warning on CakePHP 5.2
1 parent 667efc1 commit 0b4fccf

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/View/Helper/FormHelper.php

Lines changed: 9 additions & 2 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(

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)