[TASK] Move processData functionality into a trait 03/41803/7
authorSascha Egerer <sascha@sascha-egerer.de>
Wed, 22 Jul 2015 09:22:02 +0000 (11:22 +0200)
committerBenjamin Mack <benni@typo3.org>
Fri, 24 Jul 2015 07:09:20 +0000 (09:09 +0200)
The functionality of FluidTemplateContentObject::processData
can be resued in different places and should therefore be
extracted into a trait.

Change-Id: I298eaf9e7285f0f8d6f00b89ee7de130994f4c3f
Resolves: #68459
Releases: master
Reviewed-on: http://review.typo3.org/41803
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Reviewed-by: Benjamin Mack <benni@typo3.org>
Tested-by: Benjamin Mack <benni@typo3.org>
typo3/sysext/frontend/Classes/ContentObject/DataProcessingTrait.php [new file with mode: 0644]
typo3/sysext/frontend/Classes/ContentObject/FluidTemplateContentObject.php

diff --git a/typo3/sysext/frontend/Classes/ContentObject/DataProcessingTrait.php b/typo3/sysext/frontend/Classes/ContentObject/DataProcessingTrait.php
new file mode 100644 (file)
index 0000000..94f0035
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+namespace TYPO3\CMS\Frontend\ContentObject;
+
+/*
+ * 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!
+ */
+
+use TYPO3\CMS\Core\TypoScript\TemplateService;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * A trait that contains methods that can be used to use the dataProcessing functionality
+ */
+trait DataProcessingTrait {
+
+       /**
+        * Check for the availability of processors, defined in TypoScript, and use them for data processing
+        *
+        * @param ContentObjectRenderer $cObject
+        * @param array $configuration Configuration array
+        * @param array $variables the variables to be processed
+        * @return array the processed data and variables as key/value store
+        */
+       protected function processData(ContentObjectRenderer $cObject, array $configuration, array $variables) {
+               if (
+                       !empty($configuration['dataProcessing.'])
+                       && is_array($configuration['dataProcessing.'])
+               ) {
+                       $processors = $configuration['dataProcessing.'];
+                       $processorKeys = TemplateService::sortedKeyList($processors);
+
+                       foreach ($processorKeys as $key) {
+                               $className = $processors[$key];
+                               $processor = GeneralUtility::makeInstance($className);
+
+                               if (!$processor instanceof DataProcessorInterface) {
+                                       throw new \UnexpectedValueException(
+                                               '$processor with class name "' . $className . '" ' .
+                                               'must implement interface "' . DataProcessorInterface::class . '"',
+                                               1427455377
+                                       );
+                               }
+
+                               $processorConfiguration = isset($processors[$key . '.']) ? $processors[$key . '.'] : array();
+
+                               $variables = $processor->process(
+                                       $cObject,
+                                       $configuration,
+                                       $processorConfiguration,
+                                       $variables
+                               );
+                       }
+               }
+
+               return $variables;
+       }
+
+}
index 4f96672..af2766f 100644 (file)
@@ -22,6 +22,7 @@ use TYPO3\CMS\Fluid\View\StandaloneView;
  * Contains FLUIDTEMPLATE class object
  */
 class FluidTemplateContentObject extends AbstractContentObject {
+       use DataProcessingTrait;
 
        /**
         * @var StandaloneView
@@ -71,7 +72,7 @@ class FluidTemplateContentObject extends AbstractContentObject {
                $this->setExtbaseVariables($conf);
                $this->assignSettings($conf);
                $variables = $this->getContentObjectVariables($conf);
-               $variables = $this->processData($conf, $variables);
+               $variables = $this->processData($this->cObj, $conf, $variables);
 
                $this->view->assignMultiple($variables);
 
@@ -228,47 +229,6 @@ class FluidTemplateContentObject extends AbstractContentObject {
        }
 
        /**
-        * Check for the availability of processors, defined in TypoScript, and use them for data processing
-        *
-        * @param array $configuration Configuration array
-        * @param array $variables the variables to be processed
-        * @return array the processed data and variables as key/value store
-        * @throws \UnexpectedValueException
-        */
-       protected function processData(array $configuration, array $variables) {
-               if (
-                       !empty($configuration['dataProcessing.'])
-                       && is_array($configuration['dataProcessing.'])
-               ) {
-                       $processors = $configuration['dataProcessing.'];
-                       $processorKeys = \TYPO3\CMS\Core\TypoScript\TemplateService::sortedKeyList($processors);
-
-                       foreach ($processorKeys as $key) {
-                               $className = $processors[$key];
-                               $processor = GeneralUtility::makeInstance($className);
-
-                               if (!$processor instanceof DataProcessorInterface) {
-                                       throw new \UnexpectedValueException(
-                                               '$processor with class name "' . $className . '" ' .
-                                               'must implement interface "' . DataProcessorInterface::class . '"',
-                                               1427455377
-                                       );
-                               }
-
-                               $processorConfiguration = isset($processors[$key . '.']) ? $processors[$key . '.'] : array();
-
-                               $variables = $processor->process(
-                                       $this->cObj,
-                                       $configuration,
-                                       $processorConfiguration,
-                                       $variables
-                               );
-                       }
-               }
-               return $variables;
-       }
-
-       /**
         * Compile rendered content objects in variables array ready to assign to the view
         *
         * @param array $conf Configuration array