|
3 | 3 |
|
4 | 4 | namespace BootstrapUI\View\Helper; |
5 | 5 |
|
| 6 | +use Cake\Core\Configure; |
6 | 7 | use Cake\Core\Configure\Engine\PhpConfig; |
7 | 8 | use Cake\Utility\Hash; |
8 | 9 | use Cake\Utility\Inflector; |
@@ -214,6 +215,7 @@ class FormHelper extends CoreFormHelper |
214 | 215 | '{{hidden}}<label{{attrs}}>{{input}}{{text}}{{tooltip}}</label>', |
215 | 216 | 'submitContainer' => |
216 | 217 | '<div{{containerAttrs}} class="{{containerClass}}submit">{{content}}</div>', |
| 218 | + 'errorClass' => 'is-invalid', |
217 | 219 | ]; |
218 | 220 |
|
219 | 221 | /** |
@@ -342,7 +344,7 @@ public function __construct(View $View, array $config = []) |
342 | 344 | { |
343 | 345 | $this->_defaultConfig = [ |
344 | 346 | 'align' => static::ALIGN_DEFAULT, |
345 | | - 'errorClass' => 'is-invalid', |
| 347 | + 'errorClass' => version_compare(Configure::version(), '5.2.0', '<') ? 'is-invalid' : null, |
346 | 348 | 'grid' => [ |
347 | 349 | static::GRID_COLUMN_ONE => 2, |
348 | 350 | static::GRID_COLUMN_TWO => 10, |
@@ -380,6 +382,11 @@ public function create(mixed $context = null, array $options = []): string |
380 | 382 | 'spacing' => null, |
381 | 383 | ]; |
382 | 384 |
|
| 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 | + |
383 | 390 | return parent::create($context, $this->_processFormOptions($options)); |
384 | 391 | } |
385 | 392 |
|
@@ -498,7 +505,7 @@ public function control(string $fieldName, array $options = []): string |
498 | 505 | isset($options['append']) || |
499 | 506 | isset($options['prepend']) |
500 | 507 | ) { |
501 | | - $options['injectErrorClass'] = $this->_config['errorClass']; |
| 508 | + $options['injectErrorClass'] = $this->getConfig('templates.errorClass'); |
502 | 509 | } |
503 | 510 |
|
504 | 511 | unset( |
|
0 commit comments