You are here

public static function Section::fromArray in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/src/Section.php \Drupal\layout_builder\Section::fromArray()
  2. 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.

4 calls to Section::fromArray()
layout-builder-field-block.php in core/modules/layout_builder/tests/fixtures/update/layout-builder-field-block.php
Test fixture.
layout-builder-translation.php in core/modules/layout_builder/tests/fixtures/update/layout-builder-translation.php
Test fixture.
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 358

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']);
}