1 Commits
1.0.6 ... 1.0.7

Author SHA1 Message Date
06a70b8611 Fix: use CSRF token manager for Contao 5 request token 2026-03-11 21:38:25 +01:00

View File

@@ -25,7 +25,7 @@ class DummyCopierModule extends BackendModule
$connection = System::getContainer()->get('database_connection');
$this->Template->action = Environment::get('request');
$this->Template->requestToken = \defined('REQUEST_TOKEN') ? REQUEST_TOKEN : '';
$this->Template->requestToken = $this->getCsrfToken();
$this->Template->pageChoices = $this->getPageChoices($connection);
$this->Template->moduleChoices = $this->getModuleChoices($connection);
$this->Template->contentChoices = $this->getContentChoices($connection);
@@ -139,6 +139,26 @@ class DummyCopierModule extends BackendModule
return $ids[0] ?? 0;
}
private function getCsrfToken(): string
{
$container = System::getContainer();
// Contao 5: use Symfony CSRF token manager
if ($container->has('contao.csrf.token_manager')) {
return $container
->get('contao.csrf.token_manager')
->getToken((string) $container->getParameter('contao.csrf_token_name'))
->getValue();
}
// Contao 4 fallback
if (\defined('REQUEST_TOKEN')) {
return REQUEST_TOKEN;
}
return '';
}
/**
* @return array<int,string>
*/