EmbedTypeManager::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 3
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\embed\EmbedType;
4
5
use Drupal\Core\Cache\CacheBackendInterface;
6
use Drupal\Core\Extension\ModuleHandlerInterface;
7
use Drupal\Core\Plugin\DefaultPluginManager;
8
9
/**
10
 * Provides an Embed type plugin manager.
11
 *
12
 * @see \Drupal\embed\Annotation\EmbedType
13
 * @see \Drupal\embed\EmbedType\EmbedTypeInterface
14
 * @see hook_embed_type_plugins_alter()
15
 */
16
class EmbedTypeManager extends DefaultPluginManager {
17
18
  /**
19
   * Constructs a EmbedTypeManager object.
20
   *
21
   * @param \Traversable $namespaces
22
   *   An object that implements \Traversable which contains the root paths
23
   *   keyed by the corresponding namespace to look for plugin implementations.
24
   * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
25
   *   Cache backend instance to use.
26
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
27
   *   The module handler to invoke the alter hook with.
28
   */
29
  public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
30
    parent::__construct('Plugin/EmbedType', $namespaces, $module_handler, 'Drupal\embed\EmbedType\EmbedTypeInterface', 'Drupal\embed\Annotation\EmbedType');
31
    $this->alterInfo('embed_type_plugins');
32
    $this->setCacheBackend($cache_backend, 'embed_type_plugins');
33
  }
34
35
  /**
36
   * Provides a list of plugins suitable for form options.
37
   *
38
   * @return array
39
   *   An array of valid plugin labels, keyed by plugin ID.
40
   */
41
  public function getDefinitionOptions() {
42
    $options = array_map(function ($definition) {
43
      return (string) $definition['label'];
44
    }, $this->getDefinitions());
45
    natsort($options);
46
    return $options;
47
  }
48
49
}
50