3 namespace Drupal\layout_builder\SectionStorage;
5 use Drupal\Core\Cache\CacheBackendInterface;
6 use Drupal\Core\Extension\ModuleHandlerInterface;
7 use Drupal\Core\Plugin\DefaultPluginManager;
8 use Drupal\layout_builder\Annotation\SectionStorage;
9 use Drupal\layout_builder\SectionStorageInterface;
12 * Provides the Section Storage type plugin manager.
15 * Layout Builder is currently experimental and should only be leveraged by
16 * experimental modules and development releases of contributed modules.
17 * See https://www.drupal.org/core/experimental for more information.
19 class SectionStorageManager extends DefaultPluginManager implements SectionStorageManagerInterface {
22 * Constructs a new SectionStorageManager object.
24 * @param \Traversable $namespaces
25 * An object that implements \Traversable which contains the root paths
26 * keyed by the corresponding namespace to look for plugin implementations.
27 * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
28 * Cache backend instance to use.
29 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
30 * The module handler to invoke the alter hook with.
32 public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
33 parent::__construct('Plugin/SectionStorage', $namespaces, $module_handler, SectionStorageInterface::class, SectionStorage::class);
35 $this->alterInfo('layout_builder_section_storage');
36 $this->setCacheBackend($cache_backend, 'layout_builder_section_storage_plugins');
42 public function loadEmpty($id) {
43 return $this->createInstance($id);
49 public function loadFromStorageId($type, $id) {
50 /** @var \Drupal\layout_builder\SectionStorageInterface $plugin */
51 $plugin = $this->createInstance($type);
52 return $plugin->setSectionList($plugin->getSectionListFromId($id));
58 public function loadFromRoute($type, $value, $definition, $name, array $defaults) {
59 /** @var \Drupal\layout_builder\SectionStorageInterface $plugin */
60 $plugin = $this->createInstance($type);
61 if ($id = $plugin->extractIdFromRoute($value, $definition, $name, $defaults)) {
63 return $plugin->setSectionList($plugin->getSectionListFromId($id));
65 catch (\InvalidArgumentException $e) {
66 // Intentionally empty.