Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add flat mode for the tree picker #567

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
74 changes: 74 additions & 0 deletions .ide-config/renamed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

/**
* This file is part of contao-community-alliance/dc-general.
*
* (c) 2013-2021 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* This project is provided in good faith and hope to be usable by anyone.
*
* @package contao-community-alliance/dc-general
* @author Sven Baumann <[email protected]>
* @copyright 2013-2021 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/

// This file is only here to allow IDE auto-completion.
// @codingStandardsIgnoreFile

namespace ContaoCommunityAlliance\DcGeneral {

/**
* @deprecated This class renamed, use
* @see \ContaoCommunityAlliance\DcGeneral\Config\BaseConfigRegistry
*/
class BaseConfigRegistry extends \ContaoCommunityAlliance\DcGeneral\Config\BaseConfigRegistry {}

/**
* @deprecated This interface renamed, use
* @see \ContaoCommunityAlliance\DcGeneral\Config\BaseConfigRegistryInterface
*/
interface BaseConfigRegistryInterface extends \ContaoCommunityAlliance\DcGeneral\Config\BaseConfigRegistryInterface {}
}

namespace ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Exception {
if (false) {
/**
* @deprecated This class is renamed, use
* @see \ContaoCommunityAlliance\DcGeneral\Exception\DefinitionException
*/
class DefinitionException extends \ContaoCommunityAlliance\DcGeneral\Exception\DefinitionException {}

/**
* @deprecated This class is renamed, use
* @see \ContaoCommunityAlliance\DcGeneral\Exception\EditOnlyModeException
*/
class EditOnlyModeException extends \ContaoCommunityAlliance\DcGeneral\Exception\EditOnlyModeException {}

/**
* @deprecated This class is renamed, use
* @see \ContaoCommunityAlliance\DcGeneral\Exception\NotCreatableException
*/
class NotCreatableException extends \ContaoCommunityAlliance\DcGeneral\Exception\NotCreatableException {}

/**
* @deprecated This class is renamed, use
* @see \ContaoCommunityAlliance\DcGeneral\Exception\NotDeletableException
*/
class NotDeletableException extends \ContaoCommunityAlliance\DcGeneral\Exception\NotDeletableException {}
}
}

namespace ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Subscriber {
if (false) {
/**
* @deprecated This class is renamed, use
* @see \ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\EventListener\ColorPickerWizardListener
*/
class ColorPickerWizardSubscriber extends \ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\EventListener\ColorPickerWizardListener {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This file is part of contao-community-alliance/dc-general.
*
* (c) 2013-2019 Contao Community Alliance.
* (c) 2013-2021 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -13,24 +13,25 @@
* @package contao-community-alliance/dc-general
* @author Christian Schiffler <[email protected]>
* @author Sven Baumann <[email protected]>
* @copyright 2013-2019 Contao Community Alliance.
* @copyright 2013-2021 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/

namespace ContaoCommunityAlliance\DcGeneral;
namespace ContaoCommunityAlliance\DcGeneral\Config;

use ContaoCommunityAlliance\DcGeneral\Contao\DataDefinition\Definition\Contao2BackendViewDefinitionInterface;
use ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface;
use ContaoCommunityAlliance\DcGeneral\Data\ModelId;
use ContaoCommunityAlliance\DcGeneral\Data\ModelIdInterface;
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\BasicDefinitionInterface;
use ContaoCommunityAlliance\DcGeneral\EnvironmentInterface;
use ContaoCommunityAlliance\DcGeneral\Exception\DcGeneralRuntimeException;

/**
* Registry for default data provider configurations to only resolve them once.
*/
class BaseConfigRegistry implements BaseConfigRegistryInterface
final class BaseConfigRegistry implements BaseConfigRegistryInterface
{
/**
* The attached environment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This file is part of contao-community-alliance/dc-general.
*
* (c) 2013-2019 Contao Community Alliance.
* (c) 2013-2021 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -13,15 +13,16 @@
* @package contao-community-alliance/dc-general
* @author Christian Schiffler <[email protected]>
* @author Sven Baumann <[email protected]>
* @copyright 2013-2019 Contao Community Alliance.
* @copyright 2013-2021 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/

namespace ContaoCommunityAlliance\DcGeneral;
namespace ContaoCommunityAlliance\DcGeneral\Config;

use ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface;
use ContaoCommunityAlliance\DcGeneral\Data\ModelIdInterface;
use ContaoCommunityAlliance\DcGeneral\EnvironmentAwareInterface;

/**
* Registry for default data provider configurations to only resolve them once.
Expand Down
105 changes: 105 additions & 0 deletions src/Config/FlatConfigRegistry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

/**
* This file is part of contao-community-alliance/dc-general.
*
* (c) 2013-2021 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* This project is provided in good faith and hope to be usable by anyone.
*
* @package contao-community-alliance/dc-general
* @author Sven Baumann <[email protected]>
* @copyright 2013-2021 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/

declare(strict_types=1);

namespace ContaoCommunityAlliance\DcGeneral\Config;

use ContaoCommunityAlliance\DcGeneral\Contao\DataDefinition\Definition\Contao2BackendViewDefinitionInterface;
use ContaoCommunityAlliance\DcGeneral\Data\ConfigInterface;
use ContaoCommunityAlliance\DcGeneral\Data\ModelIdInterface;
use ContaoCommunityAlliance\DcGeneral\EnvironmentFlatConfigRegistryInterface;
use ContaoCommunityAlliance\DcGeneral\EnvironmentInterface;

/**
* Registry for default data provider configurations to only resolve them once.
* The flat config registry is there to map a data definition that has a parent definition as a flat.
* In this registry, no filtering or similar is applied by the parent.
*/
final class FlatConfigRegistry implements BaseConfigRegistryInterface
{
/**
* The attached environment.
*
* @var EnvironmentFlatConfigRegistryInterface|null
*/
private $environment;

/**
* {@inheritDoc}
*/
public function getBaseConfig(ModelIdInterface $parentId = null): ConfigInterface
{
$environment = $this->getEnvironment();
$config = $environment->getDataProvider()->getEmptyConfig();
$definition = $environment->getDataDefinition();
$additional = $definition->getBasicDefinition()->getAdditionalFilter();

// Custom filter common for all modes.
if ($additional) {
$config->setFilter($additional);
}

$this->addDefaultSorting($config);

return $config;
}

/**
* Add the default sorting fields.
*
* @param ConfigInterface $config The data provider config.
*
* @return void
*/
private function addDefaultSorting(ConfigInterface $config): void
{
if (!empty($config->getSorting())) {
return;
}

$environment = $this->getEnvironment();
$definition = $environment->getDataDefinition();
/** @var Contao2BackendViewDefinitionInterface $viewDefinition */
$viewDefinition = $definition->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
$config->setSorting($viewDefinition->getListingConfig()->getDefaultSortingFields());
}

/**
* {@inheritDoc}
*/
public function getEnvironment(): ?EnvironmentFlatConfigRegistryInterface
{
return $this->environment;
}

/**
* Set the environment.
*
* @param EnvironmentInterface $environment The environment.
*
* @return FlatConfigRegistry
*/
public function setEnvironment(EnvironmentInterface $environment): FlatConfigRegistry
{
$this->environment = $environment;

return $this;
}
}
13 changes: 13 additions & 0 deletions src/Contao/Dca/Populator/HardCodedPopulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@

use ContaoCommunityAlliance\DcGeneral\BaseConfigRegistry;
use ContaoCommunityAlliance\DcGeneral\Clipboard\Clipboard;
use ContaoCommunityAlliance\DcGeneral\Config\FlatConfigRegistry;
use ContaoCommunityAlliance\DcGeneral\Contao\InputProvider;
use ContaoCommunityAlliance\DcGeneral\Controller\DefaultController;
use ContaoCommunityAlliance\DcGeneral\EnvironmentFlatConfigRegistryInterface;
use ContaoCommunityAlliance\DcGeneral\EnvironmentInterface;
use ContaoCommunityAlliance\DcGeneral\EnvironmentPopulator\AbstractEventDrivenEnvironmentPopulator;

Expand Down Expand Up @@ -99,6 +101,17 @@ public function populate(EnvironmentInterface $environment)
// @codingStandardsIgnoreEnd
}

if (($environment instanceof EnvironmentFlatConfigRegistryInterface)
&& (!$environment->getFlatConfigRegistry())
) {
$flatConfigRegistry = new FlatConfigRegistry();
$flatConfigRegistry->setEnvironment($environment);
$environment->setFlatConfigRegistry($flatConfigRegistry);
// @codingStandardsIgnoreStart
@\trigger_error('Fallback populator in use - implement a proper populator!', E_USER_DEPRECATED);
// @codingStandardsIgnoreEnd
}

$this->populateController($environment);
}
}
47 changes: 25 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 Expand Up @@ -1096,6 +1097,8 @@ private function pushRootModelToTreeCollection(
$sortDirection = $inputProvider->getParameter('sortDirection');

$baseConfig->setSorting([$orderProperty => $sortDirection]);
} elseif ($this->orderProperty && $this->sortDirection) {
$baseConfig->setSorting([$this->orderProperty => $this->sortDirection]);
}

// Fetch all root elements.
Expand Down
7 changes: 4 additions & 3 deletions src/Controller/BackendTreeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This file is part of contao-community-alliance/dc-general.
*
* (c) 2013-2019 Contao Community Alliance.
* (c) 2013-2021 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -13,7 +13,7 @@
* @package contao-community-alliance/dc-general
* @author Christian Schiffler <[email protected]>
* @author Sven Baumann <[email protected]>
* @copyright 2013-2019 Contao Community Alliance.
* @copyright 2013-2021 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/
Expand Down Expand Up @@ -354,7 +354,8 @@ private function prepareTreeSelector(PickerInterface $picker)
if (!isset($information['eval'])) {
$information['eval'] = array();
}
$information['eval'] = array_merge($property->getExtra(), $information['eval']);
$information['eval'] =
array_merge($property->getExtra(), $information['eval'], $picker->getConfig()->getExtras());

$treeSelector = new $GLOBALS['BE_FFL']['DcGeneralTreePicker'](
Widget::getAttributesFromDca(
Expand Down
Loading