33/**
44 * This file is part of contao-community-alliance/dc-general.
55 *
6- * (c) 2013-2024 Contao Community Alliance.
6+ * (c) 2013-2025 Contao Community Alliance.
77 *
88 * For the full copyright and license information, please view the LICENSE
99 * file that was distributed with this source code.
1717 * @author Sven Baumann <baumann.sv@gmail.com>
1818 * @author Richard Henkenjohann <richardhenkenjohann@googlemail.com>
1919 * @author Ingolf Steinhardt <info@e-spin.de>
20- * @copyright 2013-2024 Contao Community Alliance.
20+ * @copyright 2013-2025 Contao Community Alliance.
2121 * @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
2222 * @filesource
2323 */
5252use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
5353use Symfony \Contracts \Translation \TranslatorInterface ;
5454
55+ use function array_key_exists ;
56+ use function class_exists ;
57+ use function in_array ;
58+ use function is_array ;
59+ use function is_numeric ;
60+ use function sprintf ;
61+ use function strtr ;
62+
5563/**
5664 * Widget Builder build Contao backend widgets.
5765 *
@@ -169,9 +177,9 @@ protected function getWidgetClass(PropertyInterface $property)
169177 }
170178
171179 $ className = $ GLOBALS ['BE_FFL ' ][$ property ->getWidgetType ()] ?? '' ;
172- if (!\ class_exists ($ className )) {
180+ if (!class_exists ($ className )) {
173181 throw new DcGeneralRuntimeException (
174- \ sprintf ('Failed to get widget class for property "%s". ' , $ property ->getName ())
182+ sprintf ('Failed to get widget class for property "%s". ' , $ property ->getName ())
175183 );
176184 }
177185
@@ -222,11 +230,8 @@ private function isGetOptionsAllowed(PropertyInterface $property): bool
222230 $ propExtra = $ property ->getExtra ();
223231
224232 // Check to overwrite param.
225- if (
226- \array_key_exists ('fetchOptions ' , $ propExtra )
227- && (true === $ propExtra ['fetchOptions ' ])
228- ) {
229- return true ;
233+ if (array_key_exists ('fetchOptions ' , $ propExtra )) {
234+ return (true === $ propExtra ['fetchOptions ' ]);
230235 }
231236
232237 // Check the class.
@@ -235,7 +240,7 @@ private function isGetOptionsAllowed(PropertyInterface $property): bool
235240 }
236241
237242 // Check if multiple is active.
238- return \ array_key_exists ('multiple ' , $ propExtra ) && (true === $ propExtra ['multiple ' ]);
243+ return array_key_exists ('multiple ' , $ propExtra ) && (true === $ propExtra ['multiple ' ]);
239244 }
240245
241246 /**
@@ -269,7 +274,7 @@ protected function getTableWizard()
269274 $ shrinkEvent = new GenerateHtmlEvent (
270275 'demagnify.svg ' ,
271276 $ ccaTranslator ->translate ('shrink.0 ' , $ defName ),
272- \ sprintf (
277+ sprintf (
273278 'title="%s" ' .
274279 'style="vertical-align:text-bottom; cursor:pointer;" ' .
275280 'onclick="Backend.tableWizardResize(0.9);" ' ,
@@ -280,7 +285,7 @@ protected function getTableWizard()
280285 $ expandEvent = new GenerateHtmlEvent (
281286 'magnify.svg ' ,
282287 $ ccaTranslator ->translate ('expand.0 ' , $ defName ),
283- \ sprintf (
288+ sprintf (
284289 'title="%s" ' .
285290 'style="vertical-align:text-bottom; cursor:pointer;" ' .
286291 'onclick="Backend.tableWizardResize(1.1);" ' ,
@@ -293,7 +298,7 @@ protected function getTableWizard()
293298 $ dispatcher ->dispatch ($ shrinkEvent , ContaoEvents::IMAGE_GET_HTML );
294299 $ dispatcher ->dispatch ($ expandEvent , ContaoEvents::IMAGE_GET_HTML );
295300
296- return \ sprintf (
301+ return sprintf (
297302 ' <a href="%s" title="%s" onclick="Backend.getScrollOffset();">%s</a> %s%s ' ,
298303 StringUtil::ampersand ($ urlEvent ->getUrl ()),
299304 StringUtil::specialchars ($ ccaTranslator ->translate ('importTable.1 ' , $ defName )),
@@ -334,7 +339,7 @@ protected function getListWizard()
334339 $ dispatcher ->dispatch ($ urlEvent , ContaoEvents::BACKEND_ADD_TO_URL );
335340 $ dispatcher ->dispatch ($ importListEvent , ContaoEvents::IMAGE_GET_HTML );
336341
337- return \ sprintf (
342+ return sprintf (
338343 ' <a href="%s" title="%s" onclick="Backend.getScrollOffset();">%s</a> ' ,
339344 StringUtil::ampersand ($ urlEvent ->getUrl ()),
340345 StringUtil::specialchars ($ ccaTranslator ->translate ('importList.1 ' , $ defName )),
@@ -357,11 +362,11 @@ protected function getXLabel($propInfo)
357362 assert ($ ccaTranslator instanceof CcaTranslator);
358363
359364 // Toggle line wrap (textarea).
360- if (('textarea ' === $ propInfo ->getWidgetType ()) && !\ array_key_exists ('rte ' , $ propInfo ->getExtra ())) {
365+ if (('textarea ' === $ propInfo ->getWidgetType ()) && !array_key_exists ('rte ' , $ propInfo ->getExtra ())) {
361366 $ event = new GenerateHtmlEvent (
362367 'wrap.svg ' ,
363368 $ ccaTranslator ->translate ('wordWrap ' , 'dc-general ' ),
364- \ sprintf (
369+ sprintf (
365370 'title="%s" class="toggleWrap" onclick="Backend.toggleWrap( \'ctrl_%s \');" ' ,
366371 StringUtil::specialchars ($ ccaTranslator ->translate ('wordWrap ' , 'dc-general ' )),
367372 $ propInfo ->getName ()
@@ -410,7 +415,7 @@ protected function getHelpWizard($propInfo)
410415 return '' ;
411416 }
412417
413- if (\ array_key_exists ('helptext ' , $ extra )) {
418+ if (array_key_exists ('helptext ' , $ extra )) {
414419 $ event = new GenerateHtmlEvent (
415420 'help.svg ' ,
416421 $ ccaTranslator ->translate ('helpWizard ' , 'dc-general ' ),
@@ -426,7 +431,7 @@ protected function getHelpWizard($propInfo)
426431 assert ($ definition instanceof ContainerInterface);
427432
428433 $ generator = System::getContainer ()->get ('router ' );
429- return \ strtr (
434+ return strtr (
430435 ' <a href="{url}" title="{title}" ' .
431436 'onclick="Backend.openModalIframe({ \'title \': \'{windowTitle} \', \'url \':this.href}); ' .
432437 'return false">{icon}</a> ' ,
@@ -447,7 +452,7 @@ protected function getHelpWizard($propInfo)
447452 );
448453 }
449454
450- if (\ array_key_exists ('helpwizard ' , $ extra )) {
455+ if (array_key_exists ('helpwizard ' , $ extra )) {
451456 $ event = new GenerateHtmlEvent (
452457 'help.svg ' ,
453458 $ ccaTranslator ->translate ('helpWizard ' , 'dc-general ' ),
@@ -462,7 +467,7 @@ protected function getHelpWizard($propInfo)
462467 $ definition = $ environment ->getDataDefinition ();
463468 assert ($ definition instanceof ContainerInterface);
464469
465- return \ sprintf (
470+ return sprintf (
466471 ' <a href="/contao/help?table=%s&field=%s" ' .
467472 'title="%s" ' .
468473 'onclick="Backend.openWindow(this, 600, 500); return false;">%s</a> ' ,
@@ -498,7 +503,7 @@ public function buildWidget(
498503 || !static ::$ scopeDeterminator ->currentScopeIsBackend ()
499504 ) {
500505 throw new DcGeneralRuntimeException (
501- \ sprintf (
506+ sprintf (
502507 'WidgetBuilder only supports the backend mode. Running in mode "%s". ' ,
503508 static ::$ scopeDeterminator ->currentScopeIsUnknown () ? 'unknown ' : 'frontend '
504509 )
@@ -553,9 +558,9 @@ private function valueToWidget(ModelInterface $model, PropertyInterface $propert
553558
554559 if (
555560 (0 === (int ) $ value )
556- && \ is_numeric ($ value )
561+ && is_numeric ($ value )
557562 && empty ($ propExtra ['mandatory ' ])
558- && (isset ($ propExtra ['rgxp ' ]) && \ in_array ($ propExtra ['rgxp ' ], ['date ' , 'time ' , 'datim ' ]))
563+ && (isset ($ propExtra ['rgxp ' ]) && in_array ($ propExtra ['rgxp ' ], ['date ' , 'time ' , 'datim ' ]))
559564 ) {
560565 $ value = '' ;
561566 }
@@ -637,8 +642,8 @@ private function prepareWidgetAttributes(ModelInterface $model, PropertyInterfac
637642 && isset ($ widgetConfig ['eval ' ]['submitOnChange ' ])
638643 && $ widgetConfig ['eval ' ]['submitOnChange ' ]
639644 && isset ($ GLOBALS ['TL_DCA ' ][$ defName ]['subpalettes ' ])
640- && \ is_array ($ GLOBALS ['TL_DCA ' ][$ defName ]['subpalettes ' ])
641- && \ array_key_exists ($ property ->getName (), $ GLOBALS ['TL_DCA ' ][$ defName ]['subpalettes ' ])
645+ && is_array ($ GLOBALS ['TL_DCA ' ][$ defName ]['subpalettes ' ])
646+ && array_key_exists ($ property ->getName (), $ GLOBALS ['TL_DCA ' ][$ defName ]['subpalettes ' ])
642647 ) {
643648 // We have to override the onclick, do not append to it as Contao adds it's own code here in
644649 // Widget::getAttributesFromDca() which kills our sub palette handling!
@@ -661,7 +666,7 @@ private function setPropExtraDisabled(PropertyInterface $property, array $propEx
661666 if (
662667 isset ($ propExtra ['readonly ' ])
663668 && $ propExtra ['readonly ' ]
664- && \ in_array ($ property ->getWidgetType (), ['checkbox ' , 'select ' , 'radio ' ], true )
669+ && in_array ($ property ->getWidgetType (), ['checkbox ' , 'select ' , 'radio ' ], true )
665670 ) {
666671 $ propExtra ['disabled ' ] = true ;
667672 unset($ propExtra ['chosen ' ]);
0 commit comments