Commit 1643c457 authored by Christian Kuhn's avatar Christian Kuhn
Browse files

[TASK] Avoid a useless trait in FormEngine

ext:backend Form/Element recently got a trait with #95954
that can be easily avoided by adding the method to
AbstractFormElement, which all elements should extend.

Resolves: #96071
Related: #95954
Releases: master, 11.5
Change-Id: I8dc73f17b976f8191bf39bae5b51f2609778797c
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72281

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Jochen's avatarJochen <rothjochen@gmail.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Oliver Hader's avatarOliver Hader <oliver.hader@typo3.org>
Reviewed-by: Jochen's avatarJochen <rothjochen@gmail.com>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent f9c28d48
......@@ -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
***********************************************/
......
<?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;
}
}
......@@ -26,8 +26,6 @@ use TYPO3\CMS\Core\Utility\StringUtility;
*/
class InputColorPickerElement extends AbstractFormElement
{
use CustomEvaluationTrait;
/**
* Default field information enabled for this element.
*
......
......@@ -39,7 +39,6 @@ use TYPO3\CMS\Frontend\Service\TypoLinkCodecService;
*/
class InputLinkElement extends AbstractFormElement
{
use CustomEvaluationTrait;
use OnFieldChangeTrait;
/**
......
......@@ -30,7 +30,6 @@ use TYPO3\CMS\Core\Utility\StringUtility;
*/
class InputTextElement extends AbstractFormElement
{
use CustomEvaluationTrait;
use OnFieldChangeTrait;
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment