Skip to content

Commit

Permalink
Added a new mode to the tree picker to show the output as flat
Browse files Browse the repository at this point in the history
  • Loading branch information
baumannsven committed Apr 10, 2021
1 parent 0f8e13c commit 3133d6a
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions src/Contao/View/Contao2BackendView/TreePicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -306,7 +307,7 @@ public function getItemContainer()
/**
* Retrieve the environment of the item data container.
*
* @return EnvironmentInterface
* @return EnvironmentInterface|EnvironmentFlatConfigRegistryInterface
*/
public function getEnvironment()
{
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 3133d6a

Please sign in to comment.