3 namespace Drupal\Core\Http;
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;
12 * Provides a default plugin manager for link relation types.
14 * @see \Drupal\Core\Http\LinkRelationTypeInterface
16 class LinkRelationTypeManager extends DefaultPluginManager {
21 protected $defaults = [
22 'class' => LinkRelationType::class,
33 * Constructs a new LinkRelationTypeManager.
37 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
39 * @param \Drupal\Core\Cache\CacheBackendInterface $cache
42 public function __construct($root, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache) {
44 $this->pluginInterface = LinkRelationTypeInterface::class;
45 $this->moduleHandler = $module_handler;
46 $this->setCacheBackend($cache, 'link_relation_type_plugins', ['link_relation_type']);
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);
60 return $this->discovery;