[TASK] Add Fluid expressions and pre-processors global config 95/54395/4
authorClaus Due <claus@namelesscoder.net>
Sat, 14 Oct 2017 12:19:49 +0000 (14:19 +0200)
committerJigal van Hemert <jigal.van.hemert@typo3.org>
Tue, 7 Nov 2017 12:55:39 +0000 (13:55 +0100)
This patch moves a previously hardcoded list of Fluid
implementations from the RenderingContext constructor,
to TYPO3_CONF_VARS. Extensions and site administrators
can then add their own implementations to this array and
have them be used in every RenderingContext.

See included RST file for further information on usage.

Change-Id: I6190ceb410e1121ea935a31237cb8bcd0b2f0417
Resolves: #82763
Releases: master, 8.7
Reviewed-on: https://review.typo3.org/54395
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Mattias Nilsson <tollepjaer@gmail.com>
Tested-by: Mattias Nilsson <tollepjaer@gmail.com>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Jan Stockfisch <jan.stockfisch@googlemail.com>
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
typo3/sysext/core/Configuration/DefaultConfiguration.php
typo3/sysext/core/Documentation/Changelog/master/Important-82763-GlobalFluidExpressionNodeTypeAndTemplatePreProcessorConfiguration.rst [new file with mode: 0644]
typo3/sysext/fluid/Classes/Core/Rendering/RenderingContext.php

index f9d0494..76001ce 100644 (file)
@@ -272,6 +272,16 @@ return [
         ],
         'fluid' => [
             'interceptors' => [],
+            'preProcessors' => [
+                \TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\EscapingModifierTemplateProcessor::class,
+                \TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\PassthroughSourceModifierTemplateProcessor::class,
+                \TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\NamespaceDetectionTemplateProcessor::class
+            ],
+            'expressionNodeTypes' => [
+                \TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\Expression\CastingExpressionNode::class,
+                \TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\Expression\MathExpressionNode::class,
+                \TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\Expression\TernaryExpressionNode::class
+            ],
             'namespaces' => [
                 'core' => [
                     'TYPO3\\CMS\\Core\\ViewHelpers'
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Important-82763-GlobalFluidExpressionNodeTypeAndTemplatePreProcessorConfiguration.rst b/typo3/sysext/core/Documentation/Changelog/master/Important-82763-GlobalFluidExpressionNodeTypeAndTemplatePreProcessorConfiguration.rst
new file mode 100644 (file)
index 0000000..f6c16f5
--- /dev/null
@@ -0,0 +1,40 @@
+.. include:: ../../Includes.txt
+
+============================================================================================
+Important: #82763 - Fluid config for ExpressionNodeType and TemplatePreProcessor made global
+============================================================================================
+
+See :issue:`82763`
+
+Description
+===========
+
+Before, Fluid's arrays of class names for ``ExpressionNodeType`` and ``TemplatePreProcessor`` were hardcoded into the
+``RenderingContext`` constructor and were not possible to modify except when having access to the ``RenderingContext``.
+
+Now, these two arrays of class names are possible to configure in ``TYPO3_CONF_VARS`` which allows extensions or site
+administrators to add and remove such Fluid components on a global level.
+
+Example:
+
+.. code-block:: php
+
+    // Add one new ExpressionNodeType and one new TemplatePreProcessor to be used in every RenderingContext
+    // For example from an ext_localconf.php file in an extension.
+    $GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['expressionNodeTypes'][] = \MyVendor\MyExtension\MyFluidExpressionNodeType::class;
+    $GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['preProcessors'][] = \MyVendor\MyExtension\MyFluidTemplatePreProcessor::class;
+
+These classes will then be *added to the list of existing implementations* and will be automatically used as defaults
+when new ``RenderingContext`` instances are created.
+
+See for reference how to create such implementations:
+
+* ``\TYPO3Fluid\Fluid\Core\Parser\TemplateProcessorInterface``
+* ``\TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\Expression\ExpressionNodeInterface``
+
+Both interfaces contain the documentation for how they must be implemented, when/why functions get called and what the
+expected return types are. The interfaces must of course be implemented by classes you add to ``TYPO3_CONF_VARS`` in
+these configuration sections. Due to their global nature you should be very careful to implement the classes and in
+particular observe the return types.
+
+.. index:: Fluid
\ No newline at end of file
index 8164630..4ffc0c5 100644 (file)
@@ -24,9 +24,6 @@ use TYPO3\CMS\Fluid\View\TemplatePaths;
 use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
 use TYPO3Fluid\Fluid\Core\Parser\Configuration;
 use TYPO3Fluid\Fluid\Core\Parser\TemplateParser;
-use TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\EscapingModifierTemplateProcessor;
-use TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\NamespaceDetectionTemplateProcessor;
-use TYPO3Fluid\Fluid\Core\Parser\TemplateProcessor\PassthroughSourceModifierTemplateProcessor;
 use TYPO3Fluid\Fluid\Core\Variables\StandardVariableProvider;
 use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInvoker;
 use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperVariableContainer;
@@ -70,16 +67,11 @@ class RenderingContext extends \TYPO3Fluid\Fluid\Core\Rendering\RenderingContext
             $this->setViewHelperInvoker(new ViewHelperInvoker());
             $this->setViewHelperVariableContainer(new ViewHelperVariableContainer());
             $this->setVariableProvider(new StandardVariableProvider());
-            $this->setTemplateProcessors(
-                [
-                    new EscapingModifierTemplateProcessor(),
-                    new PassthroughSourceModifierTemplateProcessor(),
-                    new NamespaceDetectionTemplateProcessor()
-                ]
-            );
         }
 
         $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
+        $this->setTemplateProcessors(array_map([$objectManager, 'get'], $GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['preProcessors']));
+        $this->setExpressionNodeTypes($GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['expressionNodeTypes']);
         $this->setTemplatePaths($objectManager->get(TemplatePaths::class));
         $this->setViewHelperResolver($objectManager->get(ViewHelperResolver::class));