From 3c1c58cc97d8898944e46297440dea0c2c6704f2 Mon Sep 17 00:00:00 2001 From: Claus Due Date: Mon, 9 Dec 2024 14:48:59 +0100 Subject: [PATCH] [TASK] Avoid Fluid compile trait --- Classes/ViewHelpers/AbstractFormViewHelper.php | 8 ++++++++ Classes/ViewHelpers/Content/GetViewHelper.php | 11 ++++++++--- .../ViewHelpers/Content/RenderViewHelper.php | 2 +- Classes/ViewHelpers/Form/DataViewHelper.php | 14 ++++++++++---- Classes/ViewHelpers/Form/OptionViewHelper.php | 13 ++++++++++--- Classes/ViewHelpers/Form/RenderViewHelper.php | 11 ++++++++--- .../ViewHelpers/Form/VariableViewHelper.php | 15 +++++++++++---- Classes/ViewHelpers/InlineViewHelper.php | 18 ++++++++++++++---- phpstan-baseline.neon | 4 ++++ 9 files changed, 74 insertions(+), 22 deletions(-) diff --git a/Classes/ViewHelpers/AbstractFormViewHelper.php b/Classes/ViewHelpers/AbstractFormViewHelper.php index ac12e9384..45fe8776b 100755 --- a/Classes/ViewHelpers/AbstractFormViewHelper.php +++ b/Classes/ViewHelpers/AbstractFormViewHelper.php @@ -27,6 +27,14 @@ abstract class AbstractFormViewHelper extends AbstractViewHelper const SCOPE_VARIABLE_CONTAINER = 'container'; const SCOPE_VARIABLE_GRIDS = 'grids'; + /** + * @return string + */ + public function render() + { + return static::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext); + } + protected function callRenderMethod(): string { return static::renderStatic( diff --git a/Classes/ViewHelpers/Content/GetViewHelper.php b/Classes/ViewHelpers/Content/GetViewHelper.php index ed2f565f5..fa203e462 100644 --- a/Classes/ViewHelpers/Content/GetViewHelper.php +++ b/Classes/ViewHelpers/Content/GetViewHelper.php @@ -25,7 +25,6 @@ use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; use TYPO3Fluid\Fluid\Core\ViewHelper\Exception; -use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; /** * Gets all child content of a record based on area. @@ -55,8 +54,6 @@ */ class GetViewHelper extends AbstractViewHelper { - use CompileWithRenderStatic; - /** * @var boolean */ @@ -88,6 +85,14 @@ public function initializeArguments(): void $this->registerArgument('hideUntranslated', 'boolean', 'Exclude untranslated records', false, false); } + /** + * @return array|string|null + */ + public function render() + { + return static::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext); + } + /** * @return string|array|null */ diff --git a/Classes/ViewHelpers/Content/RenderViewHelper.php b/Classes/ViewHelpers/Content/RenderViewHelper.php index b2c4f7c94..249021c07 100644 --- a/Classes/ViewHelpers/Content/RenderViewHelper.php +++ b/Classes/ViewHelpers/Content/RenderViewHelper.php @@ -51,7 +51,7 @@ public static function renderStatic( RenderingContextInterface $renderingContext ) { $content = parent::renderStatic($arguments, $renderChildrenClosure, $renderingContext); - if (true === is_array($content)) { + if (is_array($content)) { return implode(PHP_EOL, $content); } return $content; diff --git a/Classes/ViewHelpers/Form/DataViewHelper.php b/Classes/ViewHelpers/Form/DataViewHelper.php index 7cf8fc116..173242b7e 100644 --- a/Classes/ViewHelpers/Form/DataViewHelper.php +++ b/Classes/ViewHelpers/Form/DataViewHelper.php @@ -19,7 +19,6 @@ use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; use TYPO3Fluid\Fluid\Core\ViewHelper\Exception; -use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; /** * Converts raw flexform xml into an associative array, and applies any @@ -47,8 +46,6 @@ */ class DataViewHelper extends AbstractViewHelper { - use CompileWithRenderStatic; - /** * @var boolean */ @@ -68,7 +65,15 @@ public function initializeArguments(): void } /** - * @return mixed + * @return array + */ + public function render() + { + return self::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext); + } + + /** + * @return array */ public static function renderStatic( array $arguments, @@ -117,6 +122,7 @@ public static function renderStatic( 1387049117 ); } + /** @var array $dataArray */ $dataArray = HookHandler::trigger( HookHandler::FORM_DATA_FETCHED, [ diff --git a/Classes/ViewHelpers/Form/OptionViewHelper.php b/Classes/ViewHelpers/Form/OptionViewHelper.php index 0395f0502..abb3689f1 100755 --- a/Classes/ViewHelpers/Form/OptionViewHelper.php +++ b/Classes/ViewHelpers/Form/OptionViewHelper.php @@ -12,15 +12,12 @@ use FluidTYPO3\Flux\Form\OptionCarryingInterface; use FluidTYPO3\Flux\ViewHelpers\AbstractFormViewHelper; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; -use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic; /** * Form option ViewHelper */ class OptionViewHelper extends AbstractFormViewHelper { - use CompileWithContentArgumentAndRenderStatic; - public static string $option = ''; public function initializeArguments(): void @@ -29,6 +26,11 @@ public function initializeArguments(): void $this->registerArgument('name', 'string', 'Name of the option to be set', true); } + public function render() + { + return self::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext); + } + public static function renderStatic( array $arguments, \Closure $renderChildrenClosure, @@ -54,4 +56,9 @@ public static function renderStatic( 1602693000 ); } + + public function getContentArgumentName(): ?string + { + return 'value'; + } } diff --git a/Classes/ViewHelpers/Form/RenderViewHelper.php b/Classes/ViewHelpers/Form/RenderViewHelper.php index 86398a9f6..e2e3515c9 100644 --- a/Classes/ViewHelpers/Form/RenderViewHelper.php +++ b/Classes/ViewHelpers/Form/RenderViewHelper.php @@ -15,7 +15,6 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; -use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; /** * ## Main form rendering ViewHelper @@ -24,8 +23,6 @@ */ class RenderViewHelper extends AbstractViewHelper { - use CompileWithRenderStatic; - /** * @var boolean */ @@ -36,6 +33,14 @@ public function initializeArguments(): void $this->registerArgument('form', Form::class, 'Form instance to render as HTML', true); } + /** + * @return string + */ + public function render() + { + return self::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext); + } + public static function renderStatic( array $arguments, \Closure $renderChildrenClosure, diff --git a/Classes/ViewHelpers/Form/VariableViewHelper.php b/Classes/ViewHelpers/Form/VariableViewHelper.php index e91ea1a58..9aad0cd99 100644 --- a/Classes/ViewHelpers/Form/VariableViewHelper.php +++ b/Classes/ViewHelpers/Form/VariableViewHelper.php @@ -11,15 +11,12 @@ use FluidTYPO3\Flux\ViewHelpers\AbstractFormViewHelper; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; -use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic; /** * Sets an option in the Form instance */ class VariableViewHelper extends AbstractFormViewHelper { - use CompileWithContentArgumentAndRenderStatic; - public function initializeArguments(): void { $this->registerArgument('value', 'mixed', 'Value of the option'); @@ -32,6 +29,11 @@ public function initializeArguments(): void ); } + public function render() + { + return self::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext); + } + public static function renderStatic( array $arguments, \Closure $renderChildrenClosure, @@ -40,7 +42,12 @@ public static function renderStatic( /** @var string $variableName */ $variableName = $arguments['name']; static::getContainerFromRenderingContext($renderingContext) - ->setVariable($variableName, $renderChildrenClosure()); + ->setVariable($variableName, $arguments['value'] ?? $renderChildrenClosure()); return ''; } + + public function getContentArgumentName(): ?string + { + return 'value'; + } } diff --git a/Classes/ViewHelpers/InlineViewHelper.php b/Classes/ViewHelpers/InlineViewHelper.php index c6aebac60..2fd8b0c02 100644 --- a/Classes/ViewHelpers/InlineViewHelper.php +++ b/Classes/ViewHelpers/InlineViewHelper.php @@ -12,7 +12,6 @@ use TYPO3Fluid\Fluid\Core\Parser\Source; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; -use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic; /** * Inline Fluid rendering ViewHelper @@ -37,8 +36,6 @@ */ class InlineViewHelper extends AbstractViewHelper { - use CompileWithContentArgumentAndRenderStatic; - /** * @var boolean */ @@ -59,6 +56,14 @@ public function initializeArguments(): void ); } + /** + * @return mixed + */ + public function render() + { + return self::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext); + } + /** * @return mixed */ @@ -67,10 +72,15 @@ public static function renderStatic( \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext ) { - $source = $renderChildrenClosure(); + $source = (string) ($arguments['code'] ?? $renderChildrenClosure()); return $renderingContext->getTemplateParser() ->parse(class_exists(Source::class) ? new Source($source) : $source) ->getRootNode() ->evaluate($renderingContext); } + + public function getContentArgumentName(): ?string + { + return 'code'; + } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 0a82518db..e8162c8f8 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,5 +1,9 @@ parameters: ignoreErrors: + - + message: "#^Parameter \\#1 \\$templateString of method TYPO3Fluid\\\\Fluid\\\\Core\\\\Parser\\\\TemplateParser\\:\\:parse\\(\\) expects string, string\\|TYPO3Fluid\\\\Fluid\\\\Core\\\\Parser\\\\Source given\\.$#" + count: 1 + path: Classes/ViewHelpers/InlineViewHelper.php - message: "#^Call to an undefined method Doctrine\\\\DBAL\\\\Result\\:\\:fetch(All)?\\(\\)\\.$#" count: 2