simple_page_manager-1.0.0-alpha1/src/PageStorage.php

src/PageStorage.php
<?php

namespace Drupal\simple_page_manager;

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

/**
 * Page storage.
 *
 * @internal
 *   Entity handlers are internal.
 */
class PageStorage extends ConfigEntityStorage {

  /**
   * {@inheritdoc}
   */
  protected function mapToStorageRecord(EntityInterface $entity) {
    $record = parent::mapToStorageRecord($entity);

    if (!empty($record['sections'])) {
      $record['sections'] = array_map(function (Section $section) {
        return $section->toArray();
      }, $record['sections']);
    }
    return $record;
  }

  /**
   * {@inheritdoc}
   */
  protected function mapFromStorageRecords(array $records) {
    foreach ($records as $id => &$record) {
      if (!empty($record['sections'])) {
        $sections = &$record['sections'];
        $sections = array_map([Section::class, 'fromArray'], $sections);
      }
    }
    return parent::mapFromStorageRecords($records);
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc