class SectionComponent (View source)

Provides a value object for a section component.

A component represents the smallest part of a layout (for example, a block). Components wrap a renderable plugin, currently using \Drupal\Core\Block\BlockPluginInterface, and contain the layout region within the section layout where the component will be rendered.

Properties

protected string $uuid

The UUID of the component.

protected string $region

The region the component is placed in.

protected array $configuration

An array of plugin configuration.

protected int $weight

The weight of the component.

protected array $additional

Any additional properties and values.

Methods

__construct(string $uuid, string $region, array $configuration = [], array $additional = [])

Constructs a new SectionComponent.

array
toRenderArray(array $contexts = [], bool $in_preview = FALSE)

Returns the renderable array for this component.

mixed
get(string $property)

Gets any arbitrary property for the component.

$this
set(string $property, mixed $value)

Sets a value to an arbitrary property for the component.

string
getRegion()

Gets the region for the component.

$this
setRegion(string $region)

Sets the region for the component.

int
getWeight()

Gets the weight of the component.

$this
setWeight(int $weight)

Sets the weight of the component.

array
getConfiguration()

Gets the component plugin configuration.

$this
setConfiguration(array $configuration)

Sets the plugin configuration.

string
getPluginId()

Gets the plugin ID.

string
getUuid()

Gets the UUID for this component.

getPlugin(array $contexts = [])

Gets the plugin for this component.

pluginManager()

Wraps the component plugin manager.

contextHandler()

Wraps the context handler.

EventDispatcherInterface
eventDispatcher()

Wraps the event dispatcher.

array
toArray()

Returns an array representation of the section component.

fromArray(array $component)

Creates an object from an array representation of the section component.

Details

__construct(string $uuid, string $region, array $configuration = [], array $additional = [])

Constructs a new SectionComponent.

Parameters

string $uuid

The UUID.

string $region

The region.

array $configuration

The plugin configuration.

array $additional

An additional values.

array toRenderArray(array $contexts = [], bool $in_preview = FALSE)

Returns the renderable array for this component.

Parameters

array $contexts

An array of available contexts.

bool $in_preview

TRUE if the component is being previewed, FALSE otherwise.

Return Value

array

A renderable array representing the content of the component.

mixed get(string $property)

Gets any arbitrary property for the component.

Parameters

string $property

The property to retrieve.

Return Value

mixed

The value for that property, or NULL if the property does not exist.

$this set(string $property, mixed $value)

Sets a value to an arbitrary property for the component.

Parameters

string $property

The property to use for the value.

mixed $value

The value to set.

Return Value

$this

string getRegion()

Gets the region for the component.

Return Value

string

The region.

$this setRegion(string $region)

Sets the region for the component.

Parameters

string $region

The region.

Return Value

$this

int getWeight()

Gets the weight of the component.

Return Value

int

The zero-based weight of the component.

Exceptions

UnexpectedValueException

$this setWeight(int $weight)

Sets the weight of the component.

Parameters

int $weight

The zero-based weight of the component.

Return Value

$this

protected array getConfiguration()

Gets the component plugin configuration.

Return Value

array

The component plugin configuration.

$this setConfiguration(array $configuration)

Sets the plugin configuration.

Parameters

array $configuration

The plugin configuration.

Return Value

$this

string getPluginId()

Gets the plugin ID.

Return Value

string

The plugin ID.

Exceptions

PluginException

string getUuid()

Gets the UUID for this component.

Return Value

string

The UUID.

PluginInspectionInterface getPlugin(array $contexts = [])

Gets the plugin for this component.

Parameters

array $contexts

An array of contexts to set on the plugin.

Return Value

PluginInspectionInterface

The plugin.

protected BlockManagerInterface pluginManager()

Wraps the component plugin manager.

Return Value

BlockManagerInterface

The plugin manager.

protected ContextHandlerInterface contextHandler()

Wraps the context handler.

Return Value

ContextHandlerInterface

The context handler.

protected EventDispatcherInterface eventDispatcher()

Wraps the event dispatcher.

Return Value

EventDispatcherInterface

The event dispatcher.

array toArray()

Returns an array representation of the section component.

Only use this method if you are implementing custom storage for sections.

Return Value

array

An array representation of the section component.

static SectionComponent fromArray(array $component)

Creates an object from an array representation of the section component.

Only use this method if you are implementing custom storage for sections.

Parameters

array $component

An array of section component data in the format returned by ::toArray().

Return Value

SectionComponent

The section component object.