function Section::fromArray

Same name in other branches
  1. 9 core/modules/layout_builder/src/Section.php \Drupal\layout_builder\Section::fromArray()
  2. 8.9.x core/modules/layout_builder/src/Section.php \Drupal\layout_builder\Section::fromArray()
  3. 10 core/modules/layout_builder/src/Section.php \Drupal\layout_builder\Section::fromArray()

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

static The section object.

2 calls to Section::fromArray()
LayoutSectionItemList::preSave in core/modules/layout_builder/src/Field/LayoutSectionItemList.php
Defines custom presave behavior for field values.
TestSectionList::__construct in core/modules/layout_builder/tests/src/Kernel/SectionListTraitTest.php
TestSectionList constructor.

File

core/modules/layout_builder/src/Section.php, line 377

Class

Section
Provides a domain object for layout sections.

Namespace

Drupal\layout_builder

Code

public static function fromArray(array $section) {
    // Ensure expected array keys are present.
    $section += [
        'layout_id' => '',
        'layout_settings' => [],
        'components' => [],
        'third_party_settings' => [],
    ];
    return new static($section['layout_id'], $section['layout_settings'], array_map([
        SectionComponent::class,
        'fromArray',
    ], $section['components']), $section['third_party_settings']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.