Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: use simplified file output #25

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions Classes/DataProcessing/FilesProcessor.php

This file was deleted.

25 changes: 25 additions & 0 deletions Classes/DataProcessing/FlexFormProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
namespace Remind\Headless\DataProcessing;

use FriendsOfTYPO3\Headless\DataProcessing\FilesProcessor;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools;
use TYPO3\CMS\Core\Service\FlexFormService;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\Exception\MissingArrayPathException;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;

class FlexFormProcessor implements DataProcessorInterface
{
protected ContentObjectRenderer $cObj;
protected array $processorConf;

/**
* @param ContentObjectRenderer $cObj The data of the content element or page
Expand All @@ -30,6 +33,7 @@ public function process(
array $processedData
): array {
$this->cObj = $cObj;
$this->processorConf = $processorConf;

$flexFormTools = GeneralUtility::makeInstance(FlexFormTools::class);
$flexFormTools->reNumberIndexesOfSectionData = true;
Expand Down Expand Up @@ -127,14 +131,30 @@ public function parseElement(
}

if ($type === 'file') {
$request = $this->getRequest();
/** @var \TYPO3\CMS\Core\TypoScript\FrontendTypoScript $frontendTypoScript */
$frontendTypoScript = $request->getAttribute('frontend.typoscript');
$fullTypoScript = $frontendTypoScript->getSetupArray();
$assetProcessingConfiguration = $fullTypoScript['lib.']['assetProcessingConfiguration.'];

$fieldName = $element['config']['foreign_match_fields']['fieldname'];

try {
$overrule = ArrayUtility::getValueByPath($this->processorConf, ['filesConfiguration.', ...array_map(function ($value) {
return $value . '.';
}, explode('.', $fieldName))]);
ArrayUtility::mergeRecursiveWithOverrule($assetProcessingConfiguration, $overrule);
} catch (MissingArrayPathException $e) {
}

$filesProcessor = GeneralUtility::makeInstance(FilesProcessor::class);
$as = 'file';
$processorConfiguration = [
'as' => $as,
'references.' => [
'fieldName' => $fieldName,
],
'processingConfiguration.' => $assetProcessingConfiguration,
];
$processedData = [
'data' => $this->cObj->data,
Expand Down Expand Up @@ -173,4 +193,9 @@ private function reNumberIndexes(mixed $value): mixed
}
return $value;
}

private function getRequest(): ServerRequestInterface
{
return $GLOBALS['TYPO3_REQUEST'];
}
}
3 changes: 3 additions & 0 deletions Configuration/TSConfig/Page/TCEFORM.tsconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ TCEFORM {
tt_content {
assets.types {
textmedia.config.maxitems = 1
textmedia.config.minitems = 1
}
bullets_type {
keepItems = 0,1
Expand All @@ -21,7 +22,9 @@ TCEFORM {
}
image.types {
image.config.maxitems = 1
image.config.minitems = 1
textpic.config.maxitems = 1
textpic.config.minitems = 1
}
imagecols.types {
textpic {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
page {
10 {
fields {
media {
dataProcessing {
10 {
processingConfiguration < lib.assetProcessingConfiguration
processingConfiguration {
returnFlattenObject = 0
}
}
}
}
}
}
}
5 changes: 3 additions & 2 deletions Configuration/TypoScript/ContentElement/Image.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ tt_content.image {
content {
fields {
gallery >
images = TEXT
images {
image = TEXT
image {
dataProcessing {
10 = FriendsOfTYPO3\Headless\DataProcessing\FilesProcessor
10 {
references.fieldName = image
as = files
processingConfiguration < lib.assetProcessingConfiguration
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ tt_content.image_gallery {
10 {
references.fieldName = image
as = files
processingConfiguration < lib.assetProcessingConfiguration
processingConfiguration {
returnFlattenObject = 0
}
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions Configuration/TypoScript/ContentElement/ImageOrient.typoscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
lib.imageOrient = COA
lib.imageOrient {
10 = TEXT
10 {
if {
value = 25
equals.field = imageorient
}
value = right
}
20 = TEXT
20 {
if {
value = 26
equals.field = imageorient
}
value = left
}
}
8 changes: 6 additions & 2 deletions Configuration/TypoScript/ContentElement/Items.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ lib.items {
parseFunc =< lib.parseFunc_links
}
items =< lib.items
images = TEXT
images {
image = TEXT
image {
dataProcessing {
10 = FriendsOfTYPO3\Headless\DataProcessing\FilesProcessor
10 {
references.fieldName = image
as = files
processingConfiguration < lib.assetProcessingConfiguration
processingConfiguration {
returnFlattenObject = 1
}
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions Configuration/TypoScript/ContentElement/MenuAbstract.typoscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
tt_content.menu_abstract {
fields {
content {
fields {
menu {
dataProcessing {
10 {
dataProcessing {
10 {
processingConfiguration < lib.assetProcessingConfiguration
processingConfiguration {
returnFlattenObject = 0
}
}
}
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
tt_content.menu_categorized_pages {
fields {
content {
fields {
menu {
dataProcessing {
10 {
dataProcessing {
10 {
processingConfiguration < lib.assetProcessingConfiguration
processingConfiguration {
returnFlattenObject = 0
}
}
}
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
tt_content.menu_recently_updated {
fields {
content {
fields {
menu {
dataProcessing {
10 {
dataProcessing {
10 {
processingConfiguration < lib.assetProcessingConfiguration
processingConfiguration {
returnFlattenObject = 0
}
}
}
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
tt_content.menu_related_pages {
fields {
content {
fields {
menu {
dataProcessing {
10 {
dataProcessing {
10 {
processingConfiguration < lib.assetProcessingConfiguration
processingConfiguration {
returnFlattenObject = 0
}
}
}
}
}
}
}
}
}
}
22 changes: 22 additions & 0 deletions Configuration/TypoScript/ContentElement/MenuSitemap.typoscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
tt_content.menu_sitemap {
fields {
content {
fields {
menu {
dataProcessing {
10 {
dataProcessing {
10 {
processingConfiguration < lib.assetProcessingConfiguration
processingConfiguration {
returnFlattenObject = 0
}
}
}
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
tt_content.menu_sitemap_pages {
fields {
content {
fields {
menu {
dataProcessing {
10 {
dataProcessing {
10 {
processingConfiguration < lib.assetProcessingConfiguration
processingConfiguration {
returnFlattenObject = 0
}
}
}
}
}
}
}
}
}
}
27 changes: 5 additions & 22 deletions Configuration/TypoScript/ContentElement/Textmedia.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,21 @@ tt_content.textmedia {
fields {
content {
fields {
gallery >
ratio = TEXT
ratio {
field = imagecols
intval = 1
}
assetPosition = COA
assetPosition {
10 = TEXT
10 {
if {
value = 25
equals.field = imageorient
}
value = right
}
20 = TEXT
20 {
if {
value = 26
equals.field = imageorient
}
value = left
}
}
gallery >
assets = TEXT
assets {
mediaPosition =< lib.imageOrient
media = TEXT
media {
dataProcessing {
10 = FriendsOfTYPO3\Headless\DataProcessing\FilesProcessor
10 {
references.fieldName = assets
as = files
processingConfiguration < lib.assetProcessingConfiguration
}
}
}
Expand Down
Loading