Pull merge.
[yaffs-website] / web / core / modules / layout_builder / src / Entity / LayoutBuilderEntityViewDisplayStorage.php
1 <?php
2
3 namespace Drupal\layout_builder\Entity;
4
5 use Drupal\Core\Config\Entity\ConfigEntityStorage;
6 use Drupal\Core\Entity\EntityInterface;
7 use Drupal\layout_builder\Section;
8
9 /**
10  * Provides storage for entity view display entities that have layouts.
11  *
12  * @internal
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.
16  */
17 class LayoutBuilderEntityViewDisplayStorage extends ConfigEntityStorage {
18
19   /**
20    * {@inheritdoc}
21    */
22   protected function mapToStorageRecord(EntityInterface $entity) {
23     $record = parent::mapToStorageRecord($entity);
24
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']);
29     }
30     return $record;
31   }
32
33   /**
34    * {@inheritdoc}
35    */
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);
41       }
42     }
43     return parent::mapFromStorageRecords($records);
44   }
45
46 }