/** * Generate variable Get string from classMappings array with the same key as the "layout" in the content * * @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; } // set targetvariable, default "layoutClass" $targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, 'layoutClass'); $processedData[$targetVariableName] = ''; // set fieldname, default "layout" $fieldName = $cObj->stdWrapValue('fieldName', $processorConfiguration, 'layout'); if (isset($cObj->data[$fieldName]) && is_array($processorConfiguration['classMappings.'])) { $layoutClassMappings = GeneralUtility::removeDotsFromTS($processorConfiguration['classMappings.']); $processedData[$targetVariableName] = $layoutClassMappings[$cObj->data[$fieldName]]; } // if targetvariable is settings, try to merge it with contentObjectConfiguration['settings.'] if ($targetVariableName == 'settings') { if (is_array($contentObjectConfiguration['settings.'])) { $convertedConf = GeneralUtility::removeDotsFromTS($contentObjectConfiguration['settings.']); foreach ($convertedConf as $key => $value) { if (!isset($processedData[$targetVariableName][$key]) || $processedData[$targetVariableName][$key] == false) { $processedData[$targetVariableName][$key] = $value; } } } } return $processedData; }
/** * Process flexform field data to 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; } // set targetvariable, default "flexform" $targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, 'flexform'); // set fieldname, default "pi_flexform" $fieldName = $cObj->stdWrapValue('fieldName', $processorConfiguration, 'pi_flexform'); // parse flexform $flexformService = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Service\\FlexFormService'); $processedData[$targetVariableName] = $flexformService->convertFlexFormContentToArray($cObj->data[$fieldName]); // if targetvariable is settings, try to merge it with contentObjectConfiguration['settings.'] if ($targetVariableName == 'settings') { if (is_array($contentObjectConfiguration['settings.'])) { $convertedConf = GeneralUtility::removeDotsFromTS($contentObjectConfiguration['settings.']); foreach ($convertedConf as $key => $value) { if (!isset($processedData[$targetVariableName][$key]) || $processedData[$targetVariableName][$key] == false) { $processedData[$targetVariableName][$key] = $value; } } } } return $processedData; }
/** * 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; }
/** * Process field data to split in 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 field name to process $fieldName = $cObj->stdWrapValue('fieldName', $processorConfiguration); if (empty($fieldName)) { return $processedData; } $originalValue = $cObj->data[$fieldName]; // Set the target variable $targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, $fieldName); // Set the delimiter which is "LF" by default $delimiter = $cObj->stdWrapValue('delimiter', $processorConfiguration, LF); // Filter integers $filterIntegers = (bool) $cObj->stdWrapValue('filterIntegers', $processorConfiguration, false); // Filter unique $filterUnique = (bool) $cObj->stdWrapValue('filterUnique', $processorConfiguration, false); // Remove empty entries $removeEmptyEntries = (bool) $cObj->stdWrapValue('removeEmptyEntries', $processorConfiguration, false); if ($filterIntegers === true) { $processedData[$targetVariableName] = GeneralUtility::intExplode($delimiter, $originalValue, $removeEmptyEntries); } else { $processedData[$targetVariableName] = GeneralUtility::trimExplode($delimiter, $originalValue, $removeEmptyEntries); } if ($filterUnique === true) { $processedData[$targetVariableName] = array_unique($processedData[$targetVariableName]); } 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); $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 flexform field data to 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; } $this->cObj = $cObj; $languages = array(); // set targetvariable, default "flexform" $targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, 'languages'); $availableLanguages = array_unique(GeneralUtility::trimExplode(',', '0,' . $processorConfiguration['availableLanguages'], TRUE)); $currentLanguageUid = (int) $processorConfiguration['currentLanguageUid']; $defaultLanguageIsoCode = $processorConfiguration['defaultLanguageIsoCode'] ? $processorConfiguration['defaultLanguageIsoCode'] : 'en'; $defaultLanguageLabel = $processorConfiguration['defaultLanguageLabel'] ? $processorConfiguration['defaultLanguageLabel'] : 'English'; $defaultLanguageFlag = $processorConfiguration['defaultLanguageFlag'] ? $processorConfiguration['defaultLanguageFlag'] : 'gb'; $flagIconPath = $processorConfiguration['flagIconPath']; $flagIconFileExtension = $processorConfiguration['flagIconFileExtension']; if (!empty($availableLanguages)) { foreach ($availableLanguages as $languageUid) { $languageIsocode = ''; $class = ''; $label = ''; $flag = ''; $hasTranslation = FALSE; if ((int) $languageUid === 0) { $languageIsocode = $defaultLanguageIsoCode; $flag = $defaultLanguageFlag; $label = $defaultLanguageLabel; $hasTranslation = TRUE; } elseif ($sysLanguage = $this->getSysLanguage($languageUid)) { $languageIsocode = $sysLanguage['language_isocode']; $flag = $sysLanguage['flag']; $label = $sysLanguage['title']; $hasTranslation = $this->hasTranslation($GLOBALS['TSFE']->id, $languageUid); } $languages[] = array('L' => $languageUid, 'languageIsocode' => $languageIsocode, 'label' => $label, 'flag' => $flag, 'hasTranslation' => $hasTranslation, 'active' => (int) $currentLanguageUid === (int) $languageUid); } $processedData[$targetVariableName] = $languages; } // if targetvariable is settings, try to merge it with contentObjectConfiguration['settings.'] if ($targetVariableName == 'settings') { if (is_array($contentObjectConfiguration['settings.'])) { $convertedConf = GeneralUtility::removeDotsFromTS($contentObjectConfiguration['settings.']); foreach ($convertedConf as $key => $value) { if (!isset($processedData[$targetVariableName][$key]) || $processedData[$targetVariableName][$key] == false) { $processedData[$targetVariableName][$key] = $value; } } } } 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; }
/** * Process CSV field data to split into a multi dimensional 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 field name to process $fieldName = $cObj->stdWrapValue('fieldName', $processorConfiguration); if (empty($fieldName)) { return $processedData; } $originalValue = $cObj->data[$fieldName]; // Set the target variable $targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, $fieldName); // Set the maximum amount of columns $maximumColumns = $cObj->stdWrapValue('maximumColumns', $processorConfiguration, 0); // Set the field delimiter which is "," by default $fieldDelimiter = $cObj->stdWrapValue('fieldDelimiter', $processorConfiguration, ','); // Set the field enclosure which is " by default $fieldEnclosure = $cObj->stdWrapValue('fieldEnclosure', $processorConfiguration, '"'); $processedData[$targetVariableName] = CsvUtility::csvToArray($originalValue, $fieldDelimiter, $fieldEnclosure, (int) $maximumColumns); return $processedData; }
/** * Preprocess fields from database-record for use in fluid-templates * * @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 field name to process $fieldName = $cObj->stdWrapValue('fieldName', $processorConfiguration); if (empty($fieldName)) { return $processedData; } // Set the target variable $defaultTargetName = GeneralUtility::underscoredToLowerCamelCase($fieldName); $targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, $defaultTargetName); // Let's see if we got a parentField from which the values should be retrieved $parentField = $cObj->stdWrapValue('parentField', $processorConfiguration); // Get settings from TypoScript if (!empty($parentField)) { $settings = $contentObjectConfiguration['settings.'][$fieldName . '.'][$cObj->data[$parentField] . '.']; } else { $settings = $contentObjectConfiguration['settings.'][$fieldName . '.']; } // Get value database $fieldValue = $cObj->data[$fieldName]; // Fill output with value from TypoScript if (!empty($fieldValue)) { // Use the value defined in database $output = $settings[$fieldValue]; } else { if ($settings['default'] !== '' && $settings[$settings['default']] !== '') { // Use default value (if set) $output = $settings[$settings['default']]; } else { $output = ''; } } $processedData[$targetVariableName] = $output; return $processedData; }
/** * Process data for a gallery, for instance the CType "textmedia" * * @param ContentObjectRenderer $cObj The content object renderer, which contains data of the content element * @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 * @throws ContentRenderingException */ public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData) { if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) { return $processedData; } $this->contentObjectRenderer = $cObj; $this->processorConfiguration = $processorConfiguration; $filesProcessedDataKey = (string) $cObj->stdWrapValue('filesProcessedDataKey', $processorConfiguration, 'files'); if (isset($processedData[$filesProcessedDataKey]) && is_array($processedData[$filesProcessedDataKey])) { $this->fileObjects = $processedData[$filesProcessedDataKey]; $this->galleryData['count']['files'] = count($this->fileObjects); } else { throw new ContentRenderingException('No files found for key ' . $filesProcessedDataKey . ' in $processedData.', 1436809789); } $this->numberOfColumns = (int) $this->getConfigurationValue('numberOfColumns', 'imagecols'); $this->mediaOrientation = (int) $this->getConfigurationValue('mediaOrientation', 'imageorient'); $this->maxGalleryWidth = (int) $this->getConfigurationValue('maxGalleryWidth') ?: 600; $this->maxGalleryWidthInText = (int) $this->getConfigurationValue('maxGalleryWidthInText') ?: 300; $this->equalMediaHeight = (int) $this->getConfigurationValue('equalMediaHeight', 'imageheight'); $this->equalMediaWidth = (int) $this->getConfigurationValue('equalMediaWidth', 'imagewidth'); $this->columnSpacing = (int) $this->getConfigurationValue('columnSpacing'); $this->borderEnabled = (bool) $this->getConfigurationValue('borderEnabled', 'imageborder'); $this->borderWidth = (int) $this->getConfigurationValue('borderWidth'); $this->borderPadding = (int) $this->getConfigurationValue('borderPadding'); $this->determineGalleryPosition(); $this->determineMaximumGalleryWidth(); $this->calculateRowsAndColumns(); $this->calculateMediaWidthsAndHeights(); $this->prepareGalleryData(); $targetFieldName = (string) $cObj->stdWrapValue('as', $processorConfiguration, 'gallery'); $processedData[$targetFieldName] = $this->galleryData; return $processedData; }
/** * Process data for a gallery, for instance the CType "textmedia" * * @param ContentObjectRenderer $cObj The content object renderer, which contains data of the content element * @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 * @throws ContentRenderingException */ public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData) { if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) { return $processedData; } $this->contentObjectRenderer = $cObj; $this->processorConfiguration = $processorConfiguration; $filesProcessedDataKey = (string) $cObj->stdWrapValue('filesProcessedDataKey', $processorConfiguration, 'files'); if (isset($processedData[$filesProcessedDataKey]) && is_array($processedData[$filesProcessedDataKey])) { $this->fileObjects = $processedData[$filesProcessedDataKey]; $this->galleryData['count']['files'] = count($this->fileObjects); } else { throw new ContentRenderingException('No files found for key ' . $filesProcessedDataKey . ' in $processedData.', 1436809789); } // If carousel is enabled, there is only one column in use $this->galleryCarousel = (int) $cObj->data['gallery_carousel']; $this->numberOfColumns = empty($this->galleryCarousel) ? (int) $this->getConfigurationValue('numberOfColumns', 'imagecols') : 1; $this->mediaOrientation = (int) $this->getConfigurationValue('mediaOrientation', 'imageorient'); $this->maxGalleryWidth = (int) $this->getConfigurationValue('maxGalleryWidth') ?: 1140; $this->maxGalleryWidthInText = (int) $this->getConfigurationValue('maxGalleryWidthInText') ?: 737; $this->equalMediaHeight = (int) $this->getConfigurationValue('equalMediaHeight', 'imageheight'); $this->equalMediaWidth = (int) $this->getConfigurationValue('equalMediaWidth', 'imagewidth'); $this->columnSpacing = (int) $this->getConfigurationValue('columnSpacing'); $this->borderEnabled = (bool) $this->getConfigurationValue('borderEnabled', 'imageborder'); $this->borderWidth = (int) $this->getConfigurationValue('borderWidth'); $this->borderPadding = (int) $this->getConfigurationValue('borderPadding'); $this->gridColumns = (int) $this->getConfigurationValue('gridColumns') ?: 12; $this->galleryResponsiveMinWidth = (int) $this->getConfigurationValue('galleryResponsiveMinWidth') ?: 737; $this->galleryWidth = (int) $this->getConfigurationValue('galleryWidth', 'gallery_width'); $this->columnClass = $this->getConfigurationValue('columnClass') ?: 'col-xs-(0)'; $this->galleryGridClass = $this->getGalleryGridClass($cObj->data['gallery_break'], $contentObjectConfiguration['settings.']['gallery_break.']); $this->defaultGalleryWidth = (int) $this->getConfigurationValue('defaultGalleryWidth') ?: 4; $this->headerAboveContent = (int) $this->getConfigurationValue('headerAboveContent') ?: '0, 1, 2, 8, 9, 10, 17, 18'; $this->galleryAboveContent = (int) $this->getConfigurationValue('galleryAboveContent') ?: '0, 1, 2, 17, 18, 26'; $this->determineGalleryPosition(); $this->determineMaximumGalleryWidth(); $this->determineRelationsToContent(); $this->calculateRowsAndColumns(); $this->calculateMediaWidthsAndHeights(); $this->prepareGalleryData(); $this->extendGalleryData(); $targetFieldName = (string) $cObj->stdWrapValue('as', $processorConfiguration, 'gallery'); $processedData[$targetFieldName] = $this->galleryData; //\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this->galleryData, '$this->galleryData'); return $processedData; }