FieldConfigStorageBase.php 1.14 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
<?php

/**
 * @file
 * Contains \Drupal\Core\Field\FieldConfigStorageBase.
 */

namespace Drupal\Core\Field;

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

/**
 * Base storage class for field config entities.
 */
abstract class FieldConfigStorageBase extends ConfigEntityStorage {

  /**
   * The field type plugin manager.
   *
   * @var \Drupal\Core\Field\FieldTypePluginManagerInterface
   */
  protected $fieldTypeManager;

  /**
   * {@inheritdoc}
   */
  protected function mapFromStorageRecords(array $records) {
    foreach ($records as &$record) {
      $class = $this->fieldTypeManager->getPluginClass($record['field_type']);
31
      $record['settings'] = $class::fieldSettingsFromConfigData($record['settings']);
32 33 34 35 36 37 38 39 40 41
    }
    return parent::mapFromStorageRecords($records);
  }

  /**
   * {@inheritdoc}
   */
  protected function mapToStorageRecord(EntityInterface $entity) {
    $record = parent::mapToStorageRecord($entity);
    $class = $this->fieldTypeManager->getPluginClass($record['field_type']);
42
    $record['settings'] = $class::fieldSettingsFromConfigData($record['settings']);
43 44 45 46
    return $record;
  }

}