diff --git a/typo3/sysext/backend/Classes/Form/Element/AbstractFormElement.php b/typo3/sysext/backend/Classes/Form/Element/AbstractFormElement.php index b6ba4182f8ba8b5cf89bbce99c1a047a18d72f0c..649fd7f1f52a6806b7668d41f494e67c22a84e49 100644 --- a/typo3/sysext/backend/Classes/Form/Element/AbstractFormElement.php +++ b/typo3/sysext/backend/Classes/Form/Element/AbstractFormElement.php @@ -23,6 +23,7 @@ use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; use TYPO3\CMS\Core\Imaging\IconFactory; use TYPO3\CMS\Core\Localization\LanguageService; +use TYPO3\CMS\Core\Page\JavaScriptModuleInstruction; use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\MathUtility; @@ -313,6 +314,43 @@ abstract class AbstractFormElement extends AbstractNode return ceil($size * $compensationForFormFields); } + /** + * Handle custom javascript `eval` implementations. $evalObject is a hook object + * for custom eval's. It is transferred to JS as a requireJsModule if possible. + * This is used by a couple of renderType's like various type="input", should + * be used with care and is internal for now. + * + * @param array $resultArray + * @param string $name + * @param object|null $evalObject + * @return array + * @internal + */ + protected function resolveJavaScriptEvaluation(array $resultArray, string $name, ?object $evalObject): array + { + if (!is_object($evalObject) || !method_exists($evalObject, 'returnFieldJS')) { + return $resultArray; + } + + $javaScriptEvaluation = $evalObject->returnFieldJS(); + if ($javaScriptEvaluation instanceof JavaScriptModuleInstruction) { + // just use the module name and export-name + $resultArray['requireJsModules'][] = JavaScriptModuleInstruction::forRequireJS( + $javaScriptEvaluation->getName(), + $javaScriptEvaluation->getExportName() + )->invoke('registerCustomEvaluation', $name); + } else { + // @todo deprecate inline JavaScript in TYPO3 v12.0 + $resultArray['additionalJavaScriptPost'][] = sprintf( + 'TBE_EDITOR.customEvalFunctions[%s] = function(value) { %s };', + GeneralUtility::quoteJSvalue($name), + $javaScriptEvaluation + ); + } + + return $resultArray; + } + /*********************************************** * CheckboxElement related methods ***********************************************/ diff --git a/typo3/sysext/backend/Classes/Form/Element/CustomEvaluationTrait.php b/typo3/sysext/backend/Classes/Form/Element/CustomEvaluationTrait.php deleted file mode 100644 index eccf56ef5a848b2d0b886fcad574af7d8ebb9de9..0000000000000000000000000000000000000000 --- a/typo3/sysext/backend/Classes/Form/Element/CustomEvaluationTrait.php +++ /dev/null @@ -1,52 +0,0 @@ -<?php - -declare(strict_types=1); - -/* - * This file is part of the TYPO3 CMS project. - * - * It is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. - * - * For the full copyright and license information, please read the - * LICENSE.txt file that was distributed with this source code. - * - * The TYPO3 project - inspiring people to share! - */ - -namespace TYPO3\CMS\Backend\Form\Element; - -use TYPO3\CMS\Core\Page\JavaScriptModuleInstruction; -use TYPO3\CMS\Core\Utility\GeneralUtility; - -/** - * Trait handling custom `eval` implementations. - */ -trait CustomEvaluationTrait -{ - protected function resolveJavaScriptEvaluation(array $resultArray, string $name, ?object $evalObject): array - { - if (!is_object($evalObject) || !method_exists($evalObject, 'returnFieldJS')) { - return $resultArray; - } - - $javaScriptEvaluation = $evalObject->returnFieldJS(); - if ($javaScriptEvaluation instanceof JavaScriptModuleInstruction) { - // just use the module name and export-name - $resultArray['requireJsModules'][] = JavaScriptModuleInstruction::forRequireJS( - $javaScriptEvaluation->getName(), - $javaScriptEvaluation->getExportName() - )->invoke('registerCustomEvaluation', $name); - } else { - // @todo deprecate inline JavaScript in TYPO3 v12.0 - $resultArray['additionalJavaScriptPost'][] = sprintf( - 'TBE_EDITOR.customEvalFunctions[%s] = function(value) { %s };', - GeneralUtility::quoteJSvalue($name), - $javaScriptEvaluation - ); - } - - return $resultArray; - } -} diff --git a/typo3/sysext/backend/Classes/Form/Element/InputColorPickerElement.php b/typo3/sysext/backend/Classes/Form/Element/InputColorPickerElement.php index 5c2eac87d6befc42309f012a667c72efe736ea78..beb19f4e8911c802f70c066d59f7c71216a99979 100644 --- a/typo3/sysext/backend/Classes/Form/Element/InputColorPickerElement.php +++ b/typo3/sysext/backend/Classes/Form/Element/InputColorPickerElement.php @@ -26,8 +26,6 @@ use TYPO3\CMS\Core\Utility\StringUtility; */ class InputColorPickerElement extends AbstractFormElement { - use CustomEvaluationTrait; - /** * Default field information enabled for this element. * diff --git a/typo3/sysext/backend/Classes/Form/Element/InputLinkElement.php b/typo3/sysext/backend/Classes/Form/Element/InputLinkElement.php index a960e39f0d3bbf8bc27fd44bd62c574bab7077f7..1c4d732daf959b7e8619150a9d37e4279d818529 100644 --- a/typo3/sysext/backend/Classes/Form/Element/InputLinkElement.php +++ b/typo3/sysext/backend/Classes/Form/Element/InputLinkElement.php @@ -39,7 +39,6 @@ use TYPO3\CMS\Frontend\Service\TypoLinkCodecService; */ class InputLinkElement extends AbstractFormElement { - use CustomEvaluationTrait; use OnFieldChangeTrait; /** diff --git a/typo3/sysext/backend/Classes/Form/Element/InputTextElement.php b/typo3/sysext/backend/Classes/Form/Element/InputTextElement.php index 95f9eb00c695216da2901a6fa977ca4ecc533d7e..082c8842b4ecbc8dd66eded1310800d055c19881 100644 --- a/typo3/sysext/backend/Classes/Form/Element/InputTextElement.php +++ b/typo3/sysext/backend/Classes/Form/Element/InputTextElement.php @@ -30,7 +30,6 @@ use TYPO3\CMS\Core\Utility\StringUtility; */ class InputTextElement extends AbstractFormElement { - use CustomEvaluationTrait; use OnFieldChangeTrait; /**