diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php index a4884d3..204e7e2 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php @@ -166,7 +166,7 @@ protected function doLoadMultiple(array $ids = NULL) { // Load all of the configuration entities. $records = array(); foreach ($this->configFactory->loadMultiple($names) as $config) { - $records[$config->get($this->idKey)] = $config->get(); + $records[$config->get($this->idKey)] = $this->postLoadData($config->get()); } return $this->mapFromStorageRecords($records); } @@ -256,7 +256,20 @@ protected function doSave($id, EntityInterface $entity) { * @return array * Data to save with any modifications necessary for storage performed. */ - protected function preSaveData($data, EntityInterface $entity) { + protected function preSaveData(array $data, EntityInterface $entity) { + return $data; + } + + /** + * Alter data from the storage environment right after loading. + * + * @param array $data + * Raw configuration data as loaded. + * + * @return array + * Transformed data with any modifications necessary for instantiation. + */ + protected function postLoadData(array $data) { return $data; } diff --git a/core/lib/Drupal/Core/Field/FieldItemBase.php b/core/lib/Drupal/Core/Field/FieldItemBase.php index 114b2ee..8ab3ad6 100644 --- a/core/lib/Drupal/Core/Field/FieldItemBase.php +++ b/core/lib/Drupal/Core/Field/FieldItemBase.php @@ -258,21 +258,11 @@ public function instanceSettingsForm(array $form, array &$form_state) { /** * {@inheritdoc} */ - public function preSaveSettings(array &$settings) { } + public static function preSaveSettings(array &$settings) { } /** * {@inheritdoc} */ - public function postLoadSettings(array &$settings) { } - - /** - * {@inheritdoc} - */ - public function preSaveInstanceSettings(array &$settings) { } - - /** - * {@inheritdoc} - */ - public function postLoadInstanceSettings(array &$settings) { } + public static function postLoadSettings(array &$settings) { } } diff --git a/core/lib/Drupal/Core/Field/FieldItemInterface.php b/core/lib/Drupal/Core/Field/FieldItemInterface.php index d70d366..f63d36a 100644 --- a/core/lib/Drupal/Core/Field/FieldItemInterface.php +++ b/core/lib/Drupal/Core/Field/FieldItemInterface.php @@ -190,7 +190,7 @@ public function preSave(); * @param array $settings * Field settings. */ - public function preSaveSettings(array &$settings); + public static function preSaveSettings(array &$settings); /** * Defines custom behavior for transforming field settings when loading. @@ -201,28 +201,7 @@ public function preSaveSettings(array &$settings); * @param array $settings * Field settings. */ - public function postLoadSettings(array &$settings); - - /** - * Defines behavior for transforming instance settings before being saved. - * - * May be used to alter settings to transform them to a storage-friendly form. - * - * @param array $settings - * Field settings. - */ - public function preSaveInstanceSettings(array &$settings); - - /** - * Defines custom behavior for transforming instance settings when loading. - * - * May be used to alter settings to transform them from a storage-friendly - * form. - * - * @param array $settings - * Field settings. - */ - public function postLoadInstanceSettings(array &$settings); + public static function postLoadSettings(array &$settings); /** * Defines custom insert behavior for field values. diff --git a/core/modules/field/src/Entity/FieldConfig.php b/core/modules/field/src/Entity/FieldConfig.php index a135d64..3143cb0 100644 --- a/core/modules/field/src/Entity/FieldConfig.php +++ b/core/modules/field/src/Entity/FieldConfig.php @@ -727,7 +727,7 @@ public function getUniqueStorageIdentifier() { /** * Helper to retrieve the field item class. */ - public function getFieldItemClass() { + protected function getFieldItemClass() { $type_definition = \Drupal::typedDataManager() ->getDefinition('field_item:' . $this->getType()); return $type_definition['class']; diff --git a/core/modules/field/src/FieldConfigStorage.php b/core/modules/field/src/FieldConfigStorage.php index 76566c9..77d0daa 100644 --- a/core/modules/field/src/FieldConfigStorage.php +++ b/core/modules/field/src/FieldConfigStorage.php @@ -161,30 +161,22 @@ public function loadByProperties(array $conditions = array()) { /** * {@inheritdoc} */ - protected function postLoad(array &$entities) { - foreach ($entities as $entity) { - // @todo This needs to modify the entity, so works off of the entity - // settings as it believes at the same. Because this came from storage - // it would technically be the same as the output of preSaveData() but - // philosophically it feels far from it. - if (is_array($entity->settings)) { - $field_class = $entity->getFieldItemClass(); - $field_class::postLoadSettings($entity->settings); - } - } - - parent::postLoad($entities); + protected function postLoadData(array $data) { + // @todo Makes too much assumptions but it needs to. + $type_definition = \Drupal::typedDataManager() + ->getDefinition('field_item:' . $data['type']); + $type_definition['class']::postLoadSettings($data['settings']); + return $data; } /** * {@inheritdoc} */ - protected function preSaveData($data, EntityInterface $entity) { - // @todo This looks ugly as it assumes a settings key which is not codified - // on this level otherwise. Also this works in a very different level, - // not using the entity anymore to avoid modifying it vs. load. - $field_class = $entity->getFieldItemClass(); - $data['settings'] = $field_class::preSaveSettings($data['settings']); + protected function preSaveData(array $data, EntityInterface $entity) { + // @todo Makes too much assumptions but it needs to. + $type_definition = \Drupal::typedDataManager() + ->getDefinition('field_item:' . $data['type']); + $type_definition['class']::preSaveSettings($data['settings']); return $data; } diff --git a/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php b/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php index 9451ba2..f63b17f 100644 --- a/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php +++ b/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php @@ -240,7 +240,7 @@ protected function allowedValuesString($values) { /** * Defined in \Drupal\Core\Field\FieldItemInterface. */ - public function preSaveSettings(array &$settings) { + public static function preSaveSettings(array &$settings) { if (isset($settings['allowed_values'])) { $settings['allowed_values'] = static::structureAllowedValues($settings['allowed_values']); } @@ -249,7 +249,7 @@ public function preSaveSettings(array &$settings) { /** * Defined in \Drupal\Core\Field\FieldItemInterface. */ - public function postLoadSettings(array &$settings) { + public static function postLoadSettings(array &$settings) { if (isset($settings['allowed_values'])) { $settings['allowed_values'] = static::simplifyAllowedValues($settings['allowed_values']); }