interface SectionStorageInterface implements SectionListInterface, PluginInspectionInterface, ContextAwarePluginInterface, AccessibleInterface (View source)

Defines an interface for Section Storage type plugins.

Methods

getSections()

Gets the layout sections.

getSection(int $delta)

Gets a domain object for the layout section.

$this
appendSection(Section $section)

Appends a new section to the end of the list.

$this
insertSection(int $delta, Section $section)

Inserts a new section at a given delta.

$this
removeSection(int $delta)

Removes the section at the given delta.

$this
removeAllSections(bool $set_blank = FALSE)

Removes all of the sections.

string
getPluginId()

Gets the plugin_id of the plugin instance.

array
getPluginDefinition()

Overrides \Drupal\Component\Plugin\PluginInspectionInterface::getPluginDefinition().

getContextDefinitions()

Gets the context definitions of the plugin.

getContextDefinition(string $name)

Gets a specific context definition of the plugin.

array
getContexts()

Gets the defined contexts.

getContext(string $name)

Gets a defined context.

array
getContextValues()

Gets the values for all defined contexts.

mixed
getContextValue(string $name)

Gets the value for a defined context.

setContext(string $name, ContextInterface $context)

Set a context on this plugin.

$this
setContextValue(string $name, mixed $value)

Sets the value for a defined context.

ConstraintViolationListInterface
validateContexts()

Validates the set values for the defined contexts.

array
getContextMapping()

Gets a mapping of the expected assignment names to their context names.

$this
setContextMapping(array $context_mapping)

Sets a mapping of the expected assignment names to their context names.

access(string $operation, AccountInterface $account = NULL, bool $return_as_object = FALSE)

Overrides \Drupal\Core\Access\AccessibleInterface::access().

string
getStorageId()

Returns an identifier for this storage.

string
getStorageType()

Returns the type of this storage.

buildRoutes(RouteCollection $collection)

Provides the routes needed for Layout Builder UI.

Url
getRedirectUrl()

Gets the URL used when redirecting away from the Layout Builder UI.

Url
getLayoutBuilderUrl(string $rel = 'view')

Gets the URL used to display the Layout Builder UI.

deriveContextsFromRoute(mixed $value, mixed $definition, string $name, array $defaults)

Derives the available plugin contexts from route values.

getContextsDuringPreview()

Gets contexts for use during preview.

string
label()

Gets the label for the object using the sections.

int
save()

Saves the sections.

bool
isApplicable(RefinableCacheableDependencyInterface $cacheability)

Determines if this section storage is applicable for the current contexts.

Details

Section[] getSections()

Gets the layout sections.

Return Value

Section[]

A sequentially and numerically keyed array of section objects.

Section getSection(int $delta)

Gets a domain object for the layout section.

Parameters

int $delta

The delta of the section.

Return Value

Section

The layout section.

$this appendSection(Section $section)

Appends a new section to the end of the list.

Parameters

Section $section

The section to append.

Return Value

$this

$this insertSection(int $delta, Section $section)

Inserts a new section at a given delta.

If a section exists at the given index, the section at that position and others after it are shifted backward.

Parameters

int $delta

The delta of the section.

Section $section

The section to insert.

Return Value

$this

$this removeSection(int $delta)

Removes the section at the given delta.

As sections are stored sequentially and numerically this will re-key every subsequent section, shifting them forward.

Parameters

int $delta

The delta of the section.

Return Value

$this

$this removeAllSections(bool $set_blank = FALSE)

Removes all of the sections.

Parameters

bool $set_blank

(optional) The default implementation of section lists differentiates between a list that has never contained any sections and a list that has purposefully had all sections removed in order to remain blank. Passing TRUE will mirror ::removeSection() by tracking this as a blank list. Passing FALSE will reset the list as though it had never contained any sections at all. Defaults to FALSE.

Return Value

$this

string getPluginId()

Gets the plugin_id of the plugin instance.

Return Value

string

The plugin_id of the plugin instance.

array getPluginDefinition()

Overrides \Drupal\Component\Plugin\PluginInspectionInterface::getPluginDefinition().

Return Value

array

The plugin definition, as returned by the discovery object used by the plugin manager.

ContextDefinitionInterface[] getContextDefinitions()

Gets the context definitions of the plugin.

Return Value

ContextDefinitionInterface[]

The array of context definitions, keyed by context name.

ContextDefinitionInterface getContextDefinition(string $name)

Gets a specific context definition of the plugin.

Parameters

string $name

The name of the context in the plugin definition.

Return Value

ContextDefinitionInterface

The definition against which the context value must validate.

Exceptions

ContextException

array getContexts()

Gets the defined contexts.

Return Value

array

The set context objects.

Exceptions

ContextException

ContextInterface getContext(string $name)

Gets a defined context.

Parameters

string $name

The name of the context in the plugin definition.

Return Value

ContextInterface

The context object.

Exceptions

ContextException

array getContextValues()

Gets the values for all defined contexts.

Return Value

array

An array of set context values, keyed by context name. If a context is unset its value is returned as NULL.

mixed getContextValue(string $name)

Gets the value for a defined context.

Parameters

string $name

The name of the context in the plugin configuration.

Return Value

mixed

The currently set context value.

Exceptions

ContextException

setContext(string $name, ContextInterface $context)

Set a context on this plugin.

Parameters

string $name

The name of the context in the plugin configuration.

ContextInterface $context

The context object to set.

$this setContextValue(string $name, mixed $value)

Sets the value for a defined context.

Parameters

string $name

The name of the context in the plugin definition.

mixed $value

The value to set the context to. The value has to validate against the provided context definition.

Return Value

$this

A context aware plugin object for chaining.

Exceptions

ContextException

ConstraintViolationListInterface validateContexts()

Validates the set values for the defined contexts.

Return Value

ConstraintViolationListInterface

A list of constraint violations. If the list is empty, validation succeeded.

array getContextMapping()

Gets a mapping of the expected assignment names to their context names.

Return Value

array

A mapping of the expected assignment names to their context names. For example, if one of the $contexts is named 'user.current_user', but the plugin expects a context named 'user', then this map would contain 'user' => 'user.current_user'.

$this setContextMapping(array $context_mapping)

Sets a mapping of the expected assignment names to their context names.

Parameters

array $context_mapping

A mapping of the expected assignment names to their context names. For example, if one of the $contexts is named 'user.current_user', but the plugin expects a context named 'user', then this map would contain 'user' => 'user.current_user'.

Return Value

$this

bool|AccessResultInterface access(string $operation, AccountInterface $account = NULL, bool $return_as_object = FALSE)

Overrides \Drupal\Core\Access\AccessibleInterface::access().

Parameters

string $operation

The operation to be performed.

AccountInterface $account

(optional) The user for which to check access, or NULL to check access for the current user. Defaults to NULL.

bool $return_as_object

(optional) Defaults to FALSE.

Return Value

bool|AccessResultInterface

The access result. Returns a boolean if $return_as_object is FALSE (this is the default) and otherwise an AccessResultInterface object. When a boolean is returned, the result of AccessInterface::isAllowed() is returned, i.e. TRUE means access is explicitly allowed, FALSE means access is either explicitly forbidden or "no opinion".

string getStorageId()

Returns an identifier for this storage.

Return Value

string

The unique identifier for this storage.

string getStorageType()

Returns the type of this storage.

Used in conjunction with the storage ID.

Return Value

string

The type of storage.

buildRoutes(RouteCollection $collection)

Provides the routes needed for Layout Builder UI.

Allows the plugin to add or alter routes during the route building process. \Drupal\layout_builder\Routing\LayoutBuilderRoutesTrait is provided for the typical use case of building a standard Layout Builder UI.

Parameters

RouteCollection $collection

The route collection.

See also

RoutingEvents::ALTER

Url getRedirectUrl()

Gets the URL used when redirecting away from the Layout Builder UI.

Return Value

Url

The URL object.

Url getLayoutBuilderUrl(string $rel = 'view')

Gets the URL used to display the Layout Builder UI.

Parameters

string $rel

(optional) The link relationship type, for example: 'view' or 'disable'. Defaults to 'view'.

Return Value

Url

The URL object.

ContextInterface[] deriveContextsFromRoute(mixed $value, mixed $definition, string $name, array $defaults)

Derives the available plugin contexts from route values.

This should only be called during section storage instantiation, specifically for use by the routing system. For all non-routing usages, use \Drupal\Component\Plugin\ContextAwarePluginInterface::getContextValue().

Parameters

mixed $value

The raw value.

mixed $definition

The parameter definition provided in the route options.

string $name

The name of the parameter.

array $defaults

The route defaults array.

Return Value

ContextInterface[]

The available plugin contexts.

See also

ParamConverterInterface::convert

ContextInterface[] getContextsDuringPreview()

Gets contexts for use during preview.

When not in preview, ::getContexts() will be used.

Return Value

ContextInterface[]

The plugin contexts suitable for previewing.

string label()

Gets the label for the object using the sections.

Return Value

string

The label, or NULL if there is no label defined.

int save()

Saves the sections.

Return Value

int

SAVED_NEW or SAVED_UPDATED is returned depending on the operation performed.

bool isApplicable(RefinableCacheableDependencyInterface $cacheability)

internal  This method is intended to be called by \Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface::findByContext().
 

Determines if this section storage is applicable for the current contexts.

Parameters

RefinableCacheableDependencyInterface $cacheability

Refinable cacheability object, typically provided by the section storage manager. When implementing this method, populate $cacheability with any information that affects whether this storage is applicable.

Return Value

bool

TRUE if this section storage is applicable, FALSE otherwise.

See also

RefinableCacheableDependencyInterface