class NavigationSectionStorage
Same name and namespace in other branches
- 11.x core/modules/navigation/src/Plugin/SectionStorage/NavigationSectionStorage.php \Drupal\navigation\Plugin\SectionStorage\NavigationSectionStorage
Provides navigation section storage.
@internal The navigation module is experimental.
Attributes
#[SectionStorage(id: "navigation", context_definitions: [
"navigation" => new ContextDefinition(data_type: "string", label: new TranslatableMarkup("Navigation flag")),
], handles_permission_check: TRUE)]
Hierarchy
- class \Drupal\Component\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait implements \Drupal\Component\Plugin\PluginBase
- class \Drupal\navigation\Plugin\SectionStorage\NavigationSectionStorage extends \Drupal\layout_builder\SectionStorageInterface, \Drupal\layout_builder\Plugin\SectionStorage\SectionStorageLocalTaskProviderInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\Core\Cache\CacheableDependencyInterface uses \Drupal\Core\Plugin\ContextAwarePluginTrait, \Drupal\layout_builder\Routing\LayoutBuilderRoutesTrait, \Drupal\layout_builder\SectionListTrait implements \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait implements \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of NavigationSectionStorage
2 files declare their use of NavigationSectionStorage
- navigation.module in core/
modules/ navigation/ navigation.module - Primary module hooks for navigation module.
- RenderCallbacks.php in core/
modules/ navigation/ src/ RenderCallbacks.php
File
-
core/
modules/ navigation/ src/ Plugin/ SectionStorage/ NavigationSectionStorage.php, line 33
Namespace
Drupal\navigation\Plugin\SectionStorageView source
final class NavigationSectionStorage extends PluginBase implements SectionStorageInterface, SectionStorageLocalTaskProviderInterface, ContainerFactoryPluginInterface, CacheableDependencyInterface {
const STORAGE_ID = 'navigation.block_layout';
use ContextAwarePluginTrait;
use LayoutBuilderRoutesTrait;
use SectionListTrait;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected ConfigFactoryInterface $configFactory;
/**
* An array of sections.
*
* @var \Drupal\layout_builder\Section[]|null
*/
protected $sections;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) : static {
return new static($configuration, $plugin_id, $plugin_definition, $container->get('config.factory'));
}
/**
* {@inheritdoc}
*/
public function getStorageType() : string {
return $this->getPluginId();
}
/**
* {@inheritdoc}
*/
public function getStorageId() : string {
return self::STORAGE_ID;
}
/**
* {@inheritdoc}
*/
public function label() : string {
return 'Navigation layout';
}
/**
* Returns the name to be used to store in the config system.
*/
protected function getConfigName() : string {
return self::STORAGE_ID;
}
/**
* {@inheritdoc}
*/
public function getSections() : array {
if (is_null($this->sections)) {
$sections = $this->configFactory
->get($this->getConfigName())
->get('sections') ?: [];
$this->setSections(array_map([
Section::class,
'fromArray',
], $sections));
}
return $this->sections;
}
/**
* {@inheritdoc}
*/
protected function setSections(array $sections) : static {
$this->sections = array_values($sections);
return $this;
}
/**
* {@inheritdoc}
*/
public function save() : int {
$sections = array_map(function (Section $section) {
return $section->toArray();
}, $this->getSections());
$config = $this->configFactory
->getEditable($this->getConfigName());
$return = $config->get('sections') ? SAVED_UPDATED : SAVED_NEW;
$config->set('sections', $sections)
->save();
return $return;
}
/**
* {@inheritdoc}
*/
public function buildRoutes(RouteCollection $collection) : void {
$this->buildLayoutRoutes($collection, $this->getPluginDefinition(), '/admin/config/user-interface/navigation-block');
$default_route = 'layout_builder.' . $this->getPluginDefinition()
->id() . '.view';
$route = $collection->get($default_route);
// Use a form for editing the layout instead of a controller.
$defaults = $route->getDefaults();
$defaults['_form'] = LayoutForm::class;
unset($defaults['_controller']);
$route->setDefaults($defaults);
}
/**
* {@inheritdoc}
*/
public function deriveContextsFromRoute($value, $definition, $name, array $defaults) : array {
return [
'navigation' => new Context(new ContextDefinition('string'), 'navigation'),
];
}
/**
* {@inheritdoc}
*/
public function buildLocalTasks($base_plugin_definition) : array {
return [];
}
/**
* {@inheritdoc}
*/
public function getLayoutBuilderUrl($rel = 'view') : Url {
return Url::fromRoute("layout_builder.{$this->getStorageType()}.{$rel}", [
'id' => $this->getStorageId(),
]);
}
/**
* {@inheritdoc}
*/
public function getRedirectUrl() : Url {
return $this->getLayoutBuilderUrl();
}
/**
* {@inheritdoc}
*/
public function access($operation, ?AccountInterface $account = NULL, $return_as_object = FALSE) : AccessResultInterface|bool {
$result = AccessResult::allowedIfHasPermission($account, 'configure navigation layout');
return $return_as_object ? $result : $result->isAllowed();
}
/**
* {@inheritdoc}
*/
public function getContextsDuringPreview() : array {
return $this->getContexts();
}
/**
* {@inheritdoc}
*/
public function isApplicable(RefinableCacheableDependencyInterface $cacheability) : bool {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function getContextMapping() : array {
return [
'navigation' => 'navigation',
];
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
ContextAwarePluginTrait::$context | protected | property | The data objects representing the context of this plugin. | ||
ContextAwarePluginTrait::getCacheContexts | public | function | 10 | ||
ContextAwarePluginTrait::getCacheMaxAge | public | function | 6 | ||
ContextAwarePluginTrait::getCacheTags | public | function | 3 | ||
ContextAwarePluginTrait::getContext | public | function | |||
ContextAwarePluginTrait::getContextDefinition | public | function | |||
ContextAwarePluginTrait::getContextDefinitions | public | function | |||
ContextAwarePluginTrait::getContexts | public | function | |||
ContextAwarePluginTrait::getContextValue | public | function | |||
ContextAwarePluginTrait::getContextValues | public | function | |||
ContextAwarePluginTrait::getPluginDefinition | abstract public | function | 1 | ||
ContextAwarePluginTrait::setContext | public | function | 1 | ||
ContextAwarePluginTrait::setContextMapping | public | function | |||
ContextAwarePluginTrait::setContextValue | public | function | |||
ContextAwarePluginTrait::validateContexts | public | function | |||
DependencySerializationTrait::$_entityStorages | protected | property | An array of entity type IDs keyed by the property name of their storages. | ||
DependencySerializationTrait::$_serviceIds | protected | property | An array of service IDs keyed by property name used for serialization. | ||
DependencySerializationTrait::__sleep | public | function | 2 | ||
DependencySerializationTrait::__wakeup | public | function | #[\ReturnTypeWillChange] | 2 | |
LayoutBuilderRoutesTrait::buildLayoutRoutes | protected | function | Builds the layout routes for the given values. | ||
MessengerTrait::$messenger | protected | property | The messenger. | 25 | |
MessengerTrait::messenger | public | function | Gets the messenger. | 25 | |
MessengerTrait::setMessenger | public | function | Sets the messenger. | ||
NavigationSectionStorage::$configFactory | protected | property | The config factory. | ||
NavigationSectionStorage::$sections | protected | property | An array of sections. | ||
NavigationSectionStorage::access | public | function | Overrides \Drupal\Core\Access\AccessibleInterface::access(). | Overrides SectionStorageInterface::access | |
NavigationSectionStorage::buildLocalTasks | public | function | Provides the local tasks dynamically for Layout Builder plugins. | Overrides SectionStorageLocalTaskProviderInterface::buildLocalTasks | |
NavigationSectionStorage::buildRoutes | public | function | Provides the routes needed for Layout Builder UI. | Overrides SectionStorageInterface::buildRoutes | |
NavigationSectionStorage::create | public static | function | Creates an instance of the plugin. | Overrides ContainerFactoryPluginInterface::create | |
NavigationSectionStorage::deriveContextsFromRoute | public | function | Derives the available plugin contexts from route values. | Overrides SectionStorageInterface::deriveContextsFromRoute | |
NavigationSectionStorage::getConfigName | protected | function | Returns the name to be used to store in the config system. | ||
NavigationSectionStorage::getContextMapping | public | function | Gets a mapping of the expected assignment names to their context names. | Overrides ContextAwarePluginTrait::getContextMapping | |
NavigationSectionStorage::getContextsDuringPreview | public | function | Gets contexts for use during preview. | Overrides SectionStorageInterface::getContextsDuringPreview | |
NavigationSectionStorage::getLayoutBuilderUrl | public | function | Gets the URL used to display the Layout Builder UI. | Overrides SectionStorageInterface::getLayoutBuilderUrl | |
NavigationSectionStorage::getRedirectUrl | public | function | Gets the URL used when redirecting away from the Layout Builder UI. | Overrides SectionStorageInterface::getRedirectUrl | |
NavigationSectionStorage::getSections | public | function | Gets the layout sections. | Overrides SectionListInterface::getSections | |
NavigationSectionStorage::getStorageId | public | function | Returns an identifier for this storage. | Overrides SectionStorageInterface::getStorageId | |
NavigationSectionStorage::getStorageType | public | function | Returns the type of this storage. | Overrides SectionStorageInterface::getStorageType | |
NavigationSectionStorage::isApplicable | public | function | Determines if this section storage is applicable for the current contexts. | Overrides SectionStorageInterface::isApplicable | |
NavigationSectionStorage::label | public | function | Gets the label for the object using the sections. | Overrides SectionStorageInterface::label | |
NavigationSectionStorage::save | public | function | Saves the sections. | Overrides SectionStorageInterface::save | |
NavigationSectionStorage::setSections | protected | function | Stores the information for all sections. | Overrides SectionListTrait::setSections | |
NavigationSectionStorage::STORAGE_ID | constant | ||||
NavigationSectionStorage::__construct | public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | Overrides PluginBase::__construct | |
PluginBase::$configuration | protected | property | Configuration information passed into the plugin. | 1 | |
PluginBase::$pluginDefinition | protected | property | The plugin implementation definition. | 1 | |
PluginBase::$pluginId | protected | property | The plugin ID. | ||
PluginBase::DERIVATIVE_SEPARATOR | constant | A string which is used to separate base plugin IDs from the derivative ID. | |||
PluginBase::getBaseId | public | function | Gets the base_plugin_id of the plugin instance. | Overrides DerivativeInspectionInterface::getBaseId | |
PluginBase::getDerivativeId | public | function | Gets the derivative_id of the plugin instance. | Overrides DerivativeInspectionInterface::getDerivativeId | |
PluginBase::getPluginId | public | function | Gets the plugin ID of the plugin instance. | Overrides PluginInspectionInterface::getPluginId | |
PluginBase::isConfigurable | public | function | Determines if the plugin is configurable. | ||
SectionListTrait::addBlankSection | protected | function | Adds a blank section to the list. | ||
SectionListTrait::appendSection | public | function | |||
SectionListTrait::count | public | function | #[\ReturnTypeWillChange] | ||
SectionListTrait::getSection | public | function | |||
SectionListTrait::hasBlankSection | protected | function | Indicates if this section list contains a blank section. | ||
SectionListTrait::hasSection | protected | function | Indicates if there is a section at the specified delta. | ||
SectionListTrait::insertSection | public | function | |||
SectionListTrait::removeAllSections | public | function | |||
SectionListTrait::removeSection | public | function | |||
SectionListTrait::setSection | protected | function | Sets the section for the given delta on the display. | ||
SectionListTrait::__clone | public | function | Magic method: Implements a deep clone. | ||
StringTranslationTrait::$stringTranslation | protected | property | The string translation service. | 3 | |
StringTranslationTrait::formatPlural | protected | function | Formats a string containing a count of items. | ||
StringTranslationTrait::getNumberOfPlurals | protected | function | Returns the number of plurals supported by a given language. | ||
StringTranslationTrait::getStringTranslation | protected | function | Gets the string translation service. | ||
StringTranslationTrait::setStringTranslation | public | function | Sets the string translation service to use. | 2 | |
StringTranslationTrait::t | protected | function | Translates a string to the current language or to a given language. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.