first commit

This commit is contained in:
salam committed 2026-10-06 19:40:28 +02:00
commit e81864e683
2984 files changed
+267797

No files matched your search

@@ -0,0 +1,90 @@
<?php declare(strict_types=1);
/*
* This file is part of the package bk2k/bootstrap-package.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/
namespace BK2K\BootstrapPackage\DataProcessing;
use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
/**
* Minimal TypoScript configuration
* Assign all available typoscript constants for a key to template view, the
* default key that is used is `page` and the default variable is `constants`.
*
* 10 = BK2K\BootstrapPackage\DataProcessing\ConstantsProcessor
*
*
* Advanced TypoScript configuration
*
* 10 = BK2K\BootstrapPackage\DataProcessing\ConstantsProcessor
* 10 {
* key = page
* as = constants
* }
*/
class ConstantsProcessor implements DataProcessorInterface
{
/**
* @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)
{
// The key to process
$key = (string) $cObj->stdWrapValue('key', $processorConfiguration);
if ($key === '') {
$key = 'page';
}
// Collect variables
$flatConstants = $this->getFlatConstants($key);
$typoScriptParser = GeneralUtility::makeInstance(TypoScriptParser::class);
$typoScriptParser->parse($flatConstants);
$typoScriptArray = $typoScriptParser->setup;
$typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
$constants = $typoScriptService->convertTypoScriptArrayToPlainArray($typoScriptArray);
// Set the target variable
$targetVariableName = (string) $cObj->stdWrapValue('as', $processorConfiguration);
if ($targetVariableName !== '') {
$processedData[$targetVariableName] = $constants;
} else {
$processedData['constants'] = $constants;
}
return $processedData;
}
/**
* @param string $key
* @return string
*/
protected function getFlatConstants($key): string
{
$flatvariables = '';
$prefix = $key . '.';
if ($GLOBALS['TSFE']->tmpl->flatSetup === null
|| !is_array($GLOBALS['TSFE']->tmpl->flatSetup)
|| count($GLOBALS['TSFE']->tmpl->flatSetup) === 0) {
$GLOBALS['TSFE']->tmpl->generateConfig();
}
foreach ($GLOBALS['TSFE']->tmpl->flatSetup as $constant => $value) {
if (strpos($constant, $prefix) === 0) {
$flatvariables .= substr($constant, strlen($prefix)) . ' = ' . $value . PHP_EOL;
}
}
return $flatvariables;
}
}
@@ -0,0 +1,79 @@
<?php declare(strict_types=1);
/*
* This file is part of the package bk2k/bootstrap-package.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/
namespace BK2K\BootstrapPackage\DataProcessing;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
/**
* ContainerContextProcessor
*/
class ContainerContextProcessor implements DataProcessorInterface
{
/**
* @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($processedData['data']['tx_container_parent'])
|| $processedData['data']['tx_container_parent'] === 0) {
return $processedData;
}
$processedData['containerContext'] = $this->getContainerContext(
$this->getPageRecords($cObj, $processedData['data']['pid']),
$processedData['data']
);
$processedData['containerContext'] = array_reverse($processedData['containerContext']);
return $processedData;
}
public function getContainerContext(array $pageRecords, array $data, int $level = 1): array
{
$containerContext = [];
if (isset($data['tx_container_parent']) && isset($pageRecords[$data['tx_container_parent']])) {
$parent = $pageRecords[$data['tx_container_parent']];
$containerContext[] = $parent;
$containerContext = array_merge(
$containerContext,
$this->getContainerContext($pageRecords, $parent, $level++)
);
}
return $containerContext;
}
public function getPageRecords(ContentObjectRenderer $cObj, int $pid): array
{
$runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('runtime');
$cache = \is_array($runtimeCache->get('containerContext')) ? $runtimeCache->get('containerContext') : [];
$cacheIdentifier = 'containerContext:' . $pid;
if (!isset($cache[$cacheIdentifier])) {
$records = $cObj->getRecords('tt_content', ['pidInList' => $pid]);
$dataset = [];
foreach ($records as $record) {
$dataset[$record['uid']] = $record;
}
$cache[$cacheIdentifier] = $dataset;
$runtimeCache->set('containerContext', $cache);
}
return $cache[$cacheIdentifier];
}
}
@@ -0,0 +1,74 @@
<?php declare(strict_types=1);
/*
* This file is part of the package bk2k/bootstrap-package.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/
namespace BK2K\BootstrapPackage\DataProcessing;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\FileReference;
use TYPO3\CMS\Core\Resource\ProcessedFile;
use TYPO3\CMS\Core\Utility\CsvUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\DataProcessing\FilesProcessor;
/**
* CsvFileProcessor
*/
class CsvFileProcessor extends FilesProcessor
{
/**
* @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)
{
// Set the maximum amount of columns
$maximumColumns = (int) $cObj->stdWrapValue('maximumColumns', $processorConfiguration, '0');
// Set the field delimiter which is "," by default
$fieldDelimiter = (string) $cObj->stdWrapValue('fieldDelimiter', $processorConfiguration, ',');
// Set the field enclosure which is " by default
$fieldEnclosure = (string) $cObj->stdWrapValue('fieldEnclosure', $processorConfiguration, '"');
// Get processed files
$processedData = parent::process($cObj, $contentObjectConfiguration, $processorConfiguration, $processedData);
$targetVariableName = (string) $cObj->stdWrapValue('as', $processorConfiguration, 'files');
$files = $processedData[$targetVariableName];
unset($processedData[$targetVariableName]);
foreach ($files as $key => $value) {
if (is_object($value) && ($value instanceof FileReference || $value instanceof File)) {
/** @var ProcessedFile $value */
if ($value->getExtension() !== 'csv') {
unset($files[$key]);
} else {
$originalFile = $value->getOriginalFile();
$content = $originalFile->getContents();
$files[$key] = [
'file' => $value,
'bodytext' => $content,
'table' => CsvUtility::csvToArray(
$content,
$fieldDelimiter,
$fieldEnclosure,
$maximumColumns
)
];
}
}
}
$files = array_values(array_filter($files));
$processedData[$targetVariableName] = $files;
return $processedData;
}
}
@@ -0,0 +1,102 @@
<?php declare(strict_types=1);
/*
* This file is part of the package bk2k/bootstrap-package.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/
namespace BK2K\BootstrapPackage\DataProcessing;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\FileReference;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
/**
* File Filter Processor
* The DataProcessor requires a prepared array with Files or FilesReferences.
* This required array is usually generated by the FilesProcessor so it must be
* called first.
*
* Please note that the output variable name of the FilesProcessor
* must be provided to the FileFilterProcessor.
*
*
* Options:
* variableName - Resultset to work on
* predefinedList - Can be 'image', 'media' or 'text', will reference the
* global TYPO3 settings for that file type, for example:
* ['GFX']['imagefile_ext'] or ['SYS']['mediafile_ext']
* allowedFileExtensions - List of allowed file extensions,
* if set predefinedList will be overridden
*
*
* Basic Example:
* 10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
* 10 {
* references.fieldName = image
* folders.field = image_folder
* sorting.field = filelink_sorting
* as = files
* }
* 20 = BK2K\BootstrapPackage\DataProcessing\FileFilterProcessor
* 20 {
* variableName = files
* predefinedList = image
* }
*
*
* Advanced Example:
* 10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
* 10 {
* references.fieldName = image
* }
* 20 = BK2K\BootstrapPackage\DataProcessing\FileFilterProcessor
* 20 {
* allowedFileExtensions = jpg, jpeg, gif
* }
*/
class FileFilterProcessor implements DataProcessorInterface
{
/**
* @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)
{
$confVars = $GLOBALS['TYPO3_CONF_VARS'];
$predefinedLists = [
'image' => isset($confVars['GFX']['imagefile_ext']) ? $confVars['GFX']['imagefile_ext'] : 'gif,jpg,jpeg,tif,tiff,bmp,pcx,tga,png,pdf,ai,svg',
'media' => isset($confVars['SYS']['mediafile_ext']) ? $confVars['SYS']['mediafile_ext'] : 'gif,jpg,jpeg,bmp,png,pdf,svg,ai,mp3,wav,mp4,ogg,flac,opus,webm,youtube,vimeo',
'text' => isset($confVars['SYS']['textfile_ext']) ? $confVars['SYS']['textfile_ext'] : 'txt,ts,typoscript,html,htm,css,tmpl,js,sql,xml,csv,xlf,yaml,yml',
];
$predefinedList = (string) $cObj->stdWrapValue('predefinedList', $processorConfiguration, 'image');
$allowedFileExtensions = isset($predefinedLists[$predefinedList]) ? $predefinedLists[$predefinedList] : '';
$allowedFileExtensions = GeneralUtility::trimExplode(',', (string) $cObj->stdWrapValue('allowedFileExtensions', $processorConfiguration, $allowedFileExtensions));
if (count($allowedFileExtensions) === 0) {
return $processedData;
}
$variableName = (string) $cObj->stdWrapValue('variableName', $processorConfiguration, 'files');
if (!isset($processedData[$variableName]) || count($processedData[$variableName]) === 0) {
return $processedData;
}
foreach ($processedData[$variableName] as $key => $value) {
if (is_object($value)
&& ($value instanceof FileReference || $value instanceof File)
&& !in_array($value->getExtension(), $allowedFileExtensions, true)
) {
unset($processedData[$variableName][$key]);
}
}
return $processedData;
}
}
@@ -0,0 +1,84 @@
<?php
declare(strict_types = 1);
/*
* This file is part of the package bk2k/bootstrap-package.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/
namespace BK2K\BootstrapPackage\DataProcessing;
use TYPO3\CMS\Core\Service\FlexFormService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
/**
* Minimal TypoScript configuration
* Process field pi_flexform and overrides the values stored in data
*
* 10 = BK2K\BootstrapPackage\DataProcessing\FlexFormProcessor
*
*
* Advanced TypoScript configuration
* Process field assigned in fieldName and stores processed data to new key
*
* 10 = BK2K\BootstrapPackage\DataProcessing\FlexFormProcessor
* 10 {
* fieldName = pi_flexform
* as = flexform
* }
*/
class FlexFormProcessor implements DataProcessorInterface
{
/**
* @var FlexFormService
*/
protected $flexFormService;
/**
* Constructor
*/
public function __construct()
{
$this->flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
}
/**
* @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)
{
// The field name to process
$fieldName = (string) $cObj->stdWrapValue('fieldName', $processorConfiguration);
if ($fieldName === '') {
$fieldName = 'pi_flexform';
}
if (!isset($processedData['data'][$fieldName])) {
return $processedData;
}
// Process Flexform
$originalValue = $processedData['data'][$fieldName];
if (!is_string($originalValue)) {
return $processedData;
}
$flexformData = $this->flexFormService->convertFlexFormContentToArray($originalValue);
// Set the target variable
$targetVariableName = (string) $cObj->stdWrapValue('as', $processorConfiguration);
if ($targetVariableName !== '') {
$processedData[$targetVariableName] = $flexformData;
} else {
$processedData['data'][$fieldName] = $flexformData;
}
return $processedData;
}
}
@@ -0,0 +1,91 @@
<?php
declare(strict_types = 1);
/*
* This file is part of the package bk2k/bootstrap-package.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/
namespace BK2K\BootstrapPackage\DataProcessing;
use BK2K\BootstrapPackage\Icons\FileIcon;
use BK2K\BootstrapPackage\Service\IconService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
use TYPO3\CMS\Frontend\DataProcessing\FilesProcessor;
/**
* Minimal TypoScript configuration
*
* 10 = BK2K\BootstrapPackage\DataProcessing\IconsDataProcessor
* 10 {
* iconSetFieldName = icon_set
* iconIdentifierFieldName = icon
* iconFileFieldName = icon_file
* as = icon
* }
*/
class IconsDataProcessor implements DataProcessorInterface
{
/**
* @var IconService
*/
protected $iconService;
/**
* Constructor
*/
public function __construct()
{
$this->iconService = GeneralUtility::makeInstance(IconService::class);
}
/**
* @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)
{
$icon = null;
$config = [
'iconSet' => (string) $cObj->stdWrapValue('iconSet', $processorConfiguration, ''),
'iconIdentifier' => (string) $cObj->stdWrapValue('iconIdentifier', $processorConfiguration, ''),
'iconFileFieldName' => (string) $cObj->stdWrapValue('iconFileFieldName', $processorConfiguration, ''),
];
if ($config['iconSet'] !== '' && $config['iconIdentifier'] !== '') {
$iconProvider = $this->iconService->getIconProviderForIdentifier($config['iconSet']);
if ($iconProvider !== null) {
$icon = $iconProvider->getIconList()->getIcon($config['iconIdentifier']);
}
} elseif ($config['iconFileFieldName'] !== '') {
$filesProcessor = GeneralUtility::makeInstance(FilesProcessor::class);
$filesData = $filesProcessor->process(
$cObj,
$contentObjectConfiguration,
['references.' => ['fieldName' => $config['iconFileFieldName']]],
['data' => $processedData['data']]
);
if (isset($filesData['files'][0])) {
$file = $filesData['files'][0];
$icon = (new FileIcon())
->setFile($file)
->setIdentifier($file->getIdentifier())
->setName($file->getName())
->setPreviewImage($file->getPublicUrl())
;
}
}
$targetVariableName = (string) $cObj->stdWrapValue('as', $processorConfiguration, 'icon');
$processedData[$targetVariableName] = $icon;
return $processedData;
}
}
@@ -0,0 +1,81 @@
<?php declare(strict_types=1);
/*
* This file is part of the package bk2k/bootstrap-package.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/
namespace BK2K\BootstrapPackage\DataProcessing;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
/**
* This processor generates a set of file objects.
*
* 10 = BK2K\BootstrapPackage\DataProcessing\StaticFilesProcessor
* 10 {
* files {
* 0.field = image
* 1 = EXT:bootstrap_package/Resources/Public/Images/Icons/icon-1.png
* circle = EXT:bootstrap_package/Resources/Public/Images/Icons/icon-circle.png
* }
* as = staticFiles
* }
*/
class StaticFilesProcessor implements DataProcessorInterface
{
/**
* @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;
}
// Collect possible files
$files = [];
if (count($processorConfiguration['files.']) > 0) {
$filesConfiguration = $processorConfiguration['files.'];
foreach ($filesConfiguration as $key => $file) {
$key = substr($key, -1) === '.' ? substr_replace($key, '', -1) : $key;
$value = (string) $cObj->stdWrapValue($key, $filesConfiguration);
if ($value !== '') {
$files[$key] = $value;
}
}
}
// Get file objects
$images = [];
if (count($files) !== 0) {
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
foreach ($files as $key => $file) {
$absFilename = GeneralUtility::getFileAbsFileName($file);
if (file_exists($absFilename)) {
// Do not use absolute file name to ensure correct path resolution from ResourceFactory.
$images[$key] = $resourceFactory->retrieveFileOrFolderObject($file);
}
}
}
// Set the target variable
$targetVariableName = (string) $cObj->stdWrapValue('as', $processorConfiguration);
if ($targetVariableName !== '') {
$processedData[$targetVariableName] = $images;
} else {
$processedData['staticFiles'] = $images;
}
return $processedData;
}
}