Skip to content

Commit

Permalink
Update for translation handling and support arbitrary routing
Browse files Browse the repository at this point in the history
- Translate operation button labels and descriptions correctly including fallback to old style translation files
- Translate global operation button labels and descriptions correctly including fallback to old style translation files
- Correct translation key for editAll button
- Fix URL generating in CopyHandler
- Translate property names in SelectAllHandler correctly
- Translate property names in parent view header correctly
- Change various translation keys from .0 => .label etc.
- Fix URL generating in ClipboardController
- Really check permission for excluded fields instead of returning always false
- Handle translations in WidgetBuilder
- Support arbitrary routes in `ViewHelpers::redirectHome`
- Update referers in session for routes with attribute `_dcg_referer_update` (As Contao does for DC_Table)
- Translate properties in panel elements
  • Loading branch information
zonky2 committed May 15, 2024
1 parent bb6ddc0 commit 29999a3
Show file tree
Hide file tree
Showing 69 changed files with 1,771 additions and 1,286 deletions.
2 changes: 1 addition & 1 deletion .composer-require-checker.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"symbol-whitelist": [
"array", "bool", "false", "int", "mixed", "null", "self", "static", "parent", "string", "true", "void",
"array", "bool", "false", "int", "mixed", "never", "null", "self", "static", "parent", "string", "true", "void",
"ContaoCommunityAlliance\\Contao\\EventDispatcher\\CcaEventDispatcherBundle",
"ContaoCommunityAlliance\\DcGeneral\\Contao\\View\\Contao2BackendView\\Exception\\EditOnlyModeException",
"ContaoCommunityAlliance\\DcGeneral\\Contao\\View\\Contao2BackendView\\Exception\\NotCreatableException",
Expand Down
8 changes: 2 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"ext-json": "*",
"ext-pdo": "*",
"contao-community-alliance/events-contao-bindings": "^4.13",
"contao-community-alliance/translator": "^2.3",
"contao-community-alliance/translator": "^2.4.2",
"contao-community-alliance/url-builder": "^1.3",
"contao/core-bundle": "^4.13",
"contao/image": "^1.1",
Expand Down Expand Up @@ -95,12 +95,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.3.x-dev",
"dev-support/2.1.x": "2.1.x-dev"
"dev-master": "2.4.x-dev"
},
"contao-manager-plugin": "ContaoCommunityAlliance\\DcGeneral\\ContaoManager\\Plugin"
},
"scripts": {
"php-cs-fixer": "php-cs-fixer fix --rules=@PSR2"
}
}
10 changes: 6 additions & 4 deletions src/BaseConfigRegistry.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-2024 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,8 @@
* @package contao-community-alliance/dc-general
* @author Christian Schiffler <[email protected]>
* @author Sven Baumann <[email protected]>
* @copyright 2013-2019 Contao Community Alliance.
* @author Ingolf Steinhardt <[email protected]>
* @copyright 2013-2024 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 @@ -121,7 +122,7 @@ private function addParentFilter(ModelIdInterface $idParent, ConfigInterface $co
$baseFilter = $config->getFilter();
$filter = $condition->getFilter($parent);

if ($baseFilter) {
if (\is_array($baseFilter)) {
$filter = array_merge($baseFilter, $filter);
}

Expand All @@ -144,6 +145,7 @@ private function addParentFilter(ModelIdInterface $idParent, ConfigInterface $co
private function buildBaseConfig(?ModelIdInterface $parentId): ConfigInterface
{
$environment = $this->getEnvironment();
assert($environment instanceof EnvironmentInterface);
$provider = $environment->getDataProvider();
if (null === $provider) {
throw new DcGeneralRuntimeException('Data provider not set.');
Expand All @@ -156,7 +158,7 @@ private function buildBaseConfig(?ModelIdInterface $parentId): ConfigInterface
$additional = $definition->getBasicDefinition()->getAdditionalFilter();

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

Expand Down
9 changes: 5 additions & 4 deletions src/Contao/Callback/AbstractCallbackListener.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-2022 Contao Community Alliance.
* (c) 2013-2024 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -15,7 +15,7 @@
* @author Tristan Lins <[email protected]>
* @author Sven Baumann <[email protected]>
* @author Ingolf Steinhardt <[email protected]>
* @copyright 2013-2022 Contao Community Alliance.
* @copyright 2013-2024 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 @@ -60,7 +60,7 @@ public function __construct($callback, $restrictions = null)
{
$this->callback = $callback;

if ($restrictions) {
if (\is_array($restrictions)) {
call_user_func_array([$this, 'setRestrictions'], $restrictions);
}
}
Expand All @@ -86,7 +86,7 @@ public function setRestrictions(?string $dataContainerName = null)
*/
public function wantToExecute($event)
{
if (empty($this->dataContainerName)) {
if (null === $this->dataContainerName) {
return true;
}
if (!$event instanceof EnvironmentAwareInterface) {
Expand All @@ -95,6 +95,7 @@ public function wantToExecute($event)
if (null === $definition = $event->getEnvironment()->getDataDefinition()) {
return false;
}

return ($this->dataContainerName === $definition->getName());
}

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-2020 Contao Community Alliance.
* (c) 2013-2024 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,8 @@
* @package contao-community-alliance/dc-general
* @author Christian Schiffler <[email protected]>
* @author Sven Baumann <[email protected]>
* @copyright 2013-2020 Contao Community Alliance.
* @author Ingolf Steinhardt <[email protected]>
* @copyright 2013-2024 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 @@ -66,7 +67,7 @@ public function setRestrictions(?string $dataContainerName = null, ?string $prop
public function wantToExecute($event)
{
return parent::wantToExecute($event)
&& (empty($this->propertyName) || ($this->propertyName === $this->getProperty($event)));
&& (null === $this->propertyName || ($this->propertyName === $this->getProperty($event)));
}

private function getProperty(Event $event): string
Expand Down
9 changes: 4 additions & 5 deletions src/Contao/Callback/ContainerGlobalButtonCallbackListener.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-2024 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -14,7 +14,8 @@
* @author Christian Schiffler <[email protected]>
* @author Tristan Lins <[email protected]>
* @author Sven Baumann <[email protected]>
* @copyright 2013-2019 Contao Community Alliance.
* @author Ingolf Steinhardt <[email protected]>
* @copyright 2013-2024 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 @@ -59,9 +60,7 @@ public function setRestrictions($dataContainerName = null, $operationName = null
public function wantToExecute($event)
{
return parent::wantToExecute($event)
&& (empty($this->operationName)
|| ($this->operationName === $event->getKey())
);
&& (null === $this->operationName || ($this->operationName === $event->getKey()));
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/Contao/Callback/ContainerOnLoadCallbackListener.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-2024 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -14,7 +14,8 @@
* @author Christian Schiffler <[email protected]>
* @author Tristan Lins <[email protected]>
* @author Sven Baumann <[email protected]>
* @copyright 2013-2019 Contao Community Alliance.
* @author Ingolf Steinhardt <[email protected]>
* @copyright 2013-2024 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/
Expand All @@ -38,7 +39,7 @@ class ContainerOnLoadCallbackListener extends AbstractCallbackListener
*/
public function wantToExecute($event)
{
if (empty($this->dataContainerName)) {
if (null === $this->dataContainerName) {
return true;
}
if (null === $definition = $event->getDcGeneral()->getEnvironment()->getDataDefinition()) {
Expand Down
9 changes: 4 additions & 5 deletions src/Contao/Callback/ModelOperationButtonCallbackListener.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-2020 Contao Community Alliance.
* (c) 2013-2024 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -15,7 +15,8 @@
* @author Tristan Lins <[email protected]>
* @author David Molineus <[email protected]>
* @author Sven Baumann <[email protected]>
* @copyright 2013-2020 Contao Community Alliance.
* @author Ingolf Steinhardt <[email protected]>
* @copyright 2013-2024 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 @@ -69,9 +70,7 @@ public function wantToExecute($event)
}

return parent::wantToExecute($event)
&& (empty($this->operationName)
|| ($this->operationName === $event->getKey())
);
&& (null === $this->operationName || ($this->operationName === $event->getKey()));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Contao/Compatibility/DcCompat.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,10 @@ public function __get($name)
return $dataProvider->getEmptyModel()->getProviderName();

case 'value':
if ($this->propertyName && $this->getModel()) {
if (null !== $this->propertyName && null !== $this->getModel()) {
$model = $this->getModel();
assert($model instanceof ModelInterface);

return $model->getProperty($this->propertyName);
}
return null;
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-2022 Contao Community Alliance.
* (c) 2013-2024 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -16,7 +16,7 @@
* @author Tristan Lins <[email protected]>
* @author Sven Baumann <[email protected]>
* @author Ingolf Steinhardt <[email protected]>
* @copyright 2013-2022 Contao Community Alliance.
* @copyright 2013-2024 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 @@ -118,7 +118,7 @@ function (PopulateEnvironmentEvent $event) use ($dataContainerName) {
}

$parentName = $definition->getBasicDefinition()->getParentDataProvider();
if ($parentName) {
if (null !== $parentName) {
$parentDefinition = ($parentName === $definition->getName())
? $definition
: (new DcGeneralFactory())
Expand All @@ -133,7 +133,7 @@ function (PopulateEnvironmentEvent $event) use ($dataContainerName) {
}

$rootName = $definition->getBasicDefinition()->getRootDataProvider();
if ($rootName) {
if (null !== $rootName) {
$rootDefinition = ($rootName === $definition->getName())
? $definition
: (new DcGeneralFactory())
Expand Down Expand Up @@ -221,13 +221,13 @@ protected function parseSingleDataProvider(
ContainerInterface $container,
DataProviderDefinitionInterface $providers,
array $information,
$name
?string $name
) {
if (isset($information['factory'])) {
$providerInformation = (new \ReflectionClass($information['factory']))->newInstance()->build($information);
} else {
// Determine the name.
if ($name && !$this->isSpecialName($name)) {
if (null !== $name && !$this->isSpecialName($name)) {
$providerName = $name;
} elseif ('default' === $name) {
$providerName = $container->getName();
Expand All @@ -249,13 +249,11 @@ protected function parseSingleDataProvider(
if (!$providerInformation instanceof ContaoDataProviderInformation) {
return $providerInformation;
}
if (!$providerInformation->getTableName()) {
if (null === $providerInformation->getTableName()) {
if (isset($information['source'])) {
$providerInformation
->setTableName($information['source']);
$providerInformation->setTableName($information['source']);
} else {
$providerInformation
->setTableName($providerName);
$providerInformation->setTableName($providerName);
}
}

Expand Down Expand Up @@ -384,7 +382,7 @@ protected function parseRootCondition(
if (null !== ($rootCondition = $this->getFromDca('dca_config/rootEntries'))) {
$rootProvider = $container->getBasicDefinition()->getRootDataProvider();

if (!$rootProvider) {
if (null === $rootProvider) {
throw new DcGeneralRuntimeException(
'Root data provider name not specified in DCA but rootEntries section specified.'
);
Expand Down
Loading

0 comments on commit 29999a3

Please sign in to comment.