/**
  * @test
  */
 public function processorIsCalled()
 {
     $contentObjectRendererStub = new ContentObjectRenderer();
     $config = ['dataProcessing.' => ['10' => DataProcessorFixture::class, '10.' => ['foo' => 'bar']]];
     $variables = [];
     $this->assertSame(['foo' => 'bar'], $this->contentDataProcessor->process($contentObjectRendererStub, $config, $variables));
 }
 /**
  * Fetches records from the database as an array
  *
  * @param ContentObjectRenderer $cObj The data of the content element or page
  * @param array $contentObjectConfiguration The configuration of Content Object
  * @param array $processorConfiguration The configuration of this processor
  * @param array $processedData Key/value store of processed data (e.g. to be passed to a Fluid View)
  *
  * @return array the processed data as key/value store
  */
 public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
 {
     if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) {
         return $processedData;
     }
     // the table to query, if none given, exit
     $tableName = $cObj->stdWrapValue('table', $processorConfiguration);
     if (empty($tableName)) {
         return $processedData;
     }
     if (isset($processorConfiguration['table.'])) {
         unset($processorConfiguration['table.']);
     }
     if (isset($processorConfiguration['table'])) {
         unset($processorConfiguration['table']);
     }
     // The variable to be used within the result
     $targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, 'records');
     // Execute a SQL statement to fetch the records
     $records = $cObj->getRecords($tableName, $processorConfiguration);
     $processedRecordVariables = array();
     foreach ($records as $key => $record) {
         /** @var ContentObjectRenderer $recordContentObjectRenderer */
         $recordContentObjectRenderer = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
         $recordContentObjectRenderer->start($record, $tableName);
         $processedRecordVariables[$key] = array('data' => $record);
         $processedRecordVariables[$key] = $this->contentDataProcessor->process($recordContentObjectRenderer, $processorConfiguration, $processedRecordVariables[$key]);
     }
     $processedData[$targetVariableName] = $processedRecordVariables;
     return $processedData;
 }
 /**
  * Rendering the cObject, FLUIDTEMPLATE
  *
  * Configuration properties:
  * - file string+stdWrap The FLUID template file
  * - layoutRootPaths array of filepath+stdWrap Root paths to layouts (fallback)
  * - partialRootPaths array of filepath+stdWrap Root paths to partials (fallback)
  * - variable array of cObjects, the keys are the variable names in fluid
  * - dataProcessing array of data processors which are classes to manipulate $data
  * - extbase.pluginName
  * - extbase.controllerExtensionName
  * - extbase.controllerName
  * - extbase.controllerActionName
  *
  * Example:
  * 10 = FLUIDTEMPLATE
  * 10.templateName = MyTemplate
  * 10.templateRootPaths.10 = EXT:site_configuration/Resources/Private/Templates/
  * 10.partialRootPaths.10 = EXT:site_configuration/Resources/Private/Patials/
  * 10.layoutRootPaths.10 = EXT:site_configuration/Resources/Private/Layouts/
  * 10.variables {
  *   mylabel = TEXT
  *   mylabel.value = Label from TypoScript coming
  * }
  *
  * @param array $conf Array of TypoScript properties
  * @return string The HTML output
  */
 public function render($conf = array())
 {
     $parentView = $this->view;
     $this->initializeStandaloneViewInstance();
     if (!is_array($conf)) {
         $conf = array();
     }
     $this->setFormat($conf);
     $this->setTemplate($conf);
     $this->setLayoutRootPath($conf);
     $this->setPartialRootPath($conf);
     $this->setExtbaseVariables($conf);
     $this->assignSettings($conf);
     $variables = $this->getContentObjectVariables($conf);
     $variables = $this->contentDataProcessor->process($this->cObj, $conf, $variables);
     $this->view->assignMultiple($variables);
     $content = $this->renderFluidView();
     $content = $this->applyStandardWrapToRenderedContent($content, $conf);
     $this->view = $parentView;
     return $content;
 }
Ejemplo n.º 4
0
 /**
  * Process additional data processors
  *
  * @param array $page
  * @param array $processorConfiguration
  */
 protected function processAdditionalDataProcessors($page, $processorConfiguration)
 {
     if (is_array($page['children'])) {
         foreach ($page['children'] as $key => $item) {
             $page['children'][$key] = $this->processAdditionalDataProcessors($item, $processorConfiguration);
         }
     }
     /** @var ContentObjectRenderer $recordContentObjectRenderer */
     $recordContentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class);
     $recordContentObjectRenderer->start($page['data'], 'pages');
     $processedPage = $this->contentDataProcessor->process($recordContentObjectRenderer, $processorConfiguration, $page);
     return $processedPage;
 }