drupal 8 deep dive: plugin system
DESCRIPTION
Want to learn more about Acquia’s products, services, and happenings in the Drupal Community? Visit our site: http://bit.ly/yLaHO5. Drupal 8 has introduced a number of new (to Drupalists) technologies, but embedded in this mix are a handful of Drupal-centric innovations. Amongst the first of these to be introduced to Drupal 8 was the Plug-in system. The Plug-in system is a far reaching PHP Component that has largely replaced the old hook_info/alter pattern within Drupal and can be used outside of Drupal as well. In this webinar, Kris Vanderwater (You may know him as EclipseGc) will review: • Examples of what appropriate plug-in system usages look like • What plug-in tools exist and how to leverage them • Where to get information on building your own plug-in types • How to use the existing helper classes in Drupal for the greatest impact We will compare and contrast how Drupal 7 versus Drupal 8 works for plugin converted subsystems to frame the discussion around when and why to build a conversion. In addition to this we will dig into the tools and classes Drupal provides out of the box, and dissect a simple example plug-in type that you can use to build your own plug-ins types and better understand the plug-in system. Experience level: AdvancedTRANSCRIPT
Drupal 8: PluginsA 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 YouHelior 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
• 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:
• \Drupal\Core => “core/lib/Drupal/Core”,!• \Drupal\Component => “core/lib/Drupal/Component”,
PSR-0
Autoloading Concepts:
• \Drupal\Core => “core/lib/Drupal/Core”,!• \Drupal\Component => “core/lib/Drupal/Component”,
PSR-0
• \Drupal\block => “core/modules/block/src”,
PSR-4
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!