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 16, 2021
1 parent 9af17e5 commit 5419b2a
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 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 @@ -1016,11 +1010,14 @@ private function treeWalkChildCollection(CollectionInterface $childCollection, M
*/
public function getTreeCollectionRecursive($rootId, $level = 0, $providerName = null)
{
$environment = $this->getEnvironment();
$dataDriver = $environment->getDataProvider($providerName);
$tableTreeData = $dataDriver->getEmptyCollection();
$rootConfig = $environment->getBaseConfigRegistry()->getBaseConfig();
$relationships = $environment->getDataDefinition()->getModelRelationshipDefinition();
$environment = $this->getEnvironment();
$dataDriver = $environment->getDataProvider($providerName);
$tableTreeData = $dataDriver->getEmptyCollection();
$configRegistry = ($this->flatMode ?? ($environment instanceof EnvironmentFlatConfigRegistryInterface))
? $environment->getFlatConfigRegistry()
: $environment->getBaseConfigRegistry();
$rootConfig = $configRegistry->getBaseConfig();
$relationships = $environment->getDataDefinition()->getModelRelationshipDefinition();

if (!$rootId) {
$this->prepareFilterForRootCondition();
Expand Down Expand Up @@ -1055,7 +1052,11 @@ private function prepareFilterForRootCondition()
$environment = $this->getEnvironment();
$rootCondition = $environment->getDataDefinition()->getModelRelationshipDefinition()->getRootCondition();

$baseConfig = $environment->getBaseConfigRegistry()->getBaseConfig();
$configRegistry = ($this->flatMode ?? ($environment instanceof EnvironmentFlatConfigRegistryInterface))
? $environment->getFlatConfigRegistry()
: $environment->getBaseConfigRegistry();
$baseConfig = $configRegistry->getBaseConfig();

if (!$rootCondition) {
return $baseConfig;
}
Expand Down

0 comments on commit 5419b2a

Please sign in to comment.