The Drupal 8 plugin system: extensibility for all – Jargon, do you speak it? – There's a module for that



The Drupal 8 plugin system: extensibility for all – Jargon, do you speak it? – There's a module for that

0 0


presentation_drupal_plugin_system


On Github bartfeenstra / presentation_drupal_plugin_system

The Drupal 8 plugin system: extensibility for all

I am Xano, @BartFeenstra, and http://mynameisbart.com.

What are plugins?

  • Swappable extensions that provide logic for a specific (set of) task(s)
  • Uniquely identifiable
  • Metadata
  • Multiple instances can co-exist (reuse)

Drupal 7 plugins

  • Hook discovery (core and most contributed modules)
  • File-based discovery (ctools)
  • Magic hooks/callbacks/includes
  • Some plugins are classed

Say what?

Drupal 8 plugins

  • Are classed. Always.
  • Should implement interfaces.
  • Consistent API for discovering and instantiating plugins, regardless of type.

No more dark magic

Jargon, do you speak it?

Plugin type

Plugin (definition)

Plugin discovery

Plugin factory

Plugin manager (discovery + factory + ...)

Plugin instance

Plugin configuration

Recreating/cloning plugin instances

Using Plugin type/manager, ID, and configuration through ConfigurablePluginInterface.

Discovery methods

  • Annotated class discovery (mostly different logic)
  • YAML discovery (mostly reused logic)
  • Static discovery (testing)
  • Hook discovery (deprecated)

Annotated class discovery

                        
<?php
/**
 * The plugin that handles Data response callbacks for REST resources.
 *
 * @ingroup views_display_plugins
 *
 * @ViewsDisplay(
 *   id = "rest_export",
 *   title = @Translation("REST export"),
 *   help = @Translation("Create a REST export resource."),
 *   uses_route = TRUE,
 *   admin = @Translation("REST export"),
 *   returns_response = TRUE
 * )
 */
class RestExport extends PathPluginBase implements ResponseDisplayPluginInterface {
    // Class contents here...
}
?>
                    
                    

YAML discovery

                        
system.admin:
  title: Administration
  route_name: system.admin
  weight: 9
  menu_name: admin
system.admin_content:
  title: Content
  description: 'Find and manage content.'
  route_name: system.admin_content
  parent: system.admin
  weight: -10
system.admin_structure:
  route_name: system.admin_structure
  parent: system.admin
  description: 'Administer blocks, content types, menus, etc.'
  title: Structure
  weight: -8
                    
                    

Forms

Derivatives

One base plugin definition can be dynamically expanded into multiple derivative plugin definitions.

There's a module for that

http://drupal.org/project/plugin

Plugin type discovery

Administrative overview

Configuration schemas

plugin.plugin_configuration.*.*

Typed plugin definition API

PluginDefinitionInterface

Plugin selectors

Field types/widgets/formatters

Conclusion

Extending Drupal has never been easier.

Review this presentation at http://slideshare.net/bartfeenstra.

Find the Plugin module at http://drupal.org/project/plugin.

I am Xano, @BartFeenstra, and http://mynameisbart.com.

Do you have any questions?

The Drupal 8 plugin system: extensibility for all I am Xano, @BartFeenstra, and http://mynameisbart.com.