Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

Documentation: Plugin API in Drupal 8

Motivation

This change is important for contrib to be able to provide plugins for optional core modules such as views.

Description of the change

Before if a module such as Views wants to implement a hook like hook_views_data on the behalf of another module such as Comment, it can do so easily. All functions (comment_views_data) are in the global namespace and for PHP it doesn't matter which file a certain function is defined in. If the second module (Comment) isn't enabled then Drupal won't even look for this function, it only invokes the implementations of enabled modules.

The situation for plugins is very different: plugins are in a prescribed namespace (Drupal\modulename\PluginNamespaceDefinedByThePluginType) and every plugin in that namespace is made available. If a plugin depends on the APIs (or the data structures -- but try to avoid sidestepping APIs if possible) of another module then the plugin should not be made available if the dependency is not met.

The dependency is defined by adding provider = modulename to the plugin annotation. At this moment it is not possible to specify more than one module as dependency. Also the current implementation does not support (yet?) the provider to be a theme.

/**
 * @Plugin(
 *   id = "pluginId",
 *   type = { "entity" }
 *   provider = "module_name"
 * )
 */

API changes

Plugins whose 'provider' is a disabled module will not be available

The following method signatures have changed:

DefaultPluginManager::__construct() now has the module handler injected
DefaultPluginManager::alterInfo() no longer requires the module handler

Releated change notices

DefaultPluginManager class added to simplify plugin managers
Streamlining Plugin Annotation Class Loading

Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done