LinkRelationTypeManager.php 1.7 KB

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