Skip to content
Open
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
39 changes: 30 additions & 9 deletions Classes/DataProcessing/DataProcessingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,33 @@ trait DataProcessingTrait
*/
protected function removeDataIfnotAppendInConfiguration(array $processorConfiguration, array $processedData): array
{
if (!isset($processorConfiguration['appendData']) ||
(int)$processorConfiguration['appendData'] === 0) {
unset($processedData['data']);
if (isset($processorConfiguration['as'], $processedData[$processorConfiguration['as']])
&& is_array($processedData[$processorConfiguration['as']])) {
if (
!isset($processorConfiguration['appendData']) ||
(int)$processorConfiguration['appendData'] !== 1
) {
// Items to keep
$removeAll = !isset($processorConfiguration['appendData']) || $processorConfiguration['appendData'] == 0;
$keepItems = $removeAll ? [] : array_flip(array_map('trim', explode(',', $processorConfiguration['appendData'])));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add new option like keep(Items|fields) or passFields to keep clear what is happening also do not change behavior of flag appendData to keep BC, also you can use GeneralUtility:trimExplode

if ($removeAll) {
unset($processedData['data']);
} else {
$processedData['data'] = array_intersect_key($processedData['data'], $keepItems);
}
if (
isset($processorConfiguration['as'], $processedData[$processorConfiguration['as']])
&& is_array($processedData[$processorConfiguration['as']])
) {
foreach ($processedData[$processorConfiguration['as']] as &$item) {
if (is_array($item) && isset($item['data'])) {
unset($item['data']);
if ($removeAll) {
unset($item['data']);
} else {
$item['data'] = array_intersect_key($item['data'], $keepItems);
}
}

if ($this->isMenuProcessor() && isset($item['children']) && is_array($item['children'])) {
$this->removeDataInChildrenNodes($item['children']);
$this->removeDataInChildrenNodes($item['children'], $removeAll, $keepItems);
}
}
}
Expand All @@ -49,12 +64,18 @@ protected function isMenuProcessor(): bool
* Removes recursively "data" in children nodes
*
* @param array $children
* @param bool $removeAll
* @param array $keepItems
* @param string $nodeName
*/
private function removeDataInChildrenNodes(array &$children, string $nodeName = 'children'): void
private function removeDataInChildrenNodes(array &$children, bool $removeAll, array $keepItems, string $nodeName = 'children'): void
{
foreach ($children as &$childrenItem) {
unset($childrenItem['data']);
if ($removeAll) {
unset($childrenItem['data']);
} else {
$childrenItem['data'] = array_intersect_key($childrenItem['data'], $keepItems);
}
if (isset($childrenItem[$nodeName]) && is_array($childrenItem[$nodeName])) {
$this->removeDataInChildrenNodes($childrenItem[$nodeName], $nodeName);
}
Expand Down