Discovery Decorators
A discovery decorator is a class which wraps another discovery mechanism in order to provide additional functionality. Discovery decorators conform to the same interfaces as regular discovery classes, but they are intended to be used in tandem with another discovery class. Discovery decorators should take a DiscoveryInterface typed variable in their __construct method and any other parameters that are necessary to make them work. There are two included discovery decorators in core, we'll look at the CacheDecorator first.
Drupal\Core\Plugin\Discovery\CacheDecorator
We'll discuss the various methods that exist here and what they do.
public function __construct(DiscoveryInterface $decorated, $cache_key = NULL);
As mentioned above, this function takes a DiscoveryInterface compatible variable called $decorated. This could be any of the previously discussed discovery classes. In addition to this it takes a $cache_key which will be used when making cache()->get() calls.
public function getPluginDefinition($plugin_id);
Read moreD8 Plugin discovery
Plugin discovery is the process by which Drupal finds plugins of a given type. A discovery method must be set for every plugin type (explained in the plugin manager documentation).
The discovery component of plugins implements a DiscoveryInterface that defines the methods any discovery class must have.
<?php
/**
* @file
* Contains \Drupal\Component\Plugin\Discovery\DiscoveryInterface.
*/
namespace Drupal\Component\Plugin\Discovery;
/**
* Defines the plugin discovery interface.
*/
interface DiscoveryInterface {
/**
* Gets a specific plugin definition.
*
* @param string $plugin_id
* A plugin id.
*
* @return array
* A plugin definition.
*/
public function getPluginDefinition($plugin_id);
/**
* Gets the definition of all plugins for this type.
*
* @return array
* An array of configuration definitions.
*/
public function getPluginDefinitions();
}
?>There are three different core discovery types.
- StaticDiscovery