Upgraded drupal core with security updates
[yaffs-website] / web / core / lib / Drupal / Core / Field / FieldConfigStorageBase.php
1 <?php
2
3 namespace Drupal\Core\Field;
4
5 use Drupal\Core\Config\Entity\ConfigEntityStorage;
6 use Drupal\Core\Entity\EntityInterface;
7
8 /**
9  * Base storage class for field config entities.
10  */
11 abstract class FieldConfigStorageBase extends ConfigEntityStorage {
12
13   /**
14    * The field type plugin manager.
15    *
16    * @var \Drupal\Core\Field\FieldTypePluginManagerInterface
17    */
18   protected $fieldTypeManager;
19
20   /**
21    * {@inheritdoc}
22    */
23   protected function mapFromStorageRecords(array $records) {
24     foreach ($records as $id => &$record) {
25       $class = $this->fieldTypeManager->getPluginClass($record['field_type']);
26       if (empty($class)) {
27         $config_id = $this->getPrefix() . $id;
28         throw new \RuntimeException("Unable to determine class for field type '{$record['field_type']}' found in the '$config_id' configuration");
29       }
30       $record['settings'] = $class::fieldSettingsFromConfigData($record['settings']);
31     }
32     return parent::mapFromStorageRecords($records);
33   }
34
35   /**
36    * {@inheritdoc}
37    */
38   protected function mapToStorageRecord(EntityInterface $entity) {
39     $record = parent::mapToStorageRecord($entity);
40     $class = $this->fieldTypeManager->getPluginClass($record['field_type']);
41     $record['settings'] = $class::fieldSettingsToConfigData($record['settings']);
42     return $record;
43   }
44
45 }