Skip to content

Commit

Permalink
Merge branch 'hotfix/fix_add_all_button_ref' into 'release/2.3.0'
Browse files Browse the repository at this point in the history
Fix add all button ref

See merge request metamodels/core!340
  • Loading branch information
zonky2 committed Sep 25, 2024
2 parents 5ed64dc + 5b00adb commit 5c04c2f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use ContaoCommunityAlliance\DcGeneral\InputProviderInterface;
use Doctrine\DBAL\Connection;
use MetaModels\IFactory;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

/**
Expand Down Expand Up @@ -55,18 +56,31 @@ class AddAllButtonListener
*/
private UrlGeneratorInterface $urlGenerator;

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

/**
* Create a new instance.
*
* @param Connection $connection The connection.
* @param IFactory $factory The factory.
* @param UrlGeneratorInterface $urlGenerator The url generator.
* @param RequestStack $requestStack The session.
*/
public function __construct(Connection $connection, IFactory $factory, UrlGeneratorInterface $urlGenerator)
{
public function __construct(
Connection $connection,
IFactory $factory,
UrlGeneratorInterface $urlGenerator,
RequestStack $requestStack
) {
$this->connection = $connection;
$this->factory = $factory;
$this->urlGenerator = $urlGenerator;
$this->requestStack = $requestStack;
}

/**
Expand Down Expand Up @@ -108,13 +122,15 @@ public function getGlobalButton(GetGlobalButtonEvent $event)
return;
}

$name = $this->factory->translateIdToMetaModelName($modelId);
$name = $this->factory->translateIdToMetaModelName($modelId);
$request = $this->requestStack->getCurrentRequest();

$event->setHref(
$this->urlGenerator->generate(
'metamodels.inputscreen.add_all',
['metaModel' => $name, 'inputScreen' => $inputScreen]
)
. '?ref=' . $request?->attributes->get('_contao_referer_id')
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This file is part of MetaModels/core.
*
* (c) 2012-2023 The MetaModels team.
* (c) 2012-2024 The MetaModels team.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -14,7 +14,7 @@
* @author Christian Schiffler <[email protected]>
* @author Sven Baumann <[email protected]>
* @author Ingolf Steinhardt <[email protected]>
* @copyright 2012-2023 The MetaModels team.
* @copyright 2012-2024 The MetaModels team.
* @license https://github.com/MetaModels/core/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/
Expand All @@ -27,6 +27,7 @@
use ContaoCommunityAlliance\DcGeneral\InputProviderInterface;
use Doctrine\DBAL\Connection;
use MetaModels\IFactory;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

/**
Expand Down Expand Up @@ -55,18 +56,31 @@ class AddAllButtonListener
*/
private UrlGeneratorInterface $urlGenerator;

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

/**
* Create a new instance.
*
* @param Connection $connection The connection.
* @param IFactory $factory The factory.
* @param UrlGeneratorInterface $urlGenerator The url generator.
* @param RequestStack $requestStack The session.
*/
public function __construct(Connection $connection, IFactory $factory, UrlGeneratorInterface $urlGenerator)
{
$this->connection = $connection;
$this->factory = $factory;
public function __construct(
Connection $connection,
IFactory $factory,
UrlGeneratorInterface $urlGenerator,
RequestStack $requestStack
) {
$this->connection = $connection;
$this->factory = $factory;
$this->urlGenerator = $urlGenerator;
$this->requestStack = $requestStack;
}

/**
Expand Down Expand Up @@ -108,13 +122,15 @@ public function getGlobalButton(GetGlobalButtonEvent $event)
return;
}

$name = $this->factory->translateIdToMetaModelName($modelId);
$name = $this->factory->translateIdToMetaModelName($modelId);
$request = $this->requestStack->getCurrentRequest();

$event->setHref(
$this->urlGenerator->generate(
'metamodels.rendersetting.add_all',
['metaModel' => $name, 'renderSetting' => $renderSetting]
)
. '?ref=' . $request?->attributes->get('_contao_referer_id')
);
}
}

0 comments on commit 5c04c2f

Please sign in to comment.