class PageManagerSectionStorage in Page Manager 8.4
Defines the 'page_manager' section storage type.
Plugin annotation
@SectionStorage(
id = "page_manager",
context_definitions = {
"entity" = @ContextDefinition("entity:page_variant"),
},
)
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\Plugin\SectionStorage\SectionStorageBase implements SectionStorageInterface, TempStoreIdentifierInterface uses LayoutBuilderRoutesTrait
- class \Drupal\page_manager\Plugin\SectionStorage\PageManagerSectionStorage implements ContainerFactoryPluginInterface
- class \Drupal\layout_builder\Plugin\SectionStorage\SectionStorageBase implements SectionStorageInterface, TempStoreIdentifierInterface uses LayoutBuilderRoutesTrait
- class \Drupal\Core\Plugin\ContextAwarePluginBase implements CacheableDependencyInterface, ContextAwarePluginInterface uses DependencySerializationTrait, StringTranslationTrait, TypedDataTrait
- class \Drupal\Component\Plugin\ContextAwarePluginBase implements ContextAwarePluginInterface
Expanded class hierarchy of PageManagerSectionStorage
File
- src/
Plugin/ SectionStorage/ PageManagerSectionStorage.php, line 32
Namespace
Drupal\page_manager\Plugin\SectionStorageView source
class PageManagerSectionStorage extends SectionStorageBase implements ContainerFactoryPluginInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The sample entity generator.
*
* @var \Drupal\layout_builder\Entity\SampleEntityGeneratorInterface
*/
protected $sampleEntityGenerator;
/**
* The tempstore factory.
*
* @var \Drupal\Core\TempStore\SharedTempStoreFactory
*/
protected $tempstore;
/**
* The entity bundle info.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityTypeBundleInfo;
/**
* PageManagerSectionStorage constructor.
*
* @param array $configuration
* The plugin configuration, i.e. an array with configuration values keyed
* by configuration option name. The special key 'context' may be used to
* initialize the defined contexts by setting it to an array of context
* values keyed by context names.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\layout_builder\Entity\SampleEntityGeneratorInterface $sample_entity_generator
* The sample entity generator.
* @param \Drupal\Core\TempStore\SharedTempStoreFactory $tempstore
* The tempstore factory.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity bundle information.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, SampleEntityGeneratorInterface $sample_entity_generator, SharedTempStoreFactory $tempstore, EntityTypeBundleInfoInterface $entity_type_bundle_info) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
$this->sampleEntityGenerator = $sample_entity_generator;
$this->tempstore = $tempstore;
$this->entityTypeBundleInfo = $entity_type_bundle_info;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'), $container
->get('layout_builder.sample_entity_generator'), $container
->get('tempstore.shared'), $container
->get('entity_type.bundle.info'));
}
/**
* {@inheritdoc}
*/
protected function getSectionList() {
return $this
->getContextValue('entity')
->getVariantPlugin();
}
/**
* Gets the page variant entity.
*
* @return \Drupal\page_manager\Entity\PageVariant
* The page variant entity.
*
* @throws \Drupal\Component\Plugin\Exception\PluginException
*/
protected function getPageVariant() {
return $this
->getContextValue('entity');
}
/**
* {@inheritdoc}
*/
public function getStorageId() {
return $this
->getContextValue('entity')
->id();
}
/**
* {@inheritdoc}
*/
public function getRedirectUrl() {
return Url::fromUri($this
->getPageVariant()
->getPage()
->getPath());
}
/**
* {@inheritdoc}
*/
public function getLayoutBuilderUrl($rel = 'view') {
return Url::fromRoute("layout_builder.page_manager.view", [
'page_variant' => $this
->getPageVariant()
->id(),
]);
}
/**
* {@inheritdoc}
*/
public function buildRoutes(RouteCollection $collection) {
$path = '/admin/structure/page_manager/{page_variant}/layout';
$options['parameters']['page_variant']['type'] = 'entity:page_variant';
$options['_admin_route'] = FALSE;
$this
->buildLayoutRoutes($collection, $this
->getPluginDefinition(), $path, [], [], $options, '', 'page_variant');
}
/**
* {@inheritdoc}
*/
public function deriveContextsFromRoute($value, $definition, $name, array $defaults) {
// Try to load from defaults.
$entity = $this
->extractEntityFromRoute($value, $defaults);
// Otherwise try the tempstore.
if (!$entity) {
$entity = $this->tempstore
->get('page_manager.layout_builder')
->get($value);
}
return [
'entity' => EntityContext::fromEntity($entity),
];
}
/**
* {@inheritdoc}
*/
private function extractEntityFromRoute($value, array $defaults) {
if (!empty($value)) {
return PageVariant::load($value);
}
return PageVariant::load($defaults['page_variant']);
}
/**
* {@inheritdoc}
*/
public function label() {
return $this
->getPageVariant()
->label();
}
/**
* {@inheritdoc}
*/
public function save() {
$page_variant = $this
->getPageVariant();
return $page_variant
->save();
}
/**
* {@inheritdoc}
*/
public function access($operation, AccountInterface $account = NULL, $return_as_object = FALSE) {
$result = AccessResult::allowedIf($this
->isLayoutBuilderEnabled())
->addCacheableDependency($this);
return $return_as_object ? $result : $result
->isAllowed();
}
/**
* {@inheritdoc}
*/
public function isApplicable(RefinableCacheableDependencyInterface $cacheability) {
return $this
->isLayoutBuilderEnabled();
}
/**
* Determines if Layout Builder is enabled.
*
* @return bool
* TRUE if Layout Builder is enabled, FALSE otherwise.
*
* @throws \Drupal\Component\Plugin\Exception\PluginException
*/
public function isLayoutBuilderEnabled() {
return $this
->getContextValue('entity')
->getVariantPlugin() instanceof LayoutBuilderDisplayVariant;
}
/**
* {@inheritdoc}
*/
public function getSectionListFromId($id) {
// @todo
// This is deprecated and can be removed before Drupal 9.0.0.
}
/**
* {@inheritdoc}
*/
public function extractIdFromRoute($value, $definition, $name, array $defaults) {
// @todo
// This is deprecated and can be removed before Drupal 9.0.0.
}
/**
* {@inheritdoc}
*/
public function getContextsDuringPreview() {
$contexts = $this
->getPageVariant()
->getContexts() + $this
->getPageVariant()
->getStaticContexts();
foreach ($contexts as $name => $context) {
if (!$context
->hasContextValue()) {
$data_type = $context
->getContextDefinition()
->getDataType();
if (strpos($data_type, 'entity:') === 0) {
list(, $entity_type_id) = explode(':', $data_type, 2);
$bundle = $entity_type_id;
if ($this->entityTypeManager
->getDefinition($entity_type_id)
->hasKey('bundle')) {
$bundle = key($this->entityTypeBundleInfo
->getBundleInfo($entity_type_id));
}
$sample = $this->sampleEntityGenerator
->get($entity_type_id, $bundle);
$contexts[$name] = Context::createFromContext($context, $sample);
}
}
}
return $contexts;
}
}
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. | |
PageManagerSectionStorage:: |
protected | property | The entity bundle info. | |
PageManagerSectionStorage:: |
protected | property | The entity type manager. | |
PageManagerSectionStorage:: |
protected | property | The sample entity generator. | |
PageManagerSectionStorage:: |
protected | property | The tempstore factory. | |
PageManagerSectionStorage:: |
public | function |
Overrides \Drupal\Core\Access\AccessibleInterface::access(). Overrides SectionStorageInterface:: |
|
PageManagerSectionStorage:: |
public | function |
Provides the routes needed for Layout Builder UI. Overrides SectionStorageInterface:: |
|
PageManagerSectionStorage:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
PageManagerSectionStorage:: |
public | function |
Derives the available plugin contexts from route values. Overrides SectionStorageInterface:: |
|
PageManagerSectionStorage:: |
private | function | ||
PageManagerSectionStorage:: |
public | function |
Configures the plugin based on route values. Overrides SectionStorageInterface:: |
|
PageManagerSectionStorage:: |
public | function |
Gets contexts for use during preview. Overrides SectionStorageBase:: |
|
PageManagerSectionStorage:: |
public | function |
Gets the URL used to display the Layout Builder UI. Overrides SectionStorageInterface:: |
|
PageManagerSectionStorage:: |
protected | function | Gets the page variant entity. | |
PageManagerSectionStorage:: |
public | function |
Gets the URL used when redirecting away from the Layout Builder UI. Overrides SectionStorageInterface:: |
|
PageManagerSectionStorage:: |
protected | function |
Gets the section list. Overrides SectionStorageBase:: |
|
PageManagerSectionStorage:: |
public | function |
Derives the section list from the storage ID. Overrides SectionStorageInterface:: |
|
PageManagerSectionStorage:: |
public | function |
Returns an identifier for this storage. Overrides SectionStorageInterface:: |
|
PageManagerSectionStorage:: |
public | function |
Determines if this section storage is applicable for the current contexts. Overrides SectionStorageInterface:: |
|
PageManagerSectionStorage:: |
public | function | Determines if Layout Builder is enabled. | |
PageManagerSectionStorage:: |
public | function |
Gets the label for the object using the sections. Overrides SectionStorageInterface:: |
|
PageManagerSectionStorage:: |
public | function |
Saves the sections. Overrides SectionStorageInterface:: |
|
PageManagerSectionStorage:: |
public | function |
PageManagerSectionStorage constructor. Overrides ContextAwarePluginBase:: |
|
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. | |
SectionStorageBase:: |
public | function |
Appends a new section to the end of the list. Overrides SectionListInterface:: |
|
SectionStorageBase:: |
public | function | ||
SectionStorageBase:: |
public | function |
Gets a domain object for the layout section. Overrides SectionListInterface:: |
|
SectionStorageBase:: |
public | function |
Gets the layout sections. Overrides SectionListInterface:: |
1 |
SectionStorageBase:: |
public | function |
Returns the type of this storage. Overrides SectionStorageInterface:: |
|
SectionStorageBase:: |
public | function |
Gets a string suitable for use as a tempstore key. Overrides TempStoreIdentifierInterface:: |
1 |
SectionStorageBase:: |
public | function |
Inserts a new section at a given delta. Overrides SectionListInterface:: |
|
SectionStorageBase:: |
public | function |
Removes all of the sections. Overrides SectionListInterface:: |
|
SectionStorageBase:: |
public | function |
Removes the section at the given delta. Overrides SectionListInterface:: |
|
SectionStorageBase:: |
public | function | Sets the section list on the storage. | |
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 |