Ich konnte das Problem jetzt per Service Decoration in Symfony lösen.
PHP-Code:
// src/Decorator/PageUrlGeneratorDecorator.php
namespace App\Decorator;
use Contao\Input;
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
#[AsDecorator('contao.routing.page_url_generator')]
class PageUrlGeneratorDecorator implements UrlGeneratorInterface
{
private $generator;
private $requestStack;
public function __construct(UrlGeneratorInterface $generator, RequestStack $requestStack)
{
$this->generator = $generator;
$this->requestStack = $requestStack;
}
public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH): string
{
// Im Backend überspringen
$request = $this->requestStack->getCurrentRequest();
if ($request && strpos($request->get('_route'), 'contao_backend') === 0) {
return $this->generator->generate($name, $parameters, $referenceType);
}
$objPage = $parameters["_content"]; // PageModel der Zielseite
$parameters["parameters"] = '/1'; // Beliebige Parameter setzen
return $this->generator->generate($name, $parameters, $referenceType);
}
public function setContext(RequestContext $context)
{
$this->generator->setContext($context);
}
public function getContext(): RequestContext
{
return $this->generator->getContext();
}
}
VG
Dennis
Lesezeichen