Skip to content

Commit

Permalink
Changes for MM xliff
Browse files Browse the repository at this point in the history
  • Loading branch information
zonky2 committed May 7, 2024
1 parent cc1a0aa commit 766e68f
Show file tree
Hide file tree
Showing 28 changed files with 1,221 additions and 949 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
use function explode;
use function in_array;
use function is_array;
use function is_callable;
use function next;
use function parse_str;
use function reset;
Expand Down
2 changes: 1 addition & 1 deletion src/Contao/Picker/PagePickerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function __construct(
*/
public function getName()
{
return 'ccaPagePicker';
return 'pagePicker';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@

use function array_key_exists;
use function implode;
use function in_array;
use function is_string;
use function sprintf;
use function str_contains;
use function str_replace;
use function trigger_error;
Expand Down Expand Up @@ -154,7 +157,7 @@ public function __construct(
}
if (null === $tokenName) {
$tokenName = System::getContainer()->getParameter('contao.csrf_token_name');
assert(\is_string($tokenName));
assert(is_string($tokenName));

// @codingStandardsIgnoreStart
@trigger_error(
Expand Down Expand Up @@ -264,7 +267,7 @@ protected function process(Action $action, EnvironmentInterface $environment)
*
* @return string
*/
private function languageSwitcher(EnvironmentInterface $environment)
private function languageSwitcher(EnvironmentInterface $environment): string
{
$template = new ContaoBackendViewTemplate('dcbe_general_language_selector');

Expand Down Expand Up @@ -335,9 +338,9 @@ protected function translate($key, $domain, array $parameters = [])

$translated =
$this->translator->trans(
\sprintf('%s.%s', $domain, $key),
sprintf('%s.%s', $domain, $key),
$parameters,
\sprintf('contao_%s', $domain)
sprintf('contao_%s', $domain)
);
}

Expand Down Expand Up @@ -494,7 +497,7 @@ protected function loadCollection(EnvironmentInterface $environment)
*
* @return string
*/
private function generateHeaderButtons(EnvironmentInterface $environment)
private function generateHeaderButtons(EnvironmentInterface $environment): string
{
return (new GlobalButtonRenderer($environment))->render();
}
Expand All @@ -512,7 +515,7 @@ private function renderCollection(
EnvironmentInterface $environment,
CollectionInterface $collection,
array $grouping
) {
): void {
$definition = $environment->getDataDefinition();
assert($definition instanceof ContainerInterface);

Expand Down Expand Up @@ -578,7 +581,7 @@ private function addGroupHeader(
&$groupClass,
&$eoCount,
&$remoteCur = null
) {
): void {
if ($grouping && GroupAndSortingInformationInterface::GROUP_NONE !== $grouping['mode']) {
$remoteNew = $this->renderGroupHeader(
$grouping['property'],
Expand Down Expand Up @@ -612,7 +615,7 @@ private function addGroupHeader(
*
* @return string When no information of panels can be obtained from the data container.
*/
private function panel(EnvironmentInterface $environment, $ignoredPanels = [])
private function panel(EnvironmentInterface $environment, array $ignoredPanels = []): string
{
$view = $environment->getView();
assert($view instanceof BackendViewInterface);
Expand All @@ -627,7 +630,7 @@ private function panel(EnvironmentInterface $environment, $ignoredPanels = [])
*
* @return array
*/
private function getTableHead(EnvironmentInterface $environment)
private function getTableHead(EnvironmentInterface $environment): array
{
$definition = $environment->getDataDefinition();
assert($definition instanceof ContainerInterface);
Expand All @@ -638,7 +641,7 @@ private function getTableHead(EnvironmentInterface $environment)
$columns = $this->getSortingColumns($sorting);
foreach ($formatter->getPropertyNames() as $field) {
$tableHead[] = [
'class' => 'tl_folder_tlist col_' . $field . (\in_array($field, $columns) ? ' ordered_by' : ''),
'class' => 'tl_folder_tlist col_' . $field . (in_array($field, $columns) ? ' ordered_by' : ''),
'content' => $this->translateButtonLabel($field, $definition->getName())
];
}
Expand Down Expand Up @@ -666,12 +669,12 @@ private function getTableHead(EnvironmentInterface $environment)
* @SuppressWarnings(PHPMD.CamelCaseVariableName)
*/
private function renderGroupHeader(
$field,
string $field,
ModelInterface $model,
$groupMode,
$groupLength,
string $groupMode,
int $groupLength,
EnvironmentInterface $environment
) {
): ?string {
$definition = $environment->getDataDefinition();
assert($definition instanceof ContainerInterface);

Expand Down Expand Up @@ -716,7 +719,7 @@ protected function getSelectButtons(EnvironmentInterface $environment)
*
* @return bool
*/
private function isSortable(EnvironmentInterface $environment)
private function isSortable(EnvironmentInterface $environment): bool
{
$definition = $environment->getDataDefinition();
assert($definition instanceof ContainerInterface);
Expand Down Expand Up @@ -751,7 +754,7 @@ protected function renderPasteTopButton(EnvironmentInterface $environment, $sort
assert($basicDefinition instanceof BasicDefinitionInterface);

$dataProvider = $basicDefinition->getDataProvider();
assert(\is_string($dataProvider));
assert(is_string($dataProvider));

$filter->andModelIsFromProvider($dataProvider);

Expand Down Expand Up @@ -784,7 +787,7 @@ protected function renderPasteTopButton(EnvironmentInterface $environment, $sort
ContaoEvents::IMAGE_GET_HTML
);

return \sprintf(
return sprintf(
'<a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a>',
$urlEvent->getUrl(),
$this->translateButtonLabel('pastenew', $definition->getName()),
Expand All @@ -802,7 +805,7 @@ protected function renderPasteTopButton(EnvironmentInterface $environment, $sort
* @SuppressWarnings(PHPMD.Superglobals)
* @SuppressWarnings(PHPMD.CamelCaseVariableName)
*/
private function breadcrumb(EnvironmentInterface $environment)
private function breadcrumb(EnvironmentInterface $environment): ?string
{
$event = new GetBreadcrumbEvent($environment);

Expand Down Expand Up @@ -830,7 +833,7 @@ private function breadcrumb(EnvironmentInterface $environment)
*
* @return array
*/
private function getSortingColumns($sortingDefinition)
private function getSortingColumns(?GroupAndSortingDefinitionInterface $sortingDefinition): array
{
if (null === $sortingDefinition) {
return [];
Expand All @@ -855,7 +858,7 @@ private function getSortingColumns($sortingDefinition)
*
* @return array
*/
private function getSelectContainer(EnvironmentInterface $environment)
private function getSelectContainer(EnvironmentInterface $environment): array
{
$inputProvider = $environment->getInputProvider();
assert($inputProvider instanceof InputProviderInterface);
Expand Down Expand Up @@ -892,7 +895,7 @@ private function getSelectContainer(EnvironmentInterface $environment)
*
* @return void
*/
private function handleEditAllButton(CollectionInterface $collection, EnvironmentInterface $environment)
private function handleEditAllButton(CollectionInterface $collection, EnvironmentInterface $environment): void
{
if (0 < $collection->count()) {
return;
Expand Down
79 changes: 58 additions & 21 deletions src/Contao/View/Contao2BackendView/ActionHandler/CopyHandler.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-2023 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 @@ -17,14 +17,13 @@
* @author Sven Baumann <[email protected]>
* @author Richard Henkenjohann <[email protected]>
* @author Ingolf Steinhardt <[email protected]>
* @copyright 2013-2023 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
*/

namespace ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\ActionHandler;

use Contao\System;
use ContaoCommunityAlliance\Contao\Bindings\ContaoEvents;
use ContaoCommunityAlliance\Contao\Bindings\Events\Controller\RedirectEvent;
use ContaoCommunityAlliance\Contao\Bindings\Events\System\LogEvent;
Expand All @@ -48,6 +47,8 @@
use ContaoCommunityAlliance\UrlBuilder\Contao\CsrfUrlBuilderFactory;
use ContaoCommunityAlliance\UrlBuilder\UrlBuilder;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

/**
* Class CopyModelController handles copy action on a model.
Expand All @@ -65,19 +66,41 @@ class CopyHandler
*
* @var CsrfUrlBuilderFactory
*/
private $securityUrlBuilder;
private CsrfUrlBuilderFactory $securityUrlBuilder;

/**
* The request stack.
*
* @var RequestStack
*/
private RequestStack $requestStack;

/**
* The URL generator.
*
* @var UrlGeneratorInterface
*/
private UrlGeneratorInterface $urlGenerator;

/**
* PasteHandler constructor.
*
* @param RequestScopeDeterminator $scopeDeterminator The request mode determinator.
* @param CsrfUrlBuilderFactory $securityUrlBuilder The URL builder factory for URLs with security token.
* @param RequestStack $requestStack The request stack.
* @param UrlGeneratorInterface $urlGenerator The URL generator.
*/
public function __construct(RequestScopeDeterminator $scopeDeterminator, CsrfUrlBuilderFactory $securityUrlBuilder)
{
public function __construct(
RequestScopeDeterminator $scopeDeterminator,
CsrfUrlBuilderFactory $securityUrlBuilder,
RequestStack $requestStack,
UrlGeneratorInterface $urlGenerator,
) {
$this->setScopeDeterminator($scopeDeterminator);

$this->securityUrlBuilder = $securityUrlBuilder;
$this->requestStack = $requestStack;
$this->urlGenerator = $urlGenerator;
}

/**
Expand Down Expand Up @@ -230,24 +253,38 @@ protected function redirect($environment, $copiedModelId)
return;
}

// Build a clean url to remove the copy related arguments instead of using the AddToUrlEvent.
$urlBuilder = new UrlBuilder();
$urlBuilder
->setPath('contao')
->setQueryParameter('do', $inputProvider->getParameter('do'))
->setQueryParameter('table', $copiedModelId->getDataProviderName())
->setQueryParameter('act', 'edit')
->setQueryParameter('id', $copiedModelId->getSerialized());
if (null !== ($pid = $inputProvider->getParameter('pid'))) {
$urlBuilder->setQueryParameter('pid', $pid);
}

$redirectEvent = new RedirectEvent($this->securityUrlBuilder->create($urlBuilder->getUrl())->getUrl());

if (null === ($dispatcher = $environment->getEventDispatcher())) {
return;
}

$request = $this->requestStack->getCurrentRequest();
$routeName = $request?->attributes->get('_route');
// Build a clean url to remove the copy related arguments instead of using the AddToUrlEvent.
$urlBuilder = new UrlBuilder();
if ($routeName !== 'contao.backend') {
$params = [
'table' => $copiedModelId->getDataProviderName(),
'act' => 'edit',
'id' => $copiedModelId->getSerialized(),
];
if (null !== ($pid = $inputProvider->getParameter('pid'))) {
$params['pid'] = $pid;
}
$url = $this->urlGenerator->generate($routeName, $params);
} else {
$urlBuilder
->setPath('contao')
->setQueryParameter('do', $inputProvider->getParameter('do'))
->setQueryParameter('table', $copiedModelId->getDataProviderName())
->setQueryParameter('act', 'edit')
->setQueryParameter('id', $copiedModelId->getSerialized());
if (null !== ($pid = $inputProvider->getParameter('pid'))) {
$urlBuilder->setQueryParameter('pid', $pid);
}
$url = $urlBuilder->getUrl();
}
$redirectEvent = new RedirectEvent($this->securityUrlBuilder->create($url)->getUrl());

$dispatcher->dispatch($redirectEvent, ContaoEvents::CONTROLLER_REDIRECT);
}

Expand Down Expand Up @@ -308,7 +345,7 @@ protected function process(EnvironmentInterface $environment)
*
* @return string|bool
*/
private function checkPermission(EnvironmentInterface $environment)
private function checkPermission(EnvironmentInterface $environment): bool|string
{
if (null === ($definition = $environment->getDataDefinition())) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ private function getCollection(
$model->setID($property->getName());
$model->setProperty(
'name',
$property->getLabel() ?: $property->getName()
$this->translator->trans($property->getLabel(), [], $definition->getName())
);
$model->setProperty(
'description',
$property->getDescription() ?: $property->getName()
$this->translator->trans($property->getDescription(), [], $definition->getName())
);

$this->handlePropertyFileTree($property);
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-2023 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 Stefan Heimes <[email protected]>
* @author Sven Baumann <[email protected]>
* @author Ingolf Steinhardt <[email protected]>
* @copyright 2013-2023 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 @@ -617,6 +617,9 @@ private function getSelectCollection(EnvironmentInterface $environment)
foreach (($session['models'] ?? []) as $modelId) {
$modelIds[] = ModelId::fromSerialized($modelId)->getId();
}
if ([] === $modelIds) {
return $dataProvider->getEmptyCollection();
}

$idProperty = method_exists($dataProvider, 'getIdProperty') ? $dataProvider->getIdProperty() : 'id';
$collection = $dataProvider->fetchAll(
Expand Down
10 changes: 6 additions & 4 deletions src/Contao/View/Contao2BackendView/ButtonRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,12 @@ private function hasPasteNewButton()
private function buildCommand($command, $model, $previous, $next, $isCircularReference, $childIds)

Check failure on line 325 in src/Contao/View/Contao2BackendView/ButtonRenderer.php

View workflow job for this annotation

GitHub Actions / PHP: 8.1 Contao: ~4.13.0

[325 - 415] The method buildCommand() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. (Ruleset: Code Size Rules, https://phpmd.org/rules/codesize.html#cyclomaticcomplexity) (reported by phpmd: CyclomaticComplexity)

Check failure on line 325 in src/Contao/View/Contao2BackendView/ButtonRenderer.php

View workflow job for this annotation

GitHub Actions / PHP: 8.2 Contao: ~4.13.0

[325 - 415] The method buildCommand() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. (Ruleset: Code Size Rules, https://phpmd.org/rules/codesize.html#cyclomaticcomplexity) (reported by phpmd: CyclomaticComplexity)

Check failure on line 325 in src/Contao/View/Contao2BackendView/ButtonRenderer.php

View workflow job for this annotation

GitHub Actions / PHP: 8.1 Contao: ~4.13.0

[325 - 415] The method buildCommand() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. (Ruleset: Code Size Rules, https://phpmd.org/rules/codesize.html#cyclomaticcomplexity) (reported by phpmd: CyclomaticComplexity)

Check failure on line 325 in src/Contao/View/Contao2BackendView/ButtonRenderer.php

View workflow job for this annotation

GitHub Actions / PHP: 8.2 Contao: ~4.13.0

[325 - 415] The method buildCommand() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. (Ruleset: Code Size Rules, https://phpmd.org/rules/codesize.html#cyclomaticcomplexity) (reported by phpmd: CyclomaticComplexity)
{
$extra = (array) $command->getExtra();
$attributes = '';

if (!empty($extra['attributes'])) {
$attributes .= sprintf($extra['attributes'], $model->getID());
if ('' !== ($attributes = $extra['attributes'] ?? '')) {
// BC compatibility with legacy strings containing 'Edit item %s'
if (!str_contains($attributes, '%id%')) {
$attributes = sprintf($attributes, $model->getID());
}
$attributes = strtr($attributes, ['%id%' => $model->getId()]);
}
$icon = $extra['icon'];

Expand Down
Loading

0 comments on commit 766e68f

Please sign in to comment.