Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / pathauto / src / AliasTypeManager.php
1 <?php
2
3 namespace Drupal\pathauto;
4
5 use Drupal\Core\Cache\CacheBackendInterface;
6 use Drupal\Core\Extension\ModuleHandlerInterface;
7 use Drupal\Core\Plugin\DefaultPluginManager;
8 use Drupal\Component\Plugin\FallbackPluginManagerInterface;
9
10 /**
11  * Manages pathauto alias type plugins.
12  */
13 class AliasTypeManager extends DefaultPluginManager implements FallbackPluginManagerInterface {
14
15   /**
16    * Constructs a new AliasType manager instance.
17    *
18    * @param \Traversable $namespaces
19    *   An object that implements \Traversable which contains the root paths
20    *   keyed by the corresponding namespace to look for plugin implementations.
21    * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
22    *   Cache backend instance to use.
23    * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
24    *   The module handler to invoke the alter hook with.
25    */
26   public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
27     parent::__construct('Plugin/pathauto/AliasType', $namespaces, $module_handler, 'Drupal\pathauto\AliasTypeInterface', 'Drupal\pathauto\Annotation\AliasType');
28     $this->alterInfo('pathauto_alias_types');
29     $this->setCacheBackend($cache_backend, 'pathauto_alias_types');
30   }
31
32   /**
33    * Returns plugin definitions that support a given token type.
34    *
35    * @param string $type
36    *   The type of token plugin must support to be useful.
37    *
38    * @return array
39    *   Plugin definitions.
40    */
41   public function getPluginDefinitionByType($type) {
42     $definitions = array_filter($this->getDefinitions(), function ($definition) use ($type) {
43       if (!empty($definition['types']) && in_array($type, $definition['types'])) {
44         return TRUE;
45       }
46       return FALSE;
47     });
48     return $definitions;
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   public function getFallbackPluginId($plugin_id, array $configuration = array()) {
55     return 'broken';
56   }
57
58   /**
59    * Gets the definition of all visible plugins for this type.
60    *
61    * @return array
62    *   An array of plugin definitions (empty array if no definitions were
63    *   found). Keys are plugin IDs.
64    */
65   public function getVisibleDefinitions() {
66     $definitions = $this->getDefinitions();
67     unset($definitions['broken']);
68     return $definitions;
69   }
70
71 }