<commit_before><!doctype html>
<html lang="en">

  <head>
    <meta charset="utf-8">

    <title>Drupal 8 and the Symfony Event Dispatche</title>

    <meta name="description" content="Drupal 8 and the Symfony Event Dispatcher">
    <meta name="author" content="<NAME>">

    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">

    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">

    <link rel="stylesheet" href="css/reveal.css">
    <link rel="stylesheet" href="css/theme/black.css" id="theme">

    <!-- Code syntax highlighting -->
    <link rel="stylesheet" href="lib/css/zenburn.css">

    <!--[if lt IE 9]>
    <script src="lib/js/html5shiv.js"></script>
    <![endif]-->
  </head>

  <body>

    <div class="reveal">

      <!-- Any section element inside of this container is displayed as a slide -->
      <div class="slides">
        <section>
          <h1>Drupal 8 and the Symfony Event Dispatcher</h1>
          <p><NAME> / <a href="http://twitter.com/ericgsmith">@ericgsmith</a></p>
          <aside class="notes">
            Intro / see how many people are using d8.
          </aside>
        </section>

        <section>
          <ul>
            <li>What is it / why it's useful</li>
            <li>Sending an event</li>
            <li>Responding to an event</li>
          </ul>
        </section>

        <section>
          <h2>Why should you care?</h2>
          <p>No more hook_boot</p>
          <p>No more hook_init</p>
          <p>No more hook_exit</p>
          <aside class="notes">
            Hook system - one of the first things we learn about drupal.
            A lot of invoked hooks are gone. Might be completely gone for D9.
            replaced by the event dispatcher.
          </aside>
        </section>

        <section>
          <section>
            <h2>Events</h2>
            <blockquote cite="https://en.wikipedia.org/wiki/Event_(computing)">
              <p>... an event is an action or occurrence recognised by software that may be handled by the software.</p>
            </blockquote>
            <aside class="notes">
              Think javascript. Responding to events is something we often do.
              These events can be anything.
            </aside>
          </section>

          <section>
            <h2>What we might have done</h2>
            <p>We have a form that collects a name and email address.</p>
            <ul>
              <li>Send an email to the user</li>
              <li>Add the user to our CRM</li>
              <li>Add the user to our newsletter</li>
              <li>Tweet their details to the company fridge</li>
            </ul>
          </section>

          <section>
            <pre><code>
public function submitForm(array &$form, FormStateInterface $form_state) {
  $name = $form_state->getValue('name');
  $email = $form_state->getValue('email');

  $container = Drupal::getContainer();

  $mailer = $container->get('plugin.manager.mail');
  $mailer->mail('example', 'signup_form', $email, .... ['name' => $name]);

  $crm_manager = $container->get('crm.manager');
  $crm_manager->subscribe($name, $email);

  $mailchimp_manager = $container->get('mailchimp.manager');
  $mailchimp_manager->add($name, $email);

  $twitter_manager = $container->get('twitter.manager');
  $tweet = new ThisIsGettingRidiculous();
  $tweet->setMessage('blah blah ' . $name . ' blah blah');
  $twitter_manager->tweet($tweet);
}
</code></pre>
          </section>

          <section>
            <h2>This is bad</h2>
            <ul>
              <li>Form class is doing too many things</li>
              <li>Tightly coupled</li>
              <li>Hard to maintain</li>
              <li>Harder to reuse</li>
            </ul>
          </section>

          <section>
            <h2>Symfony Event Dispatcher</h2>
            <img src="gatwick.jpg" />
            <aside class="notes">
              A component - drupal is more modern and component based.
              Component - a bit of functionality we can use.
              Example of the mediator design pattern.
              Object the encapsulates the communication of other objects.
              Mediator promotes loose coupling by keeping objects from referring to each other explicitly

              Drupal is using ContainerAwareEventDispatcher
            </aside>
          </section>
        </section>

        <section>
          <section>
            <h2>Dispatching an event</h2>
            <ul><commit_msg>Fixed<commit_after><!doctype html>
<html lang="en">

  <head>
    <meta charset="utf-8">

    <title>Drupal 8 and the Symfony Event Dispatche</title>

    <meta name="description" content="Drupal 8 and the Symfony Event Dispatcher">
    <meta name="author" content="<NAME>">

    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">

    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">

    <link rel="stylesheet" href="css/reveal.css">
    <link rel="stylesheet" href="css/theme/black.css" id="theme">

    <!-- Code syntax highlighting -->
    <link rel="stylesheet" href="lib/css/zenburn.css">

    <!--[if lt IE 9]>
    <script src="lib/js/html5shiv.js"></script>
    <![endif]-->
  </head>

  <body>

    <div class="reveal">

      <!-- Any section element inside of this container is displayed as a slide -->
      <div class="slides">
        <section>
          <h1>Drupal 8 and the Symfony Event Dispatcher</h1>
          <p><NAME> / <a href="http://twitter.com/ericgsmith">@ericgsmith</a></p>
          <aside class="notes">
            Intro / see how many people are using d8.
          </aside>
        </section>

        <section>
          <ul>
            <li>What is it / why it's useful</li>
            <li>Sending an event</li>
            <li>Responding to an event</li>
          </ul>
        </section>

        <section>
          <h2>Why should you care?</h2>
          <p>No more hook_boot</p>
          <p>No more hook_init</p>
          <p>No more hook_exit</p>
          <aside class="notes">
            Hook system - one of the first things we learn about drupal.
            A lot of invoked hooks are gone. Might be completely gone for D9.
            replaced by the event dispatcher.
          </aside>
        </section>

        <section>
          <section>
            <h2>Events</h2>
            <blockquote cite="https://en.wikipedia.org/wiki/Event_(computing)">
              <p>... an event is an action or occurrence recognised by software that may be handled by the software.</p>
            </blockquote>
            <aside class="notes">
              Think javascript. Responding to events is something we often do.
              These events can be anything.
            </aside>
          </section>

          <section>
            <h2>What we might have done</h2>
            <p>We have a form that collects a name and email address.</p>
            <ul>
              <li>Send an email to the user</li>
              <li>Add the user to our CRM</li>
              <li>Add the user to our newsletter</li>
              <li>Tweet their details to the company fridge</li>
            </ul>
          </section>

          <section>
            <pre><code>
public function submitForm(array &$form, FormStateInterface $form_state) {
  $name = $form_state->getValue('name');
  $email = $form_state->getValue('email');

  $container = Drupal::getContainer();

  $mailer = $container->get('plugin.manager.mail');
  $mailer->mail('example', 'signup_form', $email, .... ['name' => $name]);

  $crm_manager = $container->get('crm.manager');
  $crm_manager->subscribe($name, $email);

  $mailchimp_manager = $container->get('mailchimp.manager');
  $mailchimp_manager->add($name, $email);

  $twitter_manager = $container->get('twitter.manager');
  $tweet = new ThisIsGettingRidiculous();
  $tweet->setMessage('blah blah ' . $name . ' blah blah');
  $twitter_manager->tweet($tweet);
}
</code></pre>
          </section>

          <section>
            <h2>This is bad</h2>
            <ul>
              <li>Form class is doing too many things</li>
              <li>Tightly coupled</li>
              <li>Hard to maintain</li>
              <li>Harder to reuse</li>
            </ul>
          </section>

          <section>
            <h2>Symfony Event Dispatcher</h2>
            <img src="gatwick.jpg" />
            <aside class="notes">
              A component - drupal is more modern and component based.
              Component - a bit of functionality we can use.
              Example of the mediator design pattern.
              Object the encapsulates the communication of other objects.

              Mediator promotes loose coupling by keeping objects from referring to each other explicitly

              Drupal is using ContainerAwareEventDispatcher

              3 step process - listen, notify, execute.
            </aside>
          </section>
        </section>

        <section>
          <section>
            <h2>Dispatching an event</h2>
            <ul>
{'fraction_non_alphanumeric': 0.13370473537604458, 'fraction_numerical': 0.005678165845296765, 'mean_word_length': 2.0171299288946347, 'pattern_counts': {'":': 0, '<': 239, '<?xml version=': 0, '>': 263, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7163691', 'n_tokens_mistral': 2812, 'n_tokens_neox': 2665, 'n_words': 767}