-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,221 additions
and
949 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -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; | ||
|
@@ -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. | ||
|
@@ -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; | ||
} | ||
|
||
/** | ||
|
@@ -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); | ||
} | ||
|
||
|
@@ -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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -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 | ||
*/ | ||
|
@@ -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( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.