Version 1
[yaffs-website] / web / core / lib / Drupal / Core / Http / LinkRelationTypeManager.php
1 <?php
2
3 namespace Drupal\Core\Http;
4
5 use Drupal\Core\Cache\CacheBackendInterface;
6 use Drupal\Core\Extension\Extension;
7 use Drupal\Core\Extension\ModuleHandlerInterface;
8 use Drupal\Core\Plugin\DefaultPluginManager;
9 use Drupal\Core\Plugin\Discovery\YamlDiscovery;
10
11 /**
12  * Provides a default plugin manager for link relation types.
13  *
14  * @see \Drupal\Core\Http\LinkRelationTypeInterface
15  */
16 class LinkRelationTypeManager extends DefaultPluginManager {
17
18   /**
19    * {@inheritdoc}
20    */
21   protected $defaults = [
22     'class' => LinkRelationType::class,
23   ];
24
25   /**
26    * The app root.
27    *
28    * @var string
29    */
30   protected $root;
31
32   /**
33    * Constructs a new LinkRelationTypeManager.
34    *
35    * @param string $root
36    *   The app root.
37    * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
38    *   The module handler.
39    * @param \Drupal\Core\Cache\CacheBackendInterface $cache
40    *   The cache backend.
41    */
42   public function __construct($root, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache) {
43     $this->root = $root;
44     $this->pluginInterface = LinkRelationTypeInterface::class;
45     $this->moduleHandler = $module_handler;
46     $this->setCacheBackend($cache, 'link_relation_type_plugins', ['link_relation_type']);
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   protected function getDiscovery() {
53     if (!$this->discovery) {
54       $directories = ['core' => $this->root . '/core'];
55       $directories += array_map(function (Extension $extension) {
56         return $this->root . '/' . $extension->getPath();
57       }, $this->moduleHandler->getModuleList());
58       $this->discovery = new YamlDiscovery('link_relation_types', $directories);
59     }
60     return $this->discovery;
61   }
62
63 }