Paragraphs Editor
PluginManager.php
Go to the documentation of this file.
1 <?php
2 
4 
8 
9 /**
10  * Provides a common plugin manager for all paragraphs_editor plugins.
11  */
12 class PluginManager extends DefaultPluginManager {
13 
14  /**
15  * {@inheritdoc}
16  */
17  public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
18  list ($plugin_interface, $annotation) = $this->getPluginTypeInfo($type);
19  parent::__construct("Plugin/ParagraphsEditor/$type", $namespaces, $module_handler, $plugin_interface, $annotation);
20  $this->alterInfo("paragraphs_editor_{$type}_info");
21  $this->setCacheBackend($cache_backend, "paragraphs_editor_{$type}_info_plugins");
22  $this->factory = new PluginFactory($this->getDiscovery());
23  }
24 
25  /**
26  * Helper method to map plugin types to interfaces / annotations.
27  *
28  * @param string $type
29  * The paragraphs_editor plugin type.
30  *
31  * @return array
32  * A tuple where the first element is the fully qualified interface name and
33  * the second element is the fully qualified annotation name.
34  */
35  protected function getPluginTypeInfo($type) {
36  switch ($type) {
37  case 'delivery_provider':
38  return [
39  'Drupal\paragraphs_editor\Plugin\ParagraphsEditor\DeliveryProviderInterface',
40  'Drupal\paragraphs_editor\Annotation\ParagraphsEditorDeliveryProvider',
41  ];
42 
43  case 'bundle_selector':
44  return [
45  'Drupal\paragraphs_editor\Plugin\ParagraphsEditor\BundleSelectorInterface',
46  'Drupal\paragraphs_editor\Annotation\ParagraphsEditorBundleSelector',
47  ];
48 
49  default:
50  throw new \Exception("Invalid plugin type '$type'");
51  }
52  }
53 
54 }
__construct($type,\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler)