class ExternalHreflangGetCurrentUrlEventSubscriber in External Hreflang 8
Subscriber for ExternalHreflangGetCurrentUrlEvent.
@package Drupal\external_hreflang\EventSubscriber
Hierarchy
- class \Drupal\external_hreflang\EventSubscriber\ExternalHreflangGetCurrentUrlEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of ExternalHreflangGetCurrentUrlEventSubscriber
1 string reference to 'ExternalHreflangGetCurrentUrlEventSubscriber'
1 service uses ExternalHreflangGetCurrentUrlEventSubscriber
File
- src/
EventSubscriber/ ExternalHreflangGetCurrentUrlEventSubscriber.php, line 16
Namespace
Drupal\external_hreflang\EventSubscriberView source
class ExternalHreflangGetCurrentUrlEventSubscriber implements EventSubscriberInterface {
/**
* The path matcher.
*
* @var \Drupal\Core\Path\PathMatcherInterface
*/
private $pathMatcher;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
private $requestStack;
/**
* ExternalHreflangGetCurrentUrlEventSubscriber constructor.
*
* @param \Drupal\Core\Path\PathMatcherInterface $path_matcher
* The path matcher.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
*/
public function __construct(PathMatcherInterface $path_matcher, RequestStack $request_stack) {
$this->pathMatcher = $path_matcher;
$this->requestStack = $request_stack;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[ExternalHreflangGetCurrentUrlEvent::EVENT_NAME][] = [
'onGetCurrentUrlEvent',
10,
];
return $events;
}
/**
* Default implementation of getting current page url.
*
* @param \Drupal\external_hreflang\Event\ExternalHreflangGetCurrentUrlEvent $event
* Event object.
*/
public function onGetCurrentUrlEvent(ExternalHreflangGetCurrentUrlEvent $event) {
if ($this->pathMatcher
->isFrontPage()) {
$url = Url::fromRoute('<front>');
}
else {
$url = Url::createFromRequest($this->requestStack
->getCurrentRequest());
}
$event
->setCurrentUrl($url);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ExternalHreflangGetCurrentUrlEventSubscriber:: |
private | property | The path matcher. | |
ExternalHreflangGetCurrentUrlEventSubscriber:: |
private | property | The request stack. | |
ExternalHreflangGetCurrentUrlEventSubscriber:: |
public static | function | ||
ExternalHreflangGetCurrentUrlEventSubscriber:: |
public | function | Default implementation of getting current page url. | |
ExternalHreflangGetCurrentUrlEventSubscriber:: |
public | function | ExternalHreflangGetCurrentUrlEventSubscriber constructor. |