class StaticPageSubscriber in Static Page 8
Static Page subscriber for controller requests.
Hierarchy
- class \Drupal\static_page\EventSubscriber\StaticPageSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of StaticPageSubscriber
1 string reference to 'StaticPageSubscriber'
1 service uses StaticPageSubscriber
File
- src/
EventSubscriber/ StaticPageSubscriber.php, line 13
Namespace
Drupal\static_page\EventSubscriberView source
class StaticPageSubscriber implements EventSubscriberInterface {
/**
* Performs check on the beginning of a request.
*/
public function onRequest(GetResponseEvent $event) {
// $current_path = \Drupal::service('path.current')->getPath();
// $url_object = \Drupal::service('path.validator')->getUrlIfValid($form_state->getValue($current_path));
// $route_name = $url_object->getRouteName();
$route_name = \Drupal::routeMatch()
->getRouteName();
if ($route_name == 'entity.node.canonical') {
$node = \Drupal::routeMatch()
->getParameter('node');
}
elseif ($route_name == 'entity.node.revision') {
$vid = \Drupal::routeMatch()
->getParameter('node_revision');
$node = node_revision_load($vid);
}
if (!empty($node)) {
$type = $node
->getType();
$config = \Drupal::config('static_page.fields');
$static_fields = $config
->get('fields');
if (!empty($static_fields[$type])) {
$static_page = $node
->get($static_fields[$type])->value;
$response = new Response($static_page);
$event
->setResponse($response);
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = [
'onRequest',
];
// $events[KernelEvents::RESPONSE][] = array('onResponse');
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StaticPageSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
StaticPageSubscriber:: |
public | function | Performs check on the beginning of a request. |