/** * Process data of a record to resolve File objects to the view * * @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; } // gather data /** @var FileCollector $fileCollector */ $fileCollector = GeneralUtility::makeInstance(FileCollector::class); $settings = $contentObjectConfiguration['settings.']['display_mode.']; // references / relations if (!empty($processorConfiguration['references.'])) { $referenceConfiguration = $processorConfiguration['references.']; $relationField = $cObj->stdWrapValue('fieldName', $referenceConfiguration); // If no reference fieldName is set, there's nothing to do if (!empty($relationField)) { // Fetch the references of the default element $relationTable = $cObj->stdWrapValue('table', $referenceConfiguration, $cObj->getCurrentTable()); if (!empty($relationTable)) { $fileCollector->addFilesFromRelation($relationTable, $relationField, $cObj->data); } } } // Get files from database-record $files = $fileCollector->getFiles(); if (count($files) > 0) { // Use ImageService for further processing $imageService = self::getImageService(); foreach ($files as $file) { $displayMode = $file->getReferenceProperty('display_mode'); $image = $imageService->getImage(null, $file, true); $processingInstructions = ['crop' => $image->getProperty('crop')]; $maxWidth = intval($contentObjectConfiguration['settings.']['display_mode_maxWidth.'][$displayMode]); if ($maxWidth > 0) { $processingInstructions['maxWidth'] = $maxWidth; } $processedImage = $imageService->applyProcessingInstructions($image, $processingInstructions); $styleAttribute = 'background-image:url(\'' . $imageService->getImageUri($processedImage) . '\');'; switch ($displayMode) { case '1': $targetVariableName = 'layoutMedia'; break; default: $targetVariableName = 'backgroundMedia'; break; } $processedData[$targetVariableName]['fileReference'] = $file; $processedData[$targetVariableName]['class'] = $settings[$displayMode]; $processedData[$targetVariableName]['style'] = $styleAttribute; } } //\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($files, '$files'); return $processedData; }
/** * Process data of a record to resolve File objects to the view * * @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; } // gather data /** @var FileCollector $fileCollector */ $fileCollector = GeneralUtility::makeInstance(FileCollector::class); // references / relations if (!empty($processorConfiguration['references.'])) { $referenceConfiguration = $processorConfiguration['references.']; $relationField = $cObj->stdWrapValue('fieldName', $referenceConfiguration); // If no reference fieldName is set, there's nothing to do if (!empty($relationField)) { // Fetch the references of the default element $relationTable = $cObj->stdWrapValue('table', $referenceConfiguration, $cObj->getCurrentTable()); if (!empty($relationTable)) { $fileCollector->addFilesFromRelation($relationTable, $relationField, $cObj->data); } } } // files $files = $cObj->stdWrapValue('files', $processorConfiguration); if ($files) { $files = GeneralUtility::intExplode(',', $files, TRUE); $fileCollector->addFiles($files); } // collections $collections = $cObj->stdWrapValue('collections', $processorConfiguration); if (!empty($collections)) { $collections = GeneralUtility::trimExplode(',', $collections, TRUE); $fileCollector->addFilesFromFileCollections($collections); } // folders $folders = $cObj->stdWrapValue('folders', $processorConfiguration); if (!empty($folders)) { $folders = GeneralUtility::trimExplode(',', $folders, TRUE); $fileCollector->addFilesFromFolders($folders); } // make sure to sort the files $sortingProperty = $cObj->stdWrapValue('sorting', $processorConfiguration); if ($sortingProperty) { $sortingDirection = $cObj->stdWrapValue('direction', isset($processorConfiguration['sorting.']) ? $processorConfiguration['sorting.'] : array(), 'ascending'); $fileCollector->sort($sortingProperty, $sortingDirection); } // set the files into a variable, default "files" $targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, 'files'); $processedData[$targetVariableName] = $fileCollector->getFiles(); return $processedData; }
/** * Hook to extend the Data Array of the Object with the FlexForm fields * * @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $pObject * @return bool */ public function postProcessContentObjectInitialization(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer &$pObject) { if (isset($pObject->data['tx_contentdesigner_flexform'])) { $objData = $pObject->data['tx_contentdesigner_flexform']; } elseif (isset($GLOBALS['TSFE']->page['tx_contentdesigner_flexform'])) { $objData = $GLOBALS['TSFE']->page['tx_contentdesigner_flexform']; } else { return false; } if (empty($objData)) { return false; } $ffh = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Service\\FlexFormService'); $flexArray = $ffh->convertFlexFormContentToArray($objData); if (is_array($flexArray['settings']['flexform'])) { if ($pObject->getCurrentTable() == 'pages') { $this->mergeData($pObject, $flexArray['settings']['flexform']); } if ($pObject->getCurrentTable() == 'tt_content') { $this->mergeData($pObject, $flexArray['settings']['flexform']); } unset($flexArray['settings']['flexform']); } if (is_array($flexArray['settings'])) { if ($pObject->getCurrentTable() == 'pages') { $this->mergeData($pObject, $flexArray['settings']); } if ($pObject->getCurrentTable() == 'tt_content') { $this->mergeData($pObject, $flexArray['settings']); } unset($flexArray['settings']); } if (sizeof($flexArray) > 0) { if ($pObject->getCurrentTable() == 'pages') { $this->mergeData($pObject, $flexArray); } if ($pObject->getCurrentTable() == 'tt_content') { $this->mergeData($pObject, $flexArray); } unset($flexArray); } }