Commit 74f94352 authored by alexpott's avatar alexpott

Issue #2437785 by amateescu: FieldConfigStorageBase::mapToStorageRecord()...

Issue #2437785 by amateescu: FieldConfigStorageBase::mapToStorageRecord() calls the wrong field type method
parent a20bad73
......@@ -39,7 +39,7 @@ protected function mapFromStorageRecords(array $records) {
protected function mapToStorageRecord(EntityInterface $entity) {
$record = parent::mapToStorageRecord($entity);
$class = $this->fieldTypeManager->getPluginClass($record['field_type']);
$record['settings'] = $class::fieldSettingsFromConfigData($record['settings']);
$record['settings'] = $class::fieldSettingsToConfigData($record['settings']);
return $record;
}
......
......@@ -75,12 +75,24 @@ function testCreateField() {
$field = entity_create('field_config', $this->fieldDefinition);
$field->save();
$field = FieldConfig::load($field->id());
$this->assertTrue($field->getSetting('field_setting_from_config_data'));
$this->assertNull($field->getSetting('config_data_from_field_setting'));
// Read the configuration. Check against raw configuration data rather than
// the loaded ConfigEntity, to be sure we check that the defaults are
// applied on write.
$config = $this->config('field.field.' . $field->id())->get();
$field_type_manager = \Drupal::service('plugin.manager.field.field_type');
$this->assertTrue($config['settings']['config_data_from_field_setting']);
$this->assertTrue(!isset($config['settings']['field_setting_from_config_data']));
// Since we are working with raw configuration, this needs to be unset
// manually.
// @see Drupal\field_test\Plugin\Field\FieldType\TestItem::fieldSettingsFromConfigData()
unset($config['settings']['config_data_from_field_setting']);
// Check that default values are set.
$this->assertEqual($config['required'], FALSE, 'Required defaults to false.');
$this->assertIdentical($config['label'], $this->fieldDefinition['field_name'], 'Label defaults to field name.');
......
......@@ -44,6 +44,11 @@ function testCreate() {
field_test_memorize();
$field_storage = entity_create('field_storage_config', $field_storage_definition);
$field_storage->save();
$field_storage = FieldStorageConfig::load($field_storage->id());
$this->assertTrue($field_storage->getSetting('storage_setting_from_config_data'));
$this->assertNull($field_storage->getSetting('config_data_from_storage_setting'));
$mem = field_test_memorize();
$this->assertIdentical($mem['field_test_field_storage_config_create'][0][0]->getName(), $field_storage_definition['field_name'], 'hook_entity_create() called with correct arguments.');
$this->assertIdentical($mem['field_test_field_storage_config_create'][0][0]->getType(), $field_storage_definition['type'], 'hook_entity_create() called with correct arguments.');
......@@ -53,6 +58,14 @@ function testCreate() {
// applied on write.
$field_storage_config = $this->config('field.storage.' . $field_storage->id())->get();
$this->assertTrue($field_storage_config['settings']['config_data_from_storage_setting']);
$this->assertTrue(!isset($field_storage_config['settings']['storage_setting_from_config_data']));
// Since we are working with raw configuration, this needs to be unset
// manually.
// @see Drupal\field_test\Plugin\Field\FieldType\TestItem::storageSettingsFromConfigData()
unset($field_storage_config['settings']['config_data_from_storage_setting']);
// Ensure that basic properties are preserved.
$this->assertEqual($field_storage_config['field_name'], $field_storage_definition['field_name'], 'The field name is properly saved.');
$this->assertEqual($field_storage_config['entity_type'], $field_storage_definition['entity_type'], 'The field entity type is properly saved.');
......
......@@ -62,6 +62,9 @@ field.storage_settings.test_field:
unchangeable:
type: string
label: 'An unchangeable field storage setting'
config_data_from_storage_setting:
type: boolean
label: 'Test FieldItemInterface::storageSettingsToConfigData()'
field.storage_settings.test_field_with_dependencies:
type: field.storage_settings.test_field
......@@ -78,6 +81,9 @@ field.field_settings.test_field:
test_field_setting:
type: string
label: 'Test field setting'
config_data_from_field_setting:
type: boolean
label: 'Test FieldItemInterface::fieldSettingsToConfigData()'
field.field_settings.test_field_with_dependencies:
type: field.field_settings.test_field
......
......@@ -137,4 +137,40 @@ public function isEmpty() {
return empty($this->value);
}
/**
* {@inheritdoc}
*/
public static function storageSettingsToConfigData(array $settings) {
$settings['config_data_from_storage_setting'] = 'TRUE';
unset($settings['storage_setting_from_config_data']);
return $settings;
}
/**
* {@inheritdoc}
*/
public static function storageSettingsFromConfigData(array $settings) {
$settings['storage_setting_from_config_data'] = 'TRUE';
unset($settings['config_data_from_storage_setting']);
return $settings;
}
/**
* {@inheritdoc}
*/
public static function fieldSettingsToConfigData(array $settings) {
$settings['config_data_from_field_setting'] = 'TRUE';
unset($settings['field_setting_from_config_data']);
return $settings;
}
/**
* {@inheritdoc}
*/
public static function fieldSettingsFromConfigData(array $settings) {
$settings['field_setting_from_config_data'] = 'TRUE';
unset($settings['config_data_from_field_setting']);
return $settings;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment