33
44namespace BootstrapUI \View \Helper ;
55
6+ use Cake \Core \Configure ;
67use Cake \Core \Configure \Engine \PhpConfig ;
78use Cake \Utility \Hash ;
89use 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 (' ' , [
0 commit comments