Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time

Document Routes

Generating Routes in current request

To create document paths/urls in current request via Twig or PHP API you may want to use the _i18n parameter builder:

Twig

{# relative #}
{{ dump( i18n_entity_route(pimcore_document(46), {}, false) ) }}

{# absolute #}
{{ dump( i18n_entity_route(pimcore_document(46), {}, true) ) }}

PHP

use I18nBundle\Builder\RouteParameterBuilder;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

public function myAction(Request $request) 
{
    $parameters = RouteParameterBuilder::buildForEntityWithRequest(
        \Pimcore\Model\Document::getById(20),
        [],
        $request
    );

    return $this->urlGenerator->generate('', $parameters, UrlGeneratorInterface::ABSOLUTE_URL);
}

Generating Routes in CLI

To create document paths/urls in headless context:

PHP

use I18nBundle\Builder\RouteParameterBuilder;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

protected function execute(InputInterface $input, OutputInterface $output): int
{
    $parameters = RouteParameterBuilder::buildForEntity(
        \Pimcore\Model\Document::getById(20),
        [],
        []
    );

    return $this->urlGenerator->generate('', $parameters, UrlGeneratorInterface::ABSOLUTE_URL);
}