Drupal 8: Plugins 
A visual and technical deep dive. 
! 
Twitter session tag: #d8plugins
Kris Vanderwater 
‣ Developer Evangelist, Acquia! 
‣ Drupal 8: Scotch Initiative Owner! 
‣ Twitter: @eclipsegc! 
‣ Co-Maintainer: Chaos Tools! 
‣ Maintainer: Contextual Administration
Drupal 8 Plugins: Topics 
• What is a Plugin? 
• Why Plugins? 
• Benefits of Plugins 
• Foundational Concepts 
• Implementing Plugins 
• Creating your own Plugin Type
Thank You 
Helior Colorado
What is a Plugin?
What is a Plugin? 
Helior’s Definition: A discreet class that 
executes an operation within the 
context of a given scope, as a means 
to extend Drupal’s functionality. 
! 
! 
! 
! 
!
What is a Plugin? 
Helior’s Definition: A discreet class that 
executes an operation within the 
context of a given scope, as a means 
to extend Drupal’s functionality. 
! 
! 
Kris’ Definition: A discoverable class 
that implements a particular interface 
which adds or extends functionality to 
a pluggable subsystem.
What is a Plugin? 
• Discoverable
What is a Plugin? 
• Discoverable! 
• Object Oriented
What is a Plugin? 
• Discoverable! 
• Object Oriented! 
• Interface Driven
What is a Plugin? 
• Discoverable! 
• Object Oriented! 
• Interface Driven! 
• Swappable
What is a Plugin? 
• Discoverable! 
• Object Oriented! 
• Interface Driven! 
• Swappable! 
• Drupal not required
Why Plugins?
Why Plugins? 
• Drupal actually is kinda unique
Why Plugins? 
• Drupal actually is kinda unique! 
• Unprecedented Configurability
Why Plugins? 
• Drupal actually is kinda unique! 
• Unprecedented Configurability! 
• Absence of similar code
Why Plugins? 
• Drupal actually is kinda unique! 
• Unprecedented Configurability! 
• Absence of similar code! 
• Other CMS don’t expose as much
Why Plugins? 
• Drupal actually is kinda unique! 
• Unprecedented Configurability! 
• Absence of similar code! 
• Other CMS don’t expose as much! 
• Frameworks expect it to be hard coded
Benefits of Plugins:
Benefits of Plugins: 
• Definition & Implementation are co-located
Drupal 7 hook_block_info()
Drupal 7 hook_block_info()
Drupal 7 hook_block_view()
Drupal 7 hook_block_view()
Drupal 8 SystemPoweredByBlock
Benefits of Plugins: 
• Definition & Implementation are co-located! 
• Plugins are Object Oriented
Drupal 7 Block Hooks 
• hook_block_info()! 
• hook_block_info_alter()! 
• hook_block_view()! 
• hook_block_view_alter()! 
• hook_block_view_MODULE_DELTA_alter()! 
• hook_block_configure()! 
• hook_block_save()
Drupal 8 BlockPluginInterface 
• label()! 
• access()! 
• build()! 
• blockForm()! 
• blockValidate()! 
• blockSubmit()! 
• getMachineNameSuggestion()! 
• getVisibilityConditions()! 
• getVisibilityCondition()! 
• setVisibilityConfig()
Methods not implemented by BlockBase 
• label()! 
• access()! 
• build()! 
• blockForm()! 
• blockValidate()! 
• blockSubmit()! 
• getMachineNameSuggestion()! 
• getVisibilityConditions()! 
• getVisibilityCondition()! 
• setVisibilityConfig()
Plugins are Extensible 
• Inherit from base class! 
• Inherit from other plugins
Drupal 8 SystemPoweredByBlock
Benefits of Plugins: 
• Definition & Implementation are co-located! 
• Plugins are Object Oriented! 
• Plugins are Lazy Loaded by default
Drupal 7 Block Hooks 
• hook_block_info()! 
• hook_block_info_alter()! 
• hook_block_view()! 
• hook_block_view_alter()! 
• hook_block_view_MODULE_DELTA_alter()! 
• hook_block_configure()! 
• hook_block_save()
Drupal 8 System Blocks! 
Contents of core/modules/system/src/Plugin/Block 
• SystemBrandingBlock.php! 
• SystemBreadcrumbBlock.php! 
• SystemHelpBlock.php! 
• SystemMainBlock.php! 
• SystemMenuBlock.php! 
• SystemPoweredByBlock.php
Benefits of Plugins: 
• Definition & Implementation are co-located! 
• Plugins are Object Oriented! 
• Plugins are Lazy Loaded by default! 
• Common Pattern (Learn once, use every where)
Drupal 8 Core Plugin Types 
• Actions 
• Archivers 
• Blocks 
• CKEditor 
Plugins 
• Conditions 
• Editors 
• Entity 
Reference 
Selectors 
• Field Types 
• Tool Tips 
• Views Access 
• Views Area 
• Views Argument 
Defaults 
• Views Argument 
Validators 
• Views Cache 
• Views Displays 
• Views Display 
Extenders 
• Views Exposed 
Forms 
• Field Formatters 
• Field Widgets 
• Filters 
• Image Effects 
• Mail 
• Contextual Links 
• Local Actions 
• Local Tasks 
• Quickedit 
Editors 
• Search 
• Views Fields 
• Views Filters 
• Views Joins 
• Views Pagers 
• Views Queries 
• Views 
Relationships 
• Views Rows 
• Views Sorts 
• Views Styles 
• Views Wizards
Foundational Concepts:
Foundational Concepts: 
• Autoloading
Foundational Concepts: 
• Autoloading! 
• PSR-0 & PSR-4
Autoloading Concepts:
Autoloading Concepts: 
PSR-0 
• DrupalCore => “core/lib/Drupal/Core”,! 
• DrupalComponent => “core/lib/Drupal/Component”,
Autoloading Concepts: 
PSR-0 
• DrupalCore => “core/lib/Drupal/Core”,! 
• DrupalComponent => “core/lib/Drupal/Component”, 
PSR-4 
• Drupalblock => “core/modules/block/src”,
Foundational Concepts: 
• Autoloading! 
• PSR-0 & PSR-4! 
• Dependency Injection
Dependency Injection:
Foundational Concepts: 
• Autoloading! 
• PSR-0 & PSR-4! 
• Dependency Injection! 
• Service Containers
Service Containers:
Service Containers:
Service Containers:
Service Containers:
Service Containers:
Service Containers:
Service Containers:
Service Containers:
Service Containers: services.core.yml
Foundational Concepts: 
• Autoloading! 
• PSR-0 & PSR-4! 
• Dependency Injection! 
• Service Containers! 
• Annotations
Annotations: @Block()
Annotations: 
• Annotations are NOT CODE!
Annotations: 
• Annotations are NOT CODE!! 
• yaml, json, {insert_serializer} are NOT CODE!
Annotations: 
• Annotations are NOT CODE!! 
• yaml, json, {insert_serializer} are NOT CODE!! 
• Annotations have more in common serialization.
Annotations: 
• Annotations are NOT CODE!! 
• yaml, json, {insert_serializer} are NOT CODE!! 
• Annotations have more in common serialization.! 
• Data not behavior.
To the Code!

Drupal 8 Deep Dive: Plugin System

  • 1.
    Drupal 8: Plugins A visual and technical deep dive. ! Twitter session tag: #d8plugins
  • 2.
    Kris Vanderwater ‣Developer Evangelist, Acquia! ‣ Drupal 8: Scotch Initiative Owner! ‣ Twitter: @eclipsegc! ‣ Co-Maintainer: Chaos Tools! ‣ Maintainer: Contextual Administration
  • 3.
    Drupal 8 Plugins:Topics • What is a Plugin? • Why Plugins? • Benefits of Plugins • Foundational Concepts • Implementing Plugins • Creating your own Plugin Type
  • 4.
  • 5.
    What is aPlugin?
  • 6.
    What is aPlugin? Helior’s Definition: A discreet class that executes an operation within the context of a given scope, as a means to extend Drupal’s functionality. ! ! ! ! !
  • 7.
    What is aPlugin? Helior’s Definition: A discreet class that executes an operation within the context of a given scope, as a means to extend Drupal’s functionality. ! ! Kris’ Definition: A discoverable class that implements a particular interface which adds or extends functionality to a pluggable subsystem.
  • 8.
    What is aPlugin? • Discoverable
  • 9.
    What is aPlugin? • Discoverable! • Object Oriented
  • 10.
    What is aPlugin? • Discoverable! • Object Oriented! • Interface Driven
  • 11.
    What is aPlugin? • Discoverable! • Object Oriented! • Interface Driven! • Swappable
  • 12.
    What is aPlugin? • Discoverable! • Object Oriented! • Interface Driven! • Swappable! • Drupal not required
  • 13.
  • 14.
    Why Plugins? •Drupal actually is kinda unique
  • 15.
    Why Plugins? •Drupal actually is kinda unique! • Unprecedented Configurability
  • 16.
    Why Plugins? •Drupal actually is kinda unique! • Unprecedented Configurability! • Absence of similar code
  • 17.
    Why Plugins? •Drupal actually is kinda unique! • Unprecedented Configurability! • Absence of similar code! • Other CMS don’t expose as much
  • 18.
    Why Plugins? •Drupal actually is kinda unique! • Unprecedented Configurability! • Absence of similar code! • Other CMS don’t expose as much! • Frameworks expect it to be hard coded
  • 19.
  • 20.
    Benefits of Plugins: • Definition & Implementation are co-located
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
    Benefits of Plugins: • Definition & Implementation are co-located! • Plugins are Object Oriented
  • 27.
    Drupal 7 BlockHooks • hook_block_info()! • hook_block_info_alter()! • hook_block_view()! • hook_block_view_alter()! • hook_block_view_MODULE_DELTA_alter()! • hook_block_configure()! • hook_block_save()
  • 28.
    Drupal 8 BlockPluginInterface • label()! • access()! • build()! • blockForm()! • blockValidate()! • blockSubmit()! • getMachineNameSuggestion()! • getVisibilityConditions()! • getVisibilityCondition()! • setVisibilityConfig()
  • 29.
    Methods not implementedby BlockBase • label()! • access()! • build()! • blockForm()! • blockValidate()! • blockSubmit()! • getMachineNameSuggestion()! • getVisibilityConditions()! • getVisibilityCondition()! • setVisibilityConfig()
  • 30.
    Plugins are Extensible • Inherit from base class! • Inherit from other plugins
  • 31.
  • 33.
    Benefits of Plugins: • Definition & Implementation are co-located! • Plugins are Object Oriented! • Plugins are Lazy Loaded by default
  • 34.
    Drupal 7 BlockHooks • hook_block_info()! • hook_block_info_alter()! • hook_block_view()! • hook_block_view_alter()! • hook_block_view_MODULE_DELTA_alter()! • hook_block_configure()! • hook_block_save()
  • 35.
    Drupal 8 SystemBlocks! Contents of core/modules/system/src/Plugin/Block • SystemBrandingBlock.php! • SystemBreadcrumbBlock.php! • SystemHelpBlock.php! • SystemMainBlock.php! • SystemMenuBlock.php! • SystemPoweredByBlock.php
  • 36.
    Benefits of Plugins: • Definition & Implementation are co-located! • Plugins are Object Oriented! • Plugins are Lazy Loaded by default! • Common Pattern (Learn once, use every where)
  • 37.
    Drupal 8 CorePlugin Types • Actions • Archivers • Blocks • CKEditor Plugins • Conditions • Editors • Entity Reference Selectors • Field Types • Tool Tips • Views Access • Views Area • Views Argument Defaults • Views Argument Validators • Views Cache • Views Displays • Views Display Extenders • Views Exposed Forms • Field Formatters • Field Widgets • Filters • Image Effects • Mail • Contextual Links • Local Actions • Local Tasks • Quickedit Editors • Search • Views Fields • Views Filters • Views Joins • Views Pagers • Views Queries • Views Relationships • Views Rows • Views Sorts • Views Styles • Views Wizards
  • 38.
  • 39.
  • 40.
    Foundational Concepts: •Autoloading! • PSR-0 & PSR-4
  • 41.
  • 42.
    Autoloading Concepts: PSR-0 • DrupalCore => “core/lib/Drupal/Core”,! • DrupalComponent => “core/lib/Drupal/Component”,
  • 43.
    Autoloading Concepts: PSR-0 • DrupalCore => “core/lib/Drupal/Core”,! • DrupalComponent => “core/lib/Drupal/Component”, PSR-4 • Drupalblock => “core/modules/block/src”,
  • 44.
    Foundational Concepts: •Autoloading! • PSR-0 & PSR-4! • Dependency Injection
  • 45.
  • 46.
    Foundational Concepts: •Autoloading! • PSR-0 & PSR-4! • Dependency Injection! • Service Containers
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
    Foundational Concepts: •Autoloading! • PSR-0 & PSR-4! • Dependency Injection! • Service Containers! • Annotations
  • 57.
  • 62.
  • 63.
    Annotations: • Annotationsare NOT CODE!! • yaml, json, {insert_serializer} are NOT CODE!
  • 64.
    Annotations: • Annotationsare NOT CODE!! • yaml, json, {insert_serializer} are NOT CODE!! • Annotations have more in common serialization.
  • 65.
    Annotations: • Annotationsare NOT CODE!! • yaml, json, {insert_serializer} are NOT CODE!! • Annotations have more in common serialization.! • Data not behavior.
  • 66.