blob: f09490c21f1173c6062904e5eb1b1a169f790d66 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
<?php
declare(strict_types=1);
namespace Drupal\navigation;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\navigation\Attribute\TopBarItem;
/**
* Top bar item plugin manager.
*/
final class TopBarItemManager extends DefaultPluginManager implements TopBarItemManagerInterface {
/**
* Constructs the object.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/TopBarItem', $namespaces, $module_handler, TopBarItemPluginInterface::class, TopBarItem::class);
$this->alterInfo('top_bar_item');
$this->setCacheBackend($cache_backend, 'top_bar_item_plugins');
}
/**
* {@inheritdoc}
*/
public function getDefinitionsByRegion(TopBarRegion $region): array {
return array_filter($this->getDefinitions(), fn (array $definition) => $definition['region'] === $region);
}
/**
* {@inheritdoc}
*/
public function getRenderedTopBarItemsByRegion(TopBarRegion $region): array {
$instances = [];
foreach ($this->getDefinitionsByRegion($region) as $plugin_id => $plugin_definition) {
$instances[$plugin_id] = $this->createInstance($plugin_id)->build();
}
return $instances;
}
}
|