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;
10 * Provides storage for entity view display entities that have layouts.
13 * Layout Builder is currently experimental and should only be leveraged by
14 * experimental modules and development releases of contributed modules.
15 * See https://www.drupal.org/core/experimental for more information.
17 class LayoutBuilderEntityViewDisplayStorage extends ConfigEntityStorage {
22 protected function mapToStorageRecord(EntityInterface $entity) {
23 $record = parent::mapToStorageRecord($entity);
25 if (!empty($record['third_party_settings']['layout_builder']['sections'])) {
26 $record['third_party_settings']['layout_builder']['sections'] = array_map(function (Section $section) {
27 return $section->toArray();
28 }, $record['third_party_settings']['layout_builder']['sections']);
36 protected function mapFromStorageRecords(array $records) {
37 foreach ($records as $id => &$record) {
38 if (!empty($record['third_party_settings']['layout_builder']['sections'])) {
39 $sections = &$record['third_party_settings']['layout_builder']['sections'];
40 $sections = array_map([Section::class, 'fromArray'], $sections);
43 return parent::mapFromStorageRecords($records);