plugin types

D8 Plugin types (plugin managers)

The plugin manager is the central controlling class that defines how the plugins of a particular type will be discovered and instantiated. This class is called directly in any module wishing to invoke a plugin type.

This documentation will require an understanding of PSR-0.

Defining the Plugin Manager

There are only two requirements for defining a new plugin manager:

  1. You must define a discovery method.
  2. You must define a factory.

Everything else within the plugin system is situational and based upon your use case. For this plugin type, we will use the hook discovery and the default factory.

<?php
namespace Drupal\components\Plugin\Manager;

use
Drupal\Component\Plugin\PluginManagerBase;
use
Drupal\Core\Plugin\Discovery\HookDiscovery;
use
Drupal\Component\Plugin\Factory\DefaultFactory;

/**
* Defines the plugin manager for Components plugins.
*/
class ComponentsPluginManagerBase extends PluginManagerBase {

 
/**
   * Constructs a new Components plugin manager object.
  */
 
public function __construct() {
   
$this->discovery = new HookDiscovery('component_info');
   
$this->factory = new DefaultFactory($this);
  }
}
?>
Read more
Subscribe with RSS Syndicate content
nobody click here