LayoutBuilderEntityViewDisplayStorage.php

Same filename in other branches
  1. 9 core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplayStorage.php
  2. 10 core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplayStorage.php
  3. 11.x core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplayStorage.php

Namespace

Drupal\layout_builder\Entity

File

core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplayStorage.php

View source
<?php

namespace Drupal\layout_builder\Entity;

use Drupal\Core\Config\Entity\ConfigEntityStorage;
use Drupal\Core\Entity\EntityInterface;
use Drupal\layout_builder\Section;

/**
 * Provides storage for entity view display entities that have layouts.
 *
 * @internal
 *   Entity handlers are internal.
 */
class LayoutBuilderEntityViewDisplayStorage extends ConfigEntityStorage {
    
    /**
     * {@inheritdoc}
     */
    protected function mapToStorageRecord(EntityInterface $entity) {
        $record = parent::mapToStorageRecord($entity);
        if (!empty($record['third_party_settings']['layout_builder']['sections'])) {
            $record['third_party_settings']['layout_builder']['sections'] = array_map(function (Section $section) {
                return $section->toArray();
            }, $record['third_party_settings']['layout_builder']['sections']);
        }
        return $record;
    }
    
    /**
     * {@inheritdoc}
     */
    protected function mapFromStorageRecords(array $records) {
        foreach ($records as $id => &$record) {
            if (!empty($record['third_party_settings']['layout_builder']['sections'])) {
                $sections =& $record['third_party_settings']['layout_builder']['sections'];
                $sections = array_map([
                    Section::class,
                    'fromArray',
                ], $sections);
            }
        }
        return parent::mapFromStorageRecords($records);
    }

}

Classes

Title Deprecated Summary
LayoutBuilderEntityViewDisplayStorage Provides storage for entity view display entities that have layouts.

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