From 3133d6ab1ee2bc9881ad23a7d37c38493e43b46a Mon Sep 17 00:00:00 2001 From: Sven Baumann Date: Sat, 10 Apr 2021 15:07:14 +0200 Subject: [PATCH] Added a new mode to the tree picker to show the output as flat --- .../View/Contao2BackendView/TreePicker.php | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/Contao/View/Contao2BackendView/TreePicker.php b/src/Contao/View/Contao2BackendView/TreePicker.php index 4f675213..dafa1c86 100644 --- a/src/Contao/View/Contao2BackendView/TreePicker.php +++ b/src/Contao/View/Contao2BackendView/TreePicker.php @@ -50,6 +50,7 @@ use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\View\ModelFormatterConfigInterface; use ContaoCommunityAlliance\DcGeneral\DataDefinition\ModelRelationship\FilterBuilder; use ContaoCommunityAlliance\DcGeneral\DC\General; +use ContaoCommunityAlliance\DcGeneral\EnvironmentFlatConfigRegistryInterface; use ContaoCommunityAlliance\DcGeneral\EnvironmentInterface; use ContaoCommunityAlliance\DcGeneral\Exception\DcGeneralRuntimeException; use ContaoCommunityAlliance\DcGeneral\Factory\DcGeneralFactory; @@ -306,7 +307,7 @@ public function getItemContainer() /** * Retrieve the environment of the item data container. * - * @return EnvironmentInterface + * @return EnvironmentInterface|EnvironmentFlatConfigRegistryInterface */ public function getEnvironment() { @@ -612,23 +613,16 @@ public function generate() protected function generatePickerUrl() { $parameter = [ - 'fieldType' => $this->fieldType, - 'sourceName' => $this->sourceName, - 'modelId' => ModelId::fromModel($this->dataContainer->getModel())->getSerialized(), - 'orderField' => $this->orderField, - 'propertyName' => $this->name + 'fieldType' => $this->fieldType, + 'sourceName' => $this->sourceName, + 'modelId' => ModelId::fromModel($this->dataContainer->getModel())->getSerialized(), + 'orderField' => $this->orderField, + 'propertyName' => $this->name, + 'orderProperty' => $this->pickerOrderProperty, + 'sortDirection' => $this->pickerSortDirection, + 'flatMode' => ($this->pickerFlatMode ?? false) ]; - if ($this->pickerOrderProperty && $this->pickerSortDirection) { - $parameter = \array_merge( - $parameter, - [ - 'orderProperty' => $this->pickerOrderProperty, - 'sortDirection' => $this->pickerSortDirection - ] - ); - } - return System::getContainer()->get('contao.picker.builder')->getUrl('cca_tree', $parameter); } @@ -1019,7 +1013,13 @@ public function getTreeCollectionRecursive($rootId, $level = 0, $providerName = $environment = $this->getEnvironment(); $dataDriver = $environment->getDataProvider($providerName); $tableTreeData = $dataDriver->getEmptyCollection(); - $rootConfig = $environment->getBaseConfigRegistry()->getBaseConfig(); + if ($environment instanceof EnvironmentFlatConfigRegistryInterface) { + $configRegistry + = $this->flatMode ? $environment->getFlatConfigRegistry() : $environment->getBaseConfigRegistry(); + } else { + $configRegistry = $environment->getBaseConfigRegistry(); + } + $rootConfig = $configRegistry->getBaseConfig(); $relationships = $environment->getDataDefinition()->getModelRelationshipDefinition(); if (!$rootId) { @@ -1055,7 +1055,14 @@ private function prepareFilterForRootCondition() $environment = $this->getEnvironment(); $rootCondition = $environment->getDataDefinition()->getModelRelationshipDefinition()->getRootCondition(); - $baseConfig = $environment->getBaseConfigRegistry()->getBaseConfig(); + if ($environment instanceof EnvironmentFlatConfigRegistryInterface) { + $configRegistry + = $this->flatMode ? $environment->getFlatConfigRegistry() : $environment->getBaseConfigRegistry(); + } else { + $configRegistry = $environment->getBaseConfigRegistry(); + } + $baseConfig = $configRegistry->getBaseConfig(); + if (!$rootCondition) { return $baseConfig; }