UrlGenerator.php in Persistent URL 8
File
src/Routing/UrlGenerator.php
View source
<?php
namespace Drupal\purl\Routing;
use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
use Drupal\Core\RouteProcessor\OutboundRouteProcessorInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\Routing\UrlGenerator as UrlGeneratorBase;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Exception\InvalidParameterException;
use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Symfony\Component\Routing\RequestContext;
class UrlGenerator implements UrlGeneratorInterface {
protected $urlGenerator;
public function __construct(UrlGeneratorInterface $urlGenerator) {
$this->urlGenerator = $urlGenerator;
}
public function setContext(RequestContext $context) {
$this->urlGenerator
->setContext($context);
}
public function generateFromRoute($name, $parameters = array(), $options = array(), $collect_bubbleable_metadata = FALSE) {
$hostOverride = null;
$originalHost = null;
if (isset($options['host']) && strlen((string) $options['host']) > 0) {
$hostOverride = $options['host'];
$originalHost = $this
->getContext()
->getHost();
$this
->getContext()
->setHost($hostOverride);
}
$result = $this->urlGenerator
->generateFromRoute($name, $parameters, $options, $collect_bubbleable_metadata);
if ($hostOverride) {
$this
->getContext()
->setHost($originalHost);
}
return $result;
}
public function getContext() {
return $this->urlGenerator
->getContext();
}
public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) {
return $this->urlGenerator
->generate($name, $parameters, $referenceType);
}
public function getPathFromRoute($name, $parameters = array()) {
return $this->urlGenerator
->getPathFromRoute($name, $parameters);
}
public function supports($name) {
return $this->urlGenerator
->supports($name);
}
public function getRouteDebugMessage($name, array $parameters = array()) {
return $this->urlGenerator
->getRouteDebugMessage($name, $parameters);
}
}