You are here

class NodeHierarchyEventSubscriber in Entity Reference Hierarchy 8

Hierarchy

  • class \Drupal\entity_hierarchy\EventSubscriber\NodeHierarchyEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of NodeHierarchyEventSubscriber

1 string reference to 'NodeHierarchyEventSubscriber'
entity_hierarchy.services.yml in ./entity_hierarchy.services.yml
entity_hierarchy.services.yml
1 service uses NodeHierarchyEventSubscriber
entity_hierarchy.event_subscriber in ./entity_hierarchy.services.yml
Drupal\entity_hierarchy\EventSubscriber\NodeHierarchyEventSubscriber

File

src/EventSubscriber/NodeHierarchyEventSubscriber.php, line 23
Contains \Drupal\entity_hierarchy\EventSubscriber\NodeHierarchyEventSubscriber.

Namespace

Drupal\entity_hierarchy\EventSubscriber
View source
class NodeHierarchyEventSubscriber implements EventSubscriberInterface {

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * Constructs a NodeHierarchyEventSubscriber object.
   */
  public function __construct(ModuleHandlerInterface $module_handler) {
    $this->moduleHandler = $module_handler;
  }

  /**
   * Initializes Entity Hierarchy module requirements.
   */
  public function onRequest(GetResponseEvent $event) {

    // Ensure we are not serving a cached page.
    if (function_exists('drupalSetContent')) {
      if ($this->moduleHandler
        ->moduleExists('token')) {
        include_once DRUPAL_ROOT . '/' . libraries_get_path('module', 'entity_hierarchy') . '/includes/entity_hierarchy_token.inc';
      }
      if ($this->moduleHandler
        ->moduleExists('workflow_ng')) {
        include_once DRUPAL_ROOT . '/' . libraries_get_path('module', 'entity_hierarchy') . '/includes/entity_hierarchy_workflow_ng.inc';
      }
    }
  }

  /**
   * Prevents page redirection so that the developer can see the intermediate debug data.
   * @param FilterResponseEvent $event
   */
  public function onResponse(FilterResponseEvent $event) {
    $response = $event
      ->getResponse();
  }

  /**
   * Implements EventSubscriberInterface::getSubscribedEvents().
   *
   * @return array
   *   An array of event listener definitions.
   */
  static function getSubscribedEvents() {

    // Set a low value to start as early as possible.
    $events[KernelEvents::REQUEST][] = array(
      'onRequest',
      -100,
    );

    // Why only large positive value works here?
    $events[KernelEvents::RESPONSE][] = array(
      'onResponse',
      1000,
    );
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
NodeHierarchyEventSubscriber::$moduleHandler protected property The module handler.
NodeHierarchyEventSubscriber::getSubscribedEvents static function Implements EventSubscriberInterface::getSubscribedEvents().
NodeHierarchyEventSubscriber::onRequest public function Initializes Entity Hierarchy module requirements.
NodeHierarchyEventSubscriber::onResponse public function Prevents page redirection so that the developer can see the intermediate debug data.
NodeHierarchyEventSubscriber::__construct public function Constructs a NodeHierarchyEventSubscriber object.