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 *
@@ -170,9 +178,9 @@ protected function getWidgetClass(PropertyInterface $property)
170178 }
171179
172180 $ className = $ GLOBALS ['BE_FFL ' ][$ property ->getWidgetType ()] ?? '' ;
173- if (!\ class_exists ($ className )) {
181+ if (!class_exists ($ className )) {
174182 throw new DcGeneralRuntimeException (
175- \ sprintf ('Failed to get widget class for property "%s". ' , $ property ->getName ())
183+ sprintf ('Failed to get widget class for property "%s". ' , $ property ->getName ())
176184 );
177185 }
178186
@@ -223,11 +231,8 @@ private function isGetOptionsAllowed(PropertyInterface $property): bool
223231 $ propExtra = $ property ->getExtra ();
224232
225233 // Check to overwrite param.
226- if (
227- \array_key_exists ('fetchOptions ' , $ propExtra )
228- && (true === $ propExtra ['fetchOptions ' ])
229- ) {
230- return true ;
234+ if (array_key_exists ('fetchOptions ' , $ propExtra )) {
235+ return (true === $ propExtra ['fetchOptions ' ]);
231236 }
232237
233238 // Check the class.
@@ -236,7 +241,7 @@ private function isGetOptionsAllowed(PropertyInterface $property): bool
236241 }
237242
238243 // Check if multiple is active.
239- return \ array_key_exists ('multiple ' , $ propExtra ) && (true === $ propExtra ['multiple ' ]);
244+ return array_key_exists ('multiple ' , $ propExtra ) && (true === $ propExtra ['multiple ' ]);
240245 }
241246
242247 /**
@@ -270,7 +275,7 @@ protected function getTableWizard()
270275 $ shrinkEvent = new GenerateHtmlEvent (
271276 'demagnify.svg ' ,
272277 $ ccaTranslator ->translate ('shrink.0 ' , $ defName ),
273- \ sprintf (
278+ sprintf (
274279 'title="%s" ' .
275280 'style="vertical-align:text-bottom; cursor:pointer;" ' .
276281 'onclick="Backend.tableWizardResize(0.9);" ' ,
@@ -281,7 +286,7 @@ protected function getTableWizard()
281286 $ expandEvent = new GenerateHtmlEvent (
282287 'magnify.svg ' ,
283288 $ ccaTranslator ->translate ('expand.0 ' , $ defName ),
284- \ sprintf (
289+ sprintf (
285290 'title="%s" ' .
286291 'style="vertical-align:text-bottom; cursor:pointer;" ' .
287292 'onclick="Backend.tableWizardResize(1.1);" ' ,
@@ -294,7 +299,7 @@ protected function getTableWizard()
294299 $ dispatcher ->dispatch ($ shrinkEvent , ContaoEvents::IMAGE_GET_HTML );
295300 $ dispatcher ->dispatch ($ expandEvent , ContaoEvents::IMAGE_GET_HTML );
296301
297- return \ sprintf (
302+ return sprintf (
298303 ' <a href="%s" title="%s" onclick="Backend.getScrollOffset();">%s</a> %s%s ' ,
299304 StringUtil::ampersand ($ urlEvent ->getUrl ()),
300305 StringUtil::specialchars ($ ccaTranslator ->translate ('importTable.1 ' , $ defName )),
@@ -335,7 +340,7 @@ protected function getListWizard()
335340 $ dispatcher ->dispatch ($ urlEvent , ContaoEvents::BACKEND_ADD_TO_URL );
336341 $ dispatcher ->dispatch ($ importListEvent , ContaoEvents::IMAGE_GET_HTML );
337342
338- return \ sprintf (
343+ return sprintf (
339344 ' <a href="%s" title="%s" onclick="Backend.getScrollOffset();">%s</a> ' ,
340345 StringUtil::ampersand ($ urlEvent ->getUrl ()),
341346 StringUtil::specialchars ($ ccaTranslator ->translate ('importList.1 ' , $ defName )),
@@ -358,11 +363,11 @@ protected function getXLabel($propInfo)
358363 assert ($ ccaTranslator instanceof CcaTranslator);
359364
360365 // Toggle line wrap (textarea).
361- if (('textarea ' === $ propInfo ->getWidgetType ()) && !\ array_key_exists ('rte ' , $ propInfo ->getExtra ())) {
366+ if (('textarea ' === $ propInfo ->getWidgetType ()) && !array_key_exists ('rte ' , $ propInfo ->getExtra ())) {
362367 $ event = new GenerateHtmlEvent (
363368 'wrap.svg ' ,
364369 $ ccaTranslator ->translate ('wordWrap ' , 'dc-general ' ),
365- \ sprintf (
370+ sprintf (
366371 'title="%s" class="toggleWrap" onclick="Backend.toggleWrap( \'ctrl_%s \');" ' ,
367372 StringUtil::specialchars ($ ccaTranslator ->translate ('wordWrap ' , 'dc-general ' )),
368373 $ propInfo ->getName ()
@@ -411,7 +416,7 @@ protected function getHelpWizard($propInfo)
411416 return '' ;
412417 }
413418
414- if (\ array_key_exists ('helptext ' , $ extra )) {
419+ if (array_key_exists ('helptext ' , $ extra )) {
415420 $ event = new GenerateHtmlEvent (
416421 'help.svg ' ,
417422 $ ccaTranslator ->translate ('helpWizard ' , 'dc-general ' ),
@@ -427,7 +432,7 @@ protected function getHelpWizard($propInfo)
427432 assert ($ definition instanceof ContainerInterface);
428433
429434 $ generator = System::getContainer ()->get ('router ' );
430- return \ strtr (
435+ return strtr (
431436 ' <a href="{url}" title="{title}" ' .
432437 'onclick="Backend.openModalIframe({ \'title \': \'{windowTitle} \', \'url \':this.href}); ' .
433438 'return false">{icon}</a> ' ,
@@ -448,7 +453,7 @@ protected function getHelpWizard($propInfo)
448453 );
449454 }
450455
451- if (\ array_key_exists ('helpwizard ' , $ extra )) {
456+ if (array_key_exists ('helpwizard ' , $ extra )) {
452457 $ event = new GenerateHtmlEvent (
453458 'help.svg ' ,
454459 $ ccaTranslator ->translate ('helpWizard ' , 'dc-general ' ),
@@ -463,7 +468,7 @@ protected function getHelpWizard($propInfo)
463468 $ definition = $ environment ->getDataDefinition ();
464469 assert ($ definition instanceof ContainerInterface);
465470
466- return \ sprintf (
471+ return sprintf (
467472 ' <a href="/contao/help?table=%s&field=%s" ' .
468473 'title="%s" ' .
469474 'onclick="Backend.openWindow(this, 600, 500); return false;">%s</a> ' ,
@@ -499,7 +504,7 @@ public function buildWidget(
499504 || !static ::$ scopeDeterminator ->currentScopeIsBackend ()
500505 ) {
501506 throw new DcGeneralRuntimeException (
502- \ sprintf (
507+ sprintf (
503508 'WidgetBuilder only supports the backend mode. Running in mode "%s". ' ,
504509 static ::$ scopeDeterminator ->currentScopeIsUnknown () ? 'unknown ' : 'frontend '
505510 )
@@ -554,9 +559,9 @@ private function valueToWidget(ModelInterface $model, PropertyInterface $propert
554559
555560 if (
556561 (0 === (int ) $ value )
557- && \ is_numeric ($ value )
562+ && is_numeric ($ value )
558563 && empty ($ propExtra ['mandatory ' ])
559- && (isset ($ propExtra ['rgxp ' ]) && \ in_array ($ propExtra ['rgxp ' ], ['date ' , 'time ' , 'datim ' ]))
564+ && (isset ($ propExtra ['rgxp ' ]) && in_array ($ propExtra ['rgxp ' ], ['date ' , 'time ' , 'datim ' ]))
560565 ) {
561566 $ value = '' ;
562567 }
@@ -638,8 +643,8 @@ private function prepareWidgetAttributes(ModelInterface $model, PropertyInterfac
638643 && isset ($ widgetConfig ['eval ' ]['submitOnChange ' ])
639644 && $ widgetConfig ['eval ' ]['submitOnChange ' ]
640645 && isset ($ GLOBALS ['TL_DCA ' ][$ defName ]['subpalettes ' ])
641- && \ is_array ($ GLOBALS ['TL_DCA ' ][$ defName ]['subpalettes ' ])
642- && \ array_key_exists ($ property ->getName (), $ GLOBALS ['TL_DCA ' ][$ defName ]['subpalettes ' ])
646+ && is_array ($ GLOBALS ['TL_DCA ' ][$ defName ]['subpalettes ' ])
647+ && array_key_exists ($ property ->getName (), $ GLOBALS ['TL_DCA ' ][$ defName ]['subpalettes ' ])
643648 ) {
644649 // We have to override the onclick, do not append to it as Contao adds it's own code here in
645650 // Widget::getAttributesFromDca() which kills our sub palette handling!
@@ -662,7 +667,7 @@ private function setPropExtraDisabled(PropertyInterface $property, array $propEx
662667 if (
663668 isset ($ propExtra ['readonly ' ])
664669 && $ propExtra ['readonly ' ]
665- && \ in_array ($ property ->getWidgetType (), ['checkbox ' , 'select ' , 'radio ' ], true )
670+ && in_array ($ property ->getWidgetType (), ['checkbox ' , 'select ' , 'radio ' ], true )
666671 ) {
667672 $ propExtra ['disabled ' ] = true ;
668673 unset($ propExtra ['chosen ' ]);
0 commit comments