PluginManager   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
dl 0
loc 39
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPluginTypeInfo() 0 16 3
A __construct() 0 6 1
1
<?php
2
3
namespace Drupal\paragraphs_editor\Plugin\ParagraphsEditor;
4
5
use Drupal\Core\Cache\CacheBackendInterface;
6
use Drupal\Core\Extension\ModuleHandlerInterface;
7
use Drupal\Core\Plugin\DefaultPluginManager;
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 1
  public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
18 1
    list ($plugin_interface, $annotation) = $this->getPluginTypeInfo($type);
19 1
    parent::__construct("Plugin/ParagraphsEditor/$type", $namespaces, $module_handler, $plugin_interface, $annotation);
20 1
    $this->alterInfo("paragraphs_editor_{$type}_info");
21 1
    $this->setCacheBackend($cache_backend, "paragraphs_editor_{$type}_info_plugins");
22 1
    $this->factory = new PluginFactory($this->getDiscovery());
23 1
  }
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 1
  protected function getPluginTypeInfo($type) {
36
    switch ($type) {
37 1
      case 'delivery_provider':
38
        return [
39 1
          'Drupal\paragraphs_editor\Plugin\ParagraphsEditor\DeliveryProviderInterface',
40
          'Drupal\paragraphs_editor\Annotation\ParagraphsEditorDeliveryProvider',
41
        ];
42
43 1
      case 'bundle_selector':
44
        return [
45 1
          '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
}
55