class Section implements ThirdPartySettingsInterface (View source)

Provides a domain object for layout sections.

A section consists of three parts:

  • The layout plugin ID for the layout applied to the section (for example, 'layout_onecol').
  • An array of settings for the layout plugin.
  • An array of components that can be rendered in the section.

Properties

protected string $layoutId

The layout plugin ID.

protected array $layoutSettings

The layout plugin settings.

protected SectionComponent[] $components

An array of components, keyed by UUID.

protected array[] $thirdPartySettings

Third party settings.

Methods

__construct(string $layout_id, array $layout_settings = [], array $components = [], array $third_party_settings = [])

Constructs a new Section.

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

Returns the renderable array for this section.

getLayout()

Gets the layout plugin for this section.

string
getLayoutId()

Gets the layout plugin ID for this section.

array
getLayoutSettings()

Gets the layout plugin settings for this section.

$this
setLayoutSettings(array $layout_settings)

Sets the layout plugin settings for this section.

string
getDefaultRegion()

Gets the default region.

getComponents()

Returns the components of the section.

getComponent(string $uuid)

Gets the component for a given UUID.

$this
setComponent(SectionComponent $component)

Helper method to set a component.

$this
removeComponent(string $uuid)

Removes a given component from a region.

$this
appendComponent(SectionComponent $component)

Appends a component to the end of a region.

int
getNextHighestWeight(string $region)

Returns the next highest weight of the component in a region.

getComponentsByRegion(string $region)

Gets the components for a specific region.

$this
insertAfterComponent(string $preceding_uuid, SectionComponent $component)

Inserts a component after a specified existing component.

$this
insertComponent(int $delta, SectionComponent $new_component)

Inserts a component at a specified delta.

layoutPluginManager()

Wraps the layout plugin manager.

array
toArray()

Returns an array representation of the section.

static Section
fromArray(array $section)

Creates an object from an array representation of the section.

__clone()

Magic method: Implements a deep clone.

mixed
getThirdPartySetting($provider, string $key, mixed $default = NULL)

Gets the value of a third-party setting.

array
getThirdPartySettings($provider)

Gets all third-party settings of a given module.

$this
setThirdPartySetting($provider, string $key, mixed $value)

Sets the value of a third-party setting.

mixed
unsetThirdPartySetting($provider, string $key)

Unsets a third-party setting.

array
getThirdPartyProviders()

Gets the list of third parties that store information.

Details

__construct(string $layout_id, array $layout_settings = [], array $components = [], array $third_party_settings = [])

Constructs a new Section.

Parameters

string $layout_id

The layout plugin ID.

array $layout_settings

(optional) The layout plugin settings.

array $components

(optional) The components.

array $third_party_settings

(optional) Any third party settings.

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

Returns the renderable array for this section.

Parameters

array $contexts

An array of available contexts.

bool $in_preview

TRUE if the section is being previewed, FALSE otherwise.

Return Value

array

A renderable array representing the content of the section.

LayoutInterface getLayout()

Gets the layout plugin for this section.

Return Value

LayoutInterface

The layout plugin.

string getLayoutId()

internal  This method should only be used by code responsible for storing the data.
 

Gets the layout plugin ID for this section.

Return Value

string

The layout plugin ID.

array getLayoutSettings()

internal  This method should only be used by code responsible for storing the data.
 

Gets the layout plugin settings for this section.

Return Value

array

The layout plugin settings.

$this setLayoutSettings(array $layout_settings)

Sets the layout plugin settings for this section.

Parameters

array $layout_settings

The layout plugin settings.

Return Value

$this

string getDefaultRegion()

Gets the default region.

Return Value

string

The machine-readable name of the default region.

SectionComponent[] getComponents()

Returns the components of the section.

Return Value

SectionComponent[]

The components.

SectionComponent getComponent(string $uuid)

Gets the component for a given UUID.

Parameters

string $uuid

The UUID of the component to retrieve.

Return Value

SectionComponent

The component.

Exceptions

InvalidArgumentException

protected $this setComponent(SectionComponent $component)

Helper method to set a component.

Parameters

SectionComponent $component

The component.

Return Value

$this

$this removeComponent(string $uuid)

Removes a given component from a region.

Parameters

string $uuid

The UUID of the component to remove.

Return Value

$this

$this appendComponent(SectionComponent $component)

Appends a component to the end of a region.

Parameters

SectionComponent $component

The component being appended.

Return Value

$this

protected int getNextHighestWeight(string $region)

Returns the next highest weight of the component in a region.

Parameters

string $region

The region name.

Return Value

int

A number higher than the highest weight of the component in the region.

SectionComponent[] getComponentsByRegion(string $region)

Gets the components for a specific region.

Parameters

string $region

The region name.

Return Value

SectionComponent[]

An array of components in the specified region, sorted by weight.

$this insertAfterComponent(string $preceding_uuid, SectionComponent $component)

Inserts a component after a specified existing component.

Parameters

string $preceding_uuid

The UUID of the existing component to insert after.

SectionComponent $component

The component being inserted.

Return Value

$this

Exceptions

InvalidArgumentException

$this insertComponent(int $delta, SectionComponent $new_component)

Inserts a component at a specified delta.

Parameters

int $delta

The zero-based delta in which to insert the component.

SectionComponent $new_component

The component being inserted.

Return Value

$this

Exceptions

OutOfBoundsException

protected LayoutPluginManagerInterface layoutPluginManager()

Wraps the layout plugin manager.

Return Value

LayoutPluginManagerInterface

The layout plugin manager.

array toArray()

Returns an array representation of the section.

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

Return Value

array

An array representation of the section component.

static Section fromArray(array $section)

Creates an object from an array representation of the section.

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

Parameters

array $section

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

Return Value

Section

The section object.

__clone()

Magic method: Implements a deep clone.

mixed getThirdPartySetting($provider, string $key, mixed $default = NULL)

Gets the value of a third-party setting.

Parameters

$provider
string $key

The setting name.

mixed $default

The default value

Return Value

mixed

The value.

array getThirdPartySettings($provider)

Gets all third-party settings of a given module.

Parameters

$provider

Return Value

array

An array of key-value pairs.

$this setThirdPartySetting($provider, string $key, mixed $value)

Sets the value of a third-party setting.

Parameters

$provider
string $key

The setting name.

mixed $value

The setting value.

Return Value

$this

mixed unsetThirdPartySetting($provider, string $key)

Unsets a third-party setting.

Parameters

$provider
string $key

The setting name.

Return Value

mixed

The value.

array getThirdPartyProviders()

Gets the list of third parties that store information.

Return Value

array

The list of third parties.