Drupal 8 plugin wonderland – About me... – Why plugins?



Drupal 8 plugin wonderland – About me... – Why plugins?

0 0


d8_plugins_session

My session about Drupal 8 plugins. Presentet at Drupalaton 2013 (drupalaton.hu).

On Github slashrsm / d8_plugins_session

Drupal 8 plugin wonderland

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

About me...

Notes.
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()

- parses file and stores info about all plugins - caches - files go from memory after parse - not true if you include .php

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