3 namespace Drupal\layout_builder\Entity;
5 use Drupal\Core\Config\Entity\ConfigEntityStorage;
6 use Drupal\Core\Entity\EntityInterface;
7 use Drupal\layout_builder\Section;
8 use Drupal\layout_builder\SectionComponent;
11 * Provides storage for entity view display entities that have layouts.
14 * Layout Builder is currently experimental and should only be leveraged by
15 * experimental modules and development releases of contributed modules.
16 * See https://www.drupal.org/core/experimental for more information.
18 class LayoutBuilderEntityViewDisplayStorage extends ConfigEntityStorage {
23 protected function mapToStorageRecord(EntityInterface $entity) {
24 $record = parent::mapToStorageRecord($entity);
26 if (!empty($record['third_party_settings']['layout_builder']['sections'])) {
27 $record['third_party_settings']['layout_builder']['sections'] = array_map(function (Section $section) {
28 return $section->toArray();
29 }, $record['third_party_settings']['layout_builder']['sections']);
37 protected function mapFromStorageRecords(array $records) {
38 foreach ($records as $id => &$record) {
39 if (!empty($record['third_party_settings']['layout_builder']['sections'])) {
40 $sections = &$record['third_party_settings']['layout_builder']['sections'];
41 foreach ($sections as $section_delta => $section) {
42 $sections[$section_delta] = new Section(
43 $section['layout_id'],
44 $section['layout_settings'],
45 array_map(function (array $component) {
46 return (new SectionComponent(
49 $component['configuration'],
50 $component['additional']
51 ))->setWeight($component['weight']);
52 }, $section['components'])
57 return parent::mapFromStorageRecords($records);