You are here

class EventSubscriber in JS Callback Handler 8.3

Same name in this branch
  1. 8.3 src/EventSubscriber.php \Drupal\js\EventSubscriber
  2. 8.3 js_callback_examples/src/EventSubscriber.php \Drupal\js_callback_examples\EventSubscriber

EventSubscriber.

Hierarchy

  • class \Drupal\js_callback_examples\EventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of EventSubscriber

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

File

js_callback_examples/src/EventSubscriber.php, line 13

Namespace

Drupal\js_callback_examples
View source
class EventSubscriber implements EventSubscriberInterface {

  /**
   * @var \Drupal\js\Js
   */
  protected $js;

  /**
   * EventSubscriber constructor.
   *
   * @param \Drupal\js\Js $js
   *   The JS Callback service.
   */
  public function __construct(Js $js) {
    $this->js = $js;
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    return [
      KernelEvents::REQUEST => [
        'onRequest',
      ],
    ];
  }

  /**
   * For
   */
  public function onRequest() {

    // Only show this message if not executing a JS Callback.
    if (!$this->js
      ->isExecuting()) {
      drupal_set_message(t('You have the JS Example module enabled. Please make sure you disable it when you are done. View <a href=":url">example page</a>.', [
        ':url' => Url::fromRoute('js_callback_examples.form')
          ->toString(),
      ]), 'status');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EventSubscriber::$js protected property
EventSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
EventSubscriber::onRequest public function For
EventSubscriber::__construct public function EventSubscriber constructor.