2121use HeimrichHannot \UtilsBundle \Model \CfgTagModel ;
2222use HeimrichHannot \UtilsBundle \Request \RequestCleaner ;
2323use Symfony \Component \DependencyInjection \ContainerInterface ;
24+ use function Symfony \Component \String \b ;
2425
2526/**
2627 * Class FormUtil.
@@ -48,13 +49,13 @@ public function __construct(ContainerInterface $container, ContaoFrameworkInterf
4849 /**
4950 * Get a new widget instance based on given attributes from a Data Container array.
5051 *
51- * @param string $name The field name in the form
52- * @param array $data The field configuration array
53- * @param mixed $value The field value
54- * @param string $dbName The field name in the database
55- * @param string $table The table name in the database
56- * @param DataContainer|null $dc An optional DataContainer object
57- * @param string $mode The contao mode, use FE or BE to get proper widget/form type
52+ * @param string $name The field name in the form
53+ * @param array $data The field configuration array
54+ * @param mixed $value The field value
55+ * @param string $dbName The field name in the database
56+ * @param string $table The table name in the database
57+ * @param DataContainer|null $dc An optional DataContainer object
58+ * @param string $mode The contao mode, use FE or BE to get proper widget/form type
5859 *
5960 * @return Widget|null The new widget based on given attributes
6061 */
@@ -160,15 +161,15 @@ public function prepareSpecialValueForOutput(string $field, $value, DataContaine
160161 $ label = '' ;
161162
162163 if (!$ skipMceFieldLabels ) {
163- $ label = ($ dca ['label ' ][0 ] ?: $ fieldName ). ': ' ;
164+ $ label = ($ dca ['label ' ][0 ] ?: $ fieldName ) . ': ' ;
164165
165166 if ($ skipMceFieldLabelFormatting ) {
166- $ label = $ fieldName. ': ' ;
167+ $ label = $ fieldName . ': ' ;
167168 }
168169 }
169170
170171 // indent new line
171- $ formatted .= $ mceFieldSeparator. $ label. $ this ->prepareSpecialValueForOutput ($ fieldName , $ fieldValue , $ dc , array_merge ($ config , [
172+ $ formatted .= $ mceFieldSeparator . $ label . $ this ->prepareSpecialValueForOutput ($ fieldName , $ fieldValue , $ dc , array_merge ($ config , [
172173 '_dcaOverride ' => $ dca ,
173174 ]));
174175 }
@@ -193,7 +194,7 @@ public function prepareSpecialValueForOutput(string $field, $value, DataContaine
193194 $ data ['unit ' ] = '' ;
194195 }
195196
196- return $ data ['value ' ]. $ arraySeparator. $ data ['unit ' ];
197+ return $ data ['value ' ] . $ arraySeparator . $ data ['unit ' ];
197198 }
198199
199200 // Recursively apply logic to array
@@ -271,11 +272,11 @@ public function prepareSpecialValueForOutput(string $field, $value, DataContaine
271272 $ value = Date::parse (Config::get ('datimFormat ' ), $ value );
272273 } elseif (Validator::isBinaryUuid ($ value )) {
273274 $ strPath = $ this ->container ->get ('huh.utils.file ' )->getPathFromUuid ($ value );
274- $ value = $ strPath ? Environment::get ('url ' ). '/ ' . $ strPath : StringUtil::binToUuid ($ value );
275+ $ value = $ strPath ? Environment::get ('url ' ) . '/ ' . $ strPath : StringUtil::binToUuid ($ value );
275276 } // Replace boolean checkbox value with "yes" and "no"
276277 else {
277278 if ((isset ($ data ['eval ' ]['isBoolean ' ]) && $ data ['eval ' ]['isBoolean ' ]) || ('checkbox ' == $ inputType && !($ data ['eval ' ]['multiple ' ] ?? false ))) {
278- $ value = ( '' != $ value ) ? $ GLOBALS ['TL_LANG ' ]['MSC ' ]['yes ' ] : $ GLOBALS ['TL_LANG ' ]['MSC ' ]['no ' ];
279+ $ value = $ this -> evaluateBoolean ( $ value ) ? $ GLOBALS ['TL_LANG ' ]['MSC ' ]['yes ' ] : $ GLOBALS ['TL_LANG ' ]['MSC ' ]['no ' ];
279280 } elseif (\is_array ($ options ) && array_is_assoc ($ options )) {
280281 $ value = isset ($ options [$ value ]) ? $ options [$ value ] : $ value ;
281282 }
@@ -341,12 +342,12 @@ public function escapeAllHtmlEntities($table, $field, $value)
341342 /**
342343 * Get an instance of Widget by passing fieldname and dca data.
343344 *
344- * @param string $fieldName The field name
345- * @param array $dca The DCA
345+ * @param string $fieldName The field name
346+ * @param array $dca The DCA
346347 * @param array|null $value
347- * @param string $dbField The database field name
348- * @param string $table The table
349- * @param null $dataContainer object The data container
348+ * @param string $dbField The database field name
349+ * @param string $table The table
350+ * @param null $dataContainer object The data container
350351 *
351352 * @return Widget|null
352353 */
@@ -383,7 +384,7 @@ public function getModelDataAsNotificationTokens(array $data, string $prefix, Da
383384 continue ;
384385 }
385386
386- $ result [$ prefix. $ rawValuePrefix. $ field ] = $ value ;
387+ $ result [$ prefix . $ rawValuePrefix . $ field ] = $ value ;
387388 }
388389 }
389390
@@ -398,12 +399,23 @@ public function getModelDataAsNotificationTokens(array $data, string $prefix, Da
398399 continue ;
399400 }
400401
401- $ result [$ prefix. $ formattedValuePrefix. $ field ] = $ this ->prepareSpecialValueForOutput (
402+ $ result [$ prefix . $ formattedValuePrefix . $ field ] = $ this ->prepareSpecialValueForOutput (
402403 $ field , $ value , $ dc , $ formatOptions
403404 );
404405 }
405406 }
406407
407408 return $ result ;
408409 }
410+
411+ public function evaluateBoolean (mixed $ value ): bool
412+ {
413+ if (is_int ($ value )) {
414+ return $ value > 0 ;
415+ }
416+ if (is_string ($ value )) {
417+ return !empty ($ value );
418+ }
419+ return (bool )$ value ;
420+ }
409421}
0 commit comments