Transcript
Page 1: Drupal 8 Deep Dive: Plugin System

Drupal 8: PluginsA visual and technical deep dive.

!Twitter session tag: #d8plugins

Page 2: Drupal 8 Deep Dive: Plugin System

Kris Vanderwater‣ Developer Evangelist, Acquia!‣ Drupal 8: Scotch Initiative Owner!‣ Twitter: @eclipsegc!‣ Co-Maintainer: Chaos Tools!‣ Maintainer: Contextual Administration

Page 3: Drupal 8 Deep Dive: Plugin System

Drupal 8 Plugins: Topics

• What is a Plugin?

• Why Plugins?

• Benefits of Plugins

• Foundational Concepts

• Implementing Plugins

• Creating your own Plugin Type

Page 4: Drupal 8 Deep Dive: Plugin System

Thank YouHelior Colorado

Page 5: Drupal 8 Deep Dive: Plugin System

What is a Plugin?

Page 6: Drupal 8 Deep Dive: Plugin System

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. !!!!!

Page 7: Drupal 8 Deep Dive: Plugin System

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.

Page 8: Drupal 8 Deep Dive: Plugin System

What is a Plugin?

• Discoverable

Page 9: Drupal 8 Deep Dive: Plugin System

What is a Plugin?

• Discoverable!• Object Oriented

Page 10: Drupal 8 Deep Dive: Plugin System

What is a Plugin?

• Discoverable!• Object Oriented!• Interface Driven

Page 11: Drupal 8 Deep Dive: Plugin System

What is a Plugin?

• Discoverable!• Object Oriented!• Interface Driven!• Swappable

Page 12: Drupal 8 Deep Dive: Plugin System

What is a Plugin?

• Discoverable!• Object Oriented!• Interface Driven!• Swappable!• Drupal not required

Page 13: Drupal 8 Deep Dive: Plugin System

Why Plugins?

Page 14: Drupal 8 Deep Dive: Plugin System

Why Plugins?

• Drupal actually is kinda unique

Page 15: Drupal 8 Deep Dive: Plugin System

Why Plugins?

• Drupal actually is kinda unique!• Unprecedented Configurability

Page 16: Drupal 8 Deep Dive: Plugin System

Why Plugins?

• Drupal actually is kinda unique!• Unprecedented Configurability!• Absence of similar code

Page 17: Drupal 8 Deep Dive: Plugin System

Why Plugins?

• Drupal actually is kinda unique!• Unprecedented Configurability!• Absence of similar code!• Other CMS don’t expose as much

Page 18: Drupal 8 Deep Dive: Plugin System

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

Page 19: Drupal 8 Deep Dive: Plugin System

Benefits of Plugins:

Page 20: Drupal 8 Deep Dive: Plugin System

Benefits of Plugins:

• Definition & Implementation are co-located

Page 21: Drupal 8 Deep Dive: Plugin System

Drupal 7 hook_block_info()

Page 22: Drupal 8 Deep Dive: Plugin System

Drupal 7 hook_block_info()

Page 23: Drupal 8 Deep Dive: Plugin System

Drupal 7 hook_block_view()

Page 24: Drupal 8 Deep Dive: Plugin System

Drupal 7 hook_block_view()

Page 25: Drupal 8 Deep Dive: Plugin System

Drupal 8 SystemPoweredByBlock

Page 26: Drupal 8 Deep Dive: Plugin System

Benefits of Plugins:

• Definition & Implementation are co-located!• Plugins are Object Oriented

Page 27: Drupal 8 Deep Dive: Plugin System

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

Page 28: Drupal 8 Deep Dive: Plugin System

Drupal 8 BlockPluginInterface

• label()!• access()!• build()!• blockForm()!• blockValidate()!• blockSubmit()!• getMachineNameSuggestion()!• getVisibilityConditions()!• getVisibilityCondition()!• setVisibilityConfig()

Page 29: Drupal 8 Deep Dive: Plugin System

Methods not implemented by BlockBase

• label()!• access()!• build()!• blockForm()!• blockValidate()!• blockSubmit()!• getMachineNameSuggestion()!• getVisibilityConditions()!• getVisibilityCondition()!• setVisibilityConfig()

Page 30: Drupal 8 Deep Dive: Plugin System

Plugins are Extensible

• Inherit from base class!• Inherit from other plugins

Page 31: Drupal 8 Deep Dive: Plugin System

Drupal 8 SystemPoweredByBlock

Page 32: Drupal 8 Deep Dive: Plugin System
Page 33: Drupal 8 Deep Dive: Plugin System

Benefits of Plugins:

• Definition & Implementation are co-located!• Plugins are Object Oriented!• Plugins are Lazy Loaded by default

Page 34: Drupal 8 Deep Dive: Plugin System

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

Page 35: Drupal 8 Deep Dive: Plugin System

Drupal 8 System Blocks!Contents of core/modules/system/src/Plugin/Block

• SystemBrandingBlock.php!• SystemBreadcrumbBlock.php!• SystemHelpBlock.php!• SystemMainBlock.php!• SystemMenuBlock.php!• SystemPoweredByBlock.php

Page 36: Drupal 8 Deep Dive: Plugin System

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)

Page 37: Drupal 8 Deep Dive: Plugin System

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

Page 38: Drupal 8 Deep Dive: Plugin System

Foundational Concepts:

Page 39: Drupal 8 Deep Dive: Plugin System

Foundational Concepts:

• Autoloading

Page 40: Drupal 8 Deep Dive: Plugin System

Foundational Concepts:

• Autoloading!• PSR-0 & PSR-4

Page 41: Drupal 8 Deep Dive: Plugin System

Autoloading Concepts:

Page 42: Drupal 8 Deep Dive: Plugin System

Autoloading Concepts:

• \Drupal\Core => “core/lib/Drupal/Core”,!• \Drupal\Component => “core/lib/Drupal/Component”,

PSR-0

Page 43: Drupal 8 Deep Dive: Plugin System

Autoloading Concepts:

• \Drupal\Core => “core/lib/Drupal/Core”,!• \Drupal\Component => “core/lib/Drupal/Component”,

PSR-0

• \Drupal\block => “core/modules/block/src”,

PSR-4

Page 44: Drupal 8 Deep Dive: Plugin System

Foundational Concepts:

• Autoloading!• PSR-0 & PSR-4!

• Dependency Injection

Page 45: Drupal 8 Deep Dive: Plugin System

Dependency Injection:

Page 46: Drupal 8 Deep Dive: Plugin System

Foundational Concepts:

• Autoloading!• PSR-0 & PSR-4!

• Dependency Injection!• Service Containers

Page 47: Drupal 8 Deep Dive: Plugin System

Service Containers:

Page 48: Drupal 8 Deep Dive: Plugin System

Service Containers:

Page 49: Drupal 8 Deep Dive: Plugin System

Service Containers:

Page 50: Drupal 8 Deep Dive: Plugin System

Service Containers:

Page 51: Drupal 8 Deep Dive: Plugin System

Service Containers:

Page 52: Drupal 8 Deep Dive: Plugin System

Service Containers:

Page 53: Drupal 8 Deep Dive: Plugin System

Service Containers:

Page 54: Drupal 8 Deep Dive: Plugin System

Service Containers:

Page 55: Drupal 8 Deep Dive: Plugin System

Service Containers: services.core.yml

Page 56: Drupal 8 Deep Dive: Plugin System

Foundational Concepts:

• Autoloading!• PSR-0 & PSR-4!

• Dependency Injection!• Service Containers!• Annotations

Page 57: Drupal 8 Deep Dive: Plugin System

Annotations: @Block()

Page 58: Drupal 8 Deep Dive: Plugin System
Page 59: Drupal 8 Deep Dive: Plugin System
Page 60: Drupal 8 Deep Dive: Plugin System
Page 61: Drupal 8 Deep Dive: Plugin System
Page 62: Drupal 8 Deep Dive: Plugin System

Annotations:

• Annotations are NOT CODE!

Page 63: Drupal 8 Deep Dive: Plugin System

Annotations:

• Annotations are NOT CODE!!• yaml, json, {insert_serializer} are NOT CODE!

Page 64: Drupal 8 Deep Dive: Plugin System

Annotations:

• Annotations are NOT CODE!!• yaml, json, {insert_serializer} are NOT CODE!!• Annotations have more in common serialization.

Page 65: Drupal 8 Deep Dive: Plugin System

Annotations:

• Annotations are NOT CODE!!• yaml, json, {insert_serializer} are NOT CODE!!• Annotations have more in common serialization.!• Data not behavior.

Page 66: Drupal 8 Deep Dive: Plugin System

To the Code!


Recommended