Paragraphs Editor
PluginFactory.php
Go to the documentation of this file.
1 <?php
2 
4 
6 
7 /**
8  * A generic plugin factory for creating paragraphs editor plugins.
9  *
10  * This is basically copied from the core ContainerFactory implementation, but
11  * also injects command context into the 'create' factory callback.
12  */
13 class PluginFactory extends DefaultFactory {
14 
15  /**
16  * {@inheritdoc}
17  */
18  public function createInstance($plugin_id, array $configuration = []) {
19  $plugin_definition = $this->discovery->getDefinition($plugin_id);
20  $plugin_class = static::getPluginClass($plugin_id, $plugin_definition, $this->interface);
21 
22  // If the plugin provides a factory method, pass the container to it.
23  if (is_subclass_of($plugin_class, 'Drupal\Core\Plugin\ContainerFactoryPluginInterface')) {
24  return $plugin_class::create(\Drupal::getContainer(), $configuration, $plugin_id, $plugin_definition);
25  }
26 
27  // Otherwise, create the plugin directly.
28  return new $plugin_class($plugin_id, $plugin_definition, $configuration['context']);
29  }
30 
31 }