class SimpleConfigSectionStorage in Drupal 8
Same name and namespace in other branches
- 9 core/modules/layout_builder/tests/modules/layout_builder_test/src/Plugin/SectionStorage/SimpleConfigSectionStorage.php \Drupal\layout_builder_test\Plugin\SectionStorage\SimpleConfigSectionStorage
Provides section storage utilizing simple config.
Plugin annotation
@SectionStorage(
id = "test_simple_config",
context_definitions = {
"config_id" = @ContextDefinition("string"),
}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Component\Plugin\ContextAwarePluginBase implements ContextAwarePluginInterface
- class \Drupal\Core\Plugin\ContextAwarePluginBase implements CacheableDependencyInterface, ContextAwarePluginInterface uses DependencySerializationTrait, StringTranslationTrait, TypedDataTrait
- class \Drupal\layout_builder_test\Plugin\SectionStorage\SimpleConfigSectionStorage implements ContainerFactoryPluginInterface, SectionStorageLocalTaskProviderInterface, SectionStorageInterface uses LayoutBuilderRoutesTrait, SectionStorageTrait
- class \Drupal\Core\Plugin\ContextAwarePluginBase implements CacheableDependencyInterface, ContextAwarePluginInterface uses DependencySerializationTrait, StringTranslationTrait, TypedDataTrait
- class \Drupal\Component\Plugin\ContextAwarePluginBase implements ContextAwarePluginInterface
Expanded class hierarchy of SimpleConfigSectionStorage
1 file declares its use of SimpleConfigSectionStorage
- SimpleConfigSectionStorageTest.php in core/
modules/ layout_builder/ tests/ src/ Kernel/ SimpleConfigSectionStorageTest.php
File
- core/
modules/ layout_builder/ tests/ modules/ layout_builder_test/ src/ Plugin/ SectionStorage/ SimpleConfigSectionStorage.php, line 32
Namespace
Drupal\layout_builder_test\Plugin\SectionStorageView source
class SimpleConfigSectionStorage extends ContextAwarePluginBase implements SectionStorageInterface, SectionStorageLocalTaskProviderInterface, ContainerFactoryPluginInterface {
use LayoutBuilderRoutesTrait;
use SectionStorageTrait;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $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) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('config.factory'));
}
/**
* {@inheritdoc}
*/
public function getStorageType() {
return $this
->getPluginId();
}
/**
* {@inheritdoc}
*/
public function getStorageId() {
return $this
->getContextValue('config_id');
}
/**
* {@inheritdoc}
*/
public function label() {
return $this
->getStorageId();
}
/**
* Returns the name to be used to store in the config system.
*/
protected function getConfigName() {
return 'layout_builder_test.' . $this
->getStorageType() . '.' . $this
->getStorageId();
}
/**
* {@inheritdoc}
*/
public function getSections() {
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) {
$this->sections = array_values($sections);
return $this;
}
/**
* {@inheritdoc}
*/
public function save() {
$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) {
$this
->buildLayoutRoutes($collection, $this
->getPluginDefinition(), 'layout-builder-test-simple-config/{id}');
}
/**
* {@inheritdoc}
*/
public function deriveContextsFromRoute($value, $definition, $name, array $defaults) {
$contexts['config_id'] = new Context(new ContextDefinition('string'), $value ?: $defaults['id']);
return $contexts;
}
/**
* {@inheritdoc}
*/
public function buildLocalTasks($base_plugin_definition) {
$type = $this
->getStorageType();
$local_tasks = [];
$local_tasks["layout_builder.{$type}.view"] = $base_plugin_definition + [
'route_name' => "layout_builder.{$type}.view",
'title' => $this
->t('Layout'),
'base_route' => "layout_builder.{$type}.view",
];
$local_tasks["layout_builder.{$type}.view__child"] = $base_plugin_definition + [
'route_name' => "layout_builder.{$type}.view",
'title' => $this
->t('Layout'),
'parent_id' => "layout_builder_ui:layout_builder.{$type}.view",
];
$local_tasks["layout_builder.{$type}.discard_changes"] = $base_plugin_definition + [
'route_name' => "layout_builder.{$type}.discard_changes",
'title' => $this
->t('Discard changes'),
'parent_id' => "layout_builder_ui:layout_builder.{$type}.view",
'weight' => 5,
];
return $local_tasks;
}
/**
* {@inheritdoc}
*/
public function getLayoutBuilderUrl($rel = 'view') {
return Url::fromRoute("layout_builder.{$this->getStorageType()}.{$rel}", [
'id' => $this
->getStorageId(),
]);
}
/**
* {@inheritdoc}
*/
public function getRedirectUrl() {
return $this
->getLayoutBuilderUrl();
}
/**
* {@inheritdoc}
*/
public function access($operation, AccountInterface $account = NULL, $return_as_object = FALSE) {
$result = AccessResult::allowed();
return $return_as_object ? $result : $result
->isAllowed();
}
/**
* {@inheritdoc}
*/
public function getContextsDuringPreview() {
return $this
->getContexts();
}
/**
* {@inheritdoc}
*/
public function getSectionListFromId($id) {
@trigger_error('\\Drupal\\layout_builder\\SectionStorageInterface::getSectionListFromId() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. The section list should be derived from context. See https://www.drupal.org/node/3016262.', E_USER_DEPRECATED);
return $this;
}
/**
* {@inheritdoc}
*/
public function extractIdFromRoute($value, $definition, $name, array $defaults) {
@trigger_error('\\Drupal\\layout_builder\\SectionStorageInterface::extractIdFromRoute() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. \\Drupal\\layout_builder\\SectionStorageInterface::deriveContextsFromRoute() should be used instead. See https://www.drupal.org/node/3016262.', E_USER_DEPRECATED);
return $value ?: $defaults['id'];
}
/**
* {@inheritdoc}
*/
public function isApplicable(RefinableCacheableDependencyInterface $cacheability) {
return TRUE;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContextAwarePluginBase:: |
protected | property | The data objects representing the context of this plugin. | |
ContextAwarePluginBase:: |
private | property | Data objects representing the contexts passed in the plugin configuration. | |
ContextAwarePluginBase:: |
protected | function | Wraps the context handler. | |
ContextAwarePluginBase:: |
protected | function |
Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
The cache contexts associated with this object. Overrides CacheableDependencyInterface:: |
9 |
ContextAwarePluginBase:: |
public | function |
The maximum age for which this object may be cached. Overrides CacheableDependencyInterface:: |
7 |
ContextAwarePluginBase:: |
public | function |
The cache tags associated with this object. Overrides CacheableDependencyInterface:: |
4 |
ContextAwarePluginBase:: |
public | function |
This code is identical to the Component in order to pick up a different
Context class. Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Gets a mapping of the expected assignment names to their context names. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Gets the defined contexts. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Gets the value for a defined context. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Gets the values for all defined contexts. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Set a context on this plugin. Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Sets a mapping of the expected assignment names to their context names. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function |
Sets the value for a defined context. Overrides ContextAwarePluginBase:: |
|
ContextAwarePluginBase:: |
public | function |
Validates the set values for the defined contexts. Overrides ContextAwarePluginInterface:: |
|
ContextAwarePluginBase:: |
public | function | Implements magic __get() method. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
LayoutBuilderRoutesTrait:: |
protected | function | Builds the layout routes for the given values. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
SectionStorageTrait:: |
protected | function | Adds a blank section to the list. | |
SectionStorageTrait:: |
public | function | ||
SectionStorageTrait:: |
public | function | ||
SectionStorageTrait:: |
public | function | ||
SectionStorageTrait:: |
protected | function | Indicates if this section list contains a blank section. | |
SectionStorageTrait:: |
protected | function | Indicates if there is a section at the specified delta. | |
SectionStorageTrait:: |
public | function | ||
SectionStorageTrait:: |
public | function | ||
SectionStorageTrait:: |
public | function | ||
SectionStorageTrait:: |
protected | function | Sets the section for the given delta on the display. | |
SectionStorageTrait:: |
public | function | Magic method: Implements a deep clone. | |
SimpleConfigSectionStorage:: |
protected | property | The config factory. | |
SimpleConfigSectionStorage:: |
protected | property | An array of sections. | |
SimpleConfigSectionStorage:: |
public | function |
Overrides \Drupal\Core\Access\AccessibleInterface::access(). Overrides SectionStorageInterface:: |
|
SimpleConfigSectionStorage:: |
public | function |
Provides the local tasks dynamically for Layout Builder plugins. Overrides SectionStorageLocalTaskProviderInterface:: |
|
SimpleConfigSectionStorage:: |
public | function |
Provides the routes needed for Layout Builder UI. Overrides SectionStorageInterface:: |
|
SimpleConfigSectionStorage:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
SimpleConfigSectionStorage:: |
public | function |
Derives the available plugin contexts from route values. Overrides SectionStorageInterface:: |
|
SimpleConfigSectionStorage:: |
public | function |
Configures the plugin based on route values. Overrides SectionStorageInterface:: |
|
SimpleConfigSectionStorage:: |
protected | function | Returns the name to be used to store in the config system. | |
SimpleConfigSectionStorage:: |
public | function |
Gets contexts for use during preview. Overrides SectionStorageInterface:: |
|
SimpleConfigSectionStorage:: |
public | function |
Gets the URL used to display the Layout Builder UI. Overrides SectionStorageInterface:: |
|
SimpleConfigSectionStorage:: |
public | function |
Gets the URL used when redirecting away from the Layout Builder UI. Overrides SectionStorageInterface:: |
|
SimpleConfigSectionStorage:: |
public | function |
Derives the section list from the storage ID. Overrides SectionStorageInterface:: |
|
SimpleConfigSectionStorage:: |
public | function |
Gets the layout sections. Overrides SectionListInterface:: |
|
SimpleConfigSectionStorage:: |
public | function |
Returns an identifier for this storage. Overrides SectionStorageInterface:: |
|
SimpleConfigSectionStorage:: |
public | function |
Returns the type of this storage. Overrides SectionStorageInterface:: |
|
SimpleConfigSectionStorage:: |
public | function |
Determines if this section storage is applicable for the current contexts. Overrides SectionStorageInterface:: |
|
SimpleConfigSectionStorage:: |
public | function |
Gets the label for the object using the sections. Overrides SectionStorageInterface:: |
|
SimpleConfigSectionStorage:: |
public | function |
Saves the sections. Overrides SectionStorageInterface:: |
|
SimpleConfigSectionStorage:: |
protected | function |
Stores the information for all sections. Overrides SectionStorageTrait:: |
|
SimpleConfigSectionStorage:: |
public | function |
Overrides \Drupal\Component\Plugin\PluginBase::__construct(). Overrides ContextAwarePluginBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TypedDataTrait:: |
protected | property | The typed data manager used for creating the data types. | |
TypedDataTrait:: |
public | function | Gets the typed data manager. | 2 |
TypedDataTrait:: |
public | function | Sets the typed data manager. | 2 |