Drupal 8 plugin wonderland

Janez Urevc / @slashrsm / http://janezurevc.name

About me...

You take the blue pill, the story ends, you wake up in your bed and believe whatever you want to believe. You take the red pill, you stay in Wonderland, and I show you how deep the rabbit hole goes.

Plugins?

hook_X_info() replacement

Why plugins?

Object oriented

Replacement logic

Memory footprint

All about discovery

hook_X_info()

Old fashioned way! :)

Variable discovery

settings.php, baby!

Annotations

So what is this thing with annotations?

Annotations ⊂ Comments

Wait, comments do matter? WTF?!?!

Provides info about plugin

Replaces hook_X_info()

Doctrine

I want to see some examples!

Drupal/tour/Plugin/tour/tip/TipPluginText.php

              
/**
 * Displays some text as a tip.
 *
 * @Tip(
 *   id = "text",
 *   title = @Translation("Text")
 * )
 */
class TipPluginText ...
              
            

Drupal/system/Plugin/Block/SystemPoweredByBlock.php

              
/**
 * Provides a 'Powered by Drupal' block.
 *
 * @Plugin(
 *   id = "system_powered_by_block",
 *   admin_label = @Translation("Powered by Drupal"),
 *   module = "system"
 * )
 */
class SystemPoweredByBlock ...
              
            

Drupal/filter/Plugin/Filter/FilterUrl.php

              
/**
 * Provides a filter to convert URLs into links.
 *
 * @Filter(
 *   id = "filter_url",
 *   module = "filter",
 *   title = @Translation("Convert URLs into links"),
 *   type = FILTER_TYPE_MARKUP_LANGUAGE,
 *   settings = {
 *     "filter_url_length" = 72
 *   }
 * )
 */
class FilterUrl ...
              
            

Gimme some code!

Unfortunately, no one can be told what The Matrix is. You have to see it for yourself.

Let's port very simple block from D7 to D8. Meet Pants module!

Feels good? Want more?

Tip/Tour

Archiver

Filter

  • https://drupal.org/node/1637614
  • http://previousnext.com.au/blog/understanding-drupal-8s-plugin-system
  • https://portland2013.drupal.org/session/drupal-8-plugin-system-deep-dive

Let's discuss!

Janez Urevc / @slashrsm / http://janezurevc.name