Skip to content

Commit

Permalink
[FEATURE] Respect flexform sheets in BE preview
Browse files Browse the repository at this point in the history
Show all sheets of a flexform inside the BE preview and also
show inages from new "file" TCA type.

Resolves: #545
Release: 12.0.0
  • Loading branch information
opi99 committed Dec 14, 2023
1 parent a546de5 commit 177bed4
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 77 deletions.
41 changes: 25 additions & 16 deletions Classes/Service/ProcessingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,21 +419,31 @@ protected function getNodeChildsFromElements(array $baseNode, string $baseSheetK
$childs[$fieldKey] = $this->getNodeChildsFromElements($baseNode, $baseSheetKey, $fieldConfig['el'], $lKey, $values[$fieldKey]['el'], $basePid, $usedElements);
}
} else {
// If the current field points to another table, process it if not sys_file or sys_file_reference:
// If the current field points to another table
if (
isset($fieldConfig['config'])
&& ($fieldConfig['config']['type'] ?? '') === 'group'
isset($fieldConfig['config']['type'])
) {
/** @TODO allowed can be multiple tables */
$table = $fieldConfig['config']['allowed'];
foreach ($vKeys as $vKey) {
$listOfSubElementUids = $values[$fieldKey][$vKey];
if ($listOfSubElementUids) {
$parentPointer = $this->createParentPointer($baseNode, $baseSheetKey, $fieldKey, $lKey, $vKey);
$childs[$fieldKey][$vKey] = $this->getNodesFromListWithTree($listOfSubElementUids, $parentPointer, $basePid, $table, $usedElements);
} else {
$childs[$fieldKey][$vKey] = [];
}
switch ($fieldConfig['config']['type']) {
case 'group':
/** @TODO allowed can be multiple tables */
$table = $fieldConfig['config']['allowed'];
foreach ($vKeys as $vKey) {
$listOfSubElementUids = $values[$fieldKey][$vKey];
if ($listOfSubElementUids) {
$parentPointer = $this->createParentPointer($baseNode, $baseSheetKey, $fieldKey, $lKey, $vKey);
$childs[$fieldKey][$vKey] = $this->getNodesFromListWithTree($listOfSubElementUids, $parentPointer, $basePid, $table, $usedElements);
} else {
$childs[$fieldKey][$vKey] = [];
}
}
break;
case 'file':
$listOfSubElementUids = (string) $baseNode['raw']['entity']['uid'];
$parentPointer = $this->createParentPointer($baseNode, $baseSheetKey, $fieldKey, $lKey, 'vDEF');
$childs[$fieldKey]['vDEF'] = $this->getNodesFromListWithTree('', $parentPointer, 0, 'sys_file_reference', $usedElements, '', $baseNode['raw']['entity']['uid'], $baseNode['raw']['table'], $fieldConfig['config']);
break;
default:
// Empty as we have no default extra processing
}
}
}
Expand Down Expand Up @@ -462,22 +472,21 @@ public function findRecordsSourcePointer(array $row): string
return 'tt_content:' . $row['uid'];
}

public function getNodesFromListWithTree(string $listOfNodes, array $parentPointer, int $basePid, string $table, array &$usedElements): array
public function getNodesFromListWithTree(string $listOfNodes, array $parentPointer, int $basePid, string $table, array &$usedElements, $MMtable = '', $MMuid = 0, string $currentTable = '', array $config = []): array
{
$nodes = [];

// Get records:
/** @var RelationHandler $dbAnalysis */
$dbAnalysis = GeneralUtility::makeInstance(RelationHandler::class);

$dbAnalysis->start($listOfNodes, $table);
$dbAnalysis->start($listOfNodes, $table, $MMtable, $MMuid, $currentTable, $config);

// Traverse records:
// Note: key in $dbAnalysis->itemArray is not a valid counter! It is in 'tt_content_xx' format!
$counter = 1;
foreach ($dbAnalysis->itemArray as $position => $recIdent) {
$contentRow = BackendUtility::getRecordWSOL($table, $recIdent['id']);

$parentPointer['position'] = $position;

// Only do it if the element referenced was not deleted! - or hidden :-)
Expand Down
3 changes: 2 additions & 1 deletion Classes/ViewHelpers/ArrayVariableViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Tvp\TemplaVoilaPlus\ViewHelpers;

use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithContentArgumentAndRenderStatic;
Expand Down Expand Up @@ -40,7 +41,7 @@ public static function renderStatic(
$container = $renderingContext->getVariableProvider()->get($arguments['name']);
}

$container[$arguments['key']] = $value;
$container = ArrayUtility::setValueByPath($container, $arguments['key'], $value, '.');

$renderingContext->getVariableProvider()->add($arguments['name'], $container);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{namespace tvp=Tvp\TemplaVoilaPlus\ViewHelpers}
{namespace be=TYPO3\CMS\Backend\ViewHelpers}

<f:if condition="{node.raw.table} == sys_file">
<f:then>
<f:switch expression="{node.raw.table}">
<f:case value="sys_file">
<be:thumbnail src="{node.raw.entity.uid}" height="64" width="64" />
</f:then>
<f:else>
</f:case>
<f:case value="sys_file_reference">
<f:comment>be:thumbnails do not work with references https://forge.typo3.org/issues/102571</f:comment>
<f:image src="{node.raw.entity.uid}" height="64" width="64" treatIdAsReference="1" />
</f:case>
<f:defaultCase>
<f:render section="TableNode" arguments="{_all}" />
</f:else>
</f:if>
</f:defaultCase>
</f:switch>


<f:section name="TableNode">
Expand Down Expand Up @@ -39,7 +43,7 @@
<div class="tvp-record-edit">
<f:render partial="Backend/Handler/DoktypeDefaultHandler/Node/TypeInformation" arguments="{node: node}" />
</div>
<f:if condition="{f:count(subject: node.childNodes.sDEF)} > 0">
<f:if condition="{f:count(subject: node.childNodes)} > 0">
<f:if condition="{node.rendering.beLayout}">
<f:variable name="beLayout" value="{node.rendering.beLayout}" />
</f:if>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<f:if condition="{node.childNodes.sDEF.lDEF}">
<f:if condition="{node.rendering.beLayout}">
<f:then>
<f:if condition="{node.rendering.beLayoutDesign}">
<f:then>
<f:render partial="Backend/Handler/DoktypeDefaultHandler/Node/ChildsDesign" section="renderChildElements" arguments="{fieldConfig: '{node.datastructure.sheets.sDEF.ROOT.el}', childElements: '{node.childNodes.sDEF.lDEF}', childFlexformData: '{node.flexform.data.sDEF.lDEF}', parentPointer: '{node.raw.table}:{node.raw.entity.uid}:sDEF:lDEF:', node: node}" />
</f:then>
<f:else>
<f:render
partial="Backend/Handler/DoktypeDefaultHandler/Node/ChildsBeLayouts"
section="renderChildElements"
arguments="{fieldConfig: '{node.datastructure.sheets.sDEF.ROOT.el}', childElements: '{node.childNodes.sDEF.lDEF}', childFlexformData: '{node.flexform.data.sDEF.lDEF}', parentPointer: '{node.raw.table}:{node.raw.entity.uid}:sDEF:lDEF:', beLayout: '{node.rendering.beLayout}', subpart: 'CHILD'}"
/>
</f:else>
</f:if>
</f:then>
<f:else>
<f:render partial="Backend/Handler/DoktypeDefaultHandler/Node/ChildsTable" section="renderChildElements" arguments="{fieldConfig: '{node.datastructure.sheets.sDEF.ROOT.el}', childElements: '{node.childNodes.sDEF.lDEF}', childFlexformData: '{node.flexform.data.sDEF.lDEF}', parentPointer: '{node.raw.table}:{node.raw.entity.uid}:sDEF:lDEF:', subpart: 'CHILD'}" />
</f:else>
<f:for as="childNodesPerSheet" each="{node.childNodes}" key="sheetKey">
<f:if condition="{childNodesPerSheet.lDEF}">
<f:if condition="{node.rendering.beLayout}">
<f:then>
<f:if condition="{node.rendering.beLayoutDesign}">
<f:then>
<f:render partial="Backend/Handler/DoktypeDefaultHandler/Node/ChildsDesign" section="renderChildElements" arguments="{fieldConfig: '{node.datastructure.sheets.{sheetKey}.ROOT.el}', childElements: '{childNodesPerSheet.lDEF}', childFlexformData: '{node.flexform.data.{sheetKey}.lDEF}', parentPointer: '{node.raw.table}:{node.raw.entity.uid}:{sheetKey}:lDEF:', node: node}" />
</f:then>
<f:else>
<f:render
partial="Backend/Handler/DoktypeDefaultHandler/Node/ChildsBeLayouts"
section="renderChildElements"
arguments="{fieldConfig: '{node.datastructure.sheets.{sheetKey}.ROOT.el}', childElements: '{childNodesPerSheet.lDEF}', childFlexformData: '{node.flexform.data.{sheetKey}.lDEF}', parentPointer: '{node.raw.table}:{node.raw.entity.uid}:{sheetKey}:lDEF:', beLayout: '{node.rendering.beLayout}', subpart: 'CHILD'}"
/>
</f:else>
</f:if>
</f:then>
<f:else>
<f:render partial="Backend/Handler/DoktypeDefaultHandler/Node/ChildsTable" section="renderChildElements" arguments="{fieldConfig: '{node.datastructure.sheets.{sheetKey}.ROOT.el}', childElements: '{childNodesPerSheet.lDEF}', childFlexformData: '{node.flexform.data.{sheetKey}.lDEF}', parentPointer: '{node.raw.table}:{node.raw.entity.uid}:{sheetKey}:lDEF:', subpart: 'CHILD'}" />
</f:else>
</f:if>
</f:if>
</f:if>
</f:for>
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<f:if condition="!{childElements.{fieldKey}}">
<f:then>
<strong>
<f:if condition="{subFieldConfig.TCEforms.label}">
<f:if condition="{subFieldConfig.label}">
<f:then>
<f:translate key="{subFieldConfig.TCEforms.label}" default="{subFieldConfig.TCEforms.label}" />
<f:translate key="{subFieldConfig.label}" default="{subFieldConfig.label}" />
</f:then>
<f:else>
<f:if condition="{subFieldConfig.title}">
Expand All @@ -28,13 +28,13 @@

<f:section name="renderChildElements">
<f:for each="{fieldConfig}" key="fieldKey" as="subFieldConfig">

<f:variable name="layoutKey">{subFieldConfig.config.foreign_table}{subFieldConfig.config.allowed}.{fieldKey}</f:variable>
<f:if condition="{childElements.{fieldKey}}">
<tvp:arrayVariable name="layoutHeaders" key="{fieldKey}">
<tvp:arrayVariable name="layoutHeaders" key="{layoutKey}">
<strong>
<f:if condition="{subFieldConfig.TCEforms.label}">
<f:if condition="{subFieldConfig.label}">
<f:then>
<f:translate key="{subFieldConfig.TCEforms.label}" default="{subFieldConfig.TCEforms.label}" />
<f:translate key="{subFieldConfig.label}" default="{subFieldConfig.label}" />
</f:then>
<f:else>
<f:if condition="{subFieldConfig.label}">
Expand All @@ -50,7 +50,7 @@
<f:if condition="{subFieldConfig.section}">
<f:then>
<f:variable name="subFlexFormData" value="{childFlexformData.{fieldKey}.el}" />
<tvp:arrayVariable name="layoutFields" key="{fieldKey}">
<tvp:arrayVariable name="layoutFields" key="{layoutKey}">
{f:variable(name: 'countWhat', value: '{childElements.{fieldKey}}')}
{f:variable(name: 'count', value: '{f:count(subject: countWhat)}')}
<f:switch expression="{count}">
Expand All @@ -72,7 +72,7 @@
</f:then>
<f:else>
<f:variable name="subFlexFormData" value="{childFlexformData.{fieldKey}.el}" />
<tvp:arrayVariable name="layoutFields" key="{fieldKey}">
<tvp:arrayVariable name="layoutFields" key="{layoutKey}">
<f:render section="renderChildElements" arguments="{fieldConfig: subFieldConfig.el, childElements: '{childElements.{fieldKey}}', childFlexformData: '{childFlexformData.{fieldKey}.el}', beLayout: beLayout, parentPointer: '{parentPointer}#{fieldKey}#el', subpart: '{subpart}.{fieldKey}'}" />
<f:render section="renderSubFields" arguments="{fieldConfig: subFieldConfig.el, childElements: '{childElements.{fieldKey}}', childFlexformData: '{childFlexformData.{fieldKey}.el}'}" />
</tvp:arrayVariable>
Expand All @@ -82,7 +82,7 @@
<f:else>
<f:if condition="{childElements.{fieldKey}}">
<f:then>
<tvp:arrayVariable name="layoutFields" key="{fieldKey}">
<tvp:arrayVariable name="layoutFields" key="{layoutKey}">
<div class="tvjs-dropzone" data-parent-pointer="{parentPointer}#{fieldKey}:vDEF" data-child-allowed="{subFieldConfig.TCEforms.config.allowed}{subFieldConfig.config.allowed}">
<f:for each="{childElements.{fieldKey}.vDEF}" as="element">
<f:render partial="Backend/Handler/DoktypeDefaultHandler/Node" arguments="{node: element.node}" />
Expand All @@ -94,21 +94,24 @@
</f:else>
</f:if>
</f:for>
{f:variable(name: 'count', value: '{f:count(subject: layoutHeaders)}')}
<f:switch expression="{count}">
<f:case value="1">{f:variable(name: 'colwidthclass', value: 'col col-lg-12')}</f:case>
<f:case value="2">{f:variable(name: 'colwidthclass', value: 'col col-lg-6')}</f:case>
<f:case value="3">{f:variable(name: 'colwidthclass', value: 'col col-lg-4')}</f:case>
<f:case value="4">{f:variable(name: 'colwidthclass', value: 'col col-lg-3')}</f:case>
<f:case value="6">{f:variable(name: 'colwidthclass', value: 'col col-lg-2')}</f:case>
<f:defaultCase>{f:variable(name: 'colwidthclass', value: 'col')}</f:defaultCase>
</f:switch>
<div class="row tvp-childs-table">
<f:for each="{layoutFields}" key="layoutKey" as="_unused">
<div class="{colwidthclass} t3-grid-cell">
<div class="t3-page-column-header"><f:format.raw>{layoutHeaders.{layoutKey}}</f:format.raw></div>
<div class="t3-page-ce"><f:format.raw>{layoutFields.{layoutKey}}</f:format.raw></div>
</div>
</f:for>
</div>

<f:for as="layoutHeaderPerTable" each="{layoutHeaders}" key="layoutKey">
{f:variable(name: 'count', value: '{f:count(subject: layoutHeaderPerTable)}')}
<f:switch expression="{count}">
<f:case value="1">{f:variable(name: 'colwidthclass', value: 'col col-lg-12')}</f:case>
<f:case value="2">{f:variable(name: 'colwidthclass', value: 'col col-lg-6')}</f:case>
<f:case value="3">{f:variable(name: 'colwidthclass', value: 'col col-lg-4')}</f:case>
<f:case value="4">{f:variable(name: 'colwidthclass', value: 'col col-lg-3')}</f:case>
<f:case value="6">{f:variable(name: 'colwidthclass', value: 'col col-lg-2')}</f:case>
<f:defaultCase>{f:variable(name: 'colwidthclass', value: 'col')}</f:defaultCase>
</f:switch>
<div class="row tvp-childs-table">
<f:for each="{layoutHeaderPerTable}" key="fieldKey" as="headerLine">
<div class="{colwidthclass} t3-grid-cell">
<div class="t3-page-column-header"><f:format.raw>{headerLine}</f:format.raw></div>
<div class="t3-page-ce"><f:format.raw>{layoutFields.{layoutKey}.{fieldKey}}</f:format.raw></div>
</div>
</f:for>
</div>
</f:for>
</f:section>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="tvp-record-edit">
<f:render partial="Backend/Handler/DoktypeDefaultHandler/Node/TypeInformation" arguments="{node: node}" />
</div>
<f:if condition="{f:count(subject: node.childNodes.sDEF)} > 0">
<f:if condition="{f:count(subject: node.childNodes)} > 0">
<f:if condition="{node.rendering.beLayout}">
<f:variable name="beLayout" value="{node.rendering.beLayout}" />
</f:if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<f:for each="{node.datastructure.sheets.sDEF.ROOT.el}" key="fieldName" as="fieldConfig">
<f:if condition="!{node.childNodes.sDEF.lDEF.{fieldName}.vDEF} && {node.flexform.data.sDEF.lDEF.{fieldName}.vDEF}">
<f:if condition="{fieldConfig.TCEforms.label}">
<strong><f:translate key="{fieldConfig.TCEforms.label}" default="{fieldConfig.TCEforms.label}" /></strong>
<f:if condition="{fieldConfig.label}">
<strong><f:translate key="{fieldConfig.label}" default="{fieldConfig.label}" /></strong>
</f:if>
<f:format.crop maxCharacters="2000" respectHtml="false">
<tvp:format.wordLength maxCharacters="75">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,35 @@
<f:if condition="{node.datastructure.error}">
<f:be.infobox state="2">{node.datastructure.error}</f:be.infobox>
</f:if>

<f:if condition="{node.raw.entity.tx_templavoilaplus_map}">
<f:then>
<f:render section="elements" arguments="{fieldsDs: node.datastructure.sheets.sDEF.ROOT.el, fieldsData: node.flexform.data.sDEF.lDEF, node: node}" />
<f:for as="sheet" each="{node.datastructure.sheets}" key="sheetKey">
<f:variable name="data" value="{node.flexform.data.{sheetKey}}" />
<f:variable name="childNodesInChild" value="{node.childNodes.{sheetKey}}" />
<f:render section="sheet" arguments="{sheet: sheet, data: data, childNodesInChild: childNodesInChild}" />
</f:for>
</f:then>
<f:else>
<f:translate key="LLL:EXT:templavoilaplus/Resources/Private/Language/Backend/PageLayout.xlf:error.fce.noMapping"/>
</f:else>
</f:if>

<f:section name="sheet">
<div>
<f:if condition="{sheet.ROOT.sheetTitle}">
<strong><f:translate key="{sheet.ROOT.sheetTitle}" default="{sheet.ROOT.sheetTitle}" /></strong><br />
</f:if>
<f:render section="elements" arguments="{fieldsDs: sheet.ROOT.el, fieldsData: data.lDEF, childNodesInChild: childNodesInChild}" />
</div>
</f:section>

<f:section name="elements">
<f:for each="{fieldsDs}" key="fieldName" as="fieldConfig">
<f:if condition="!{node.childNodes.sDEF.lDEF.{fieldName}}">
<f:if condition="{fieldConfig.TCEforms.label}">
<f:if condition="!{childNodesInChild.lDEF.{fieldName}}">
<f:if condition="{fieldConfig.label}">
<strong>
<f:translate key="{fieldConfig.TCEforms.label}" default="{fieldConfig.TCEforms.label}"/>:
<f:translate key="{fieldConfig.label}" default="{fieldConfig.label}"/>:
</strong>
</f:if>
<f:if condition="{fieldConfig.type} == 'array' && {fieldConfig.title}">
Expand Down

0 comments on commit 177bed4

Please sign in to comment.