diff -u b/core/modules/field/field.crud.inc b/core/modules/field/field.crud.inc --- b/core/modules/field/field.crud.inc +++ b/core/modules/field/field.crud.inc @@ -169,10 +169,13 @@ // Conditions. foreach ($params as $key => $value) { if ($key == 'storage.active') { - $checked_value = $field['storage']['active']; + $checked_value = $field->storage['active']; + } + else if($key == 'field_name') { + $checked_value = $field->id; } else { - $checked_value = $field[$key]; + $checked_value = $field->$key; } if ($checked_value != $value) { continue 2; @@ -182,11 +185,8 @@ // Invoke read field. module_invoke_all('field_read_field', $field); - $field_name = $field['field_name']; - if ($include_deleted) { - $field_name = $field['uuid']; - } - $fields[$field_name] = $field; + $key = $include_deleted ? $field->uuid : $field->id; + $fields[$key] = $field; } return $fields; } diff -u b/core/modules/field/lib/Drupal/field/FieldInfo.php b/core/modules/field/lib/Drupal/field/FieldInfo.php --- b/core/modules/field/lib/Drupal/field/FieldInfo.php +++ b/core/modules/field/lib/Drupal/field/FieldInfo.php @@ -146,7 +146,7 @@ foreach (config_get_storage_names_with_prefix('field.field') as $config_id) { $field_config = config($config_id)->get(); if ($field_config['active'] && $field_config['storage']['active']) { - $fields[$field_config['field_name']] = $field_config; + $fields[$field_config['id']] = $field_config; } } // Get field instances. @@ -197,7 +197,7 @@ // Fill the name/ID map. foreach ($this->fieldsById as $field) { if (!$field['deleted']) { - $this->fieldIdsByName[$field['field_name']] = $field['uuid']; + $this->fieldIdsByName[$field['id']] = $field['uuid']; } } diff -u b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php --- b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php @@ -48,13 +48,6 @@ public $uuid; /** - * The field name. - * - * @var string - */ - public $field_name; - - /** * The field type. * * @var string @@ -153,14 +146,18 @@ if (empty($values['type'])) { throw new FieldException('Attempt to create a field with no type.'); } - if (empty($values['field_name'])) { + if (empty($values['field_name']) && empty($values['id'])) { throw new FieldException('Attempt to create an unnamed field.'); } - if (!preg_match('/^[_a-z]+[_a-z0-9]*$/', $values['field_name'])) { + // Temporary BC layer: accept both 'id' and 'field_name'. + if (empty($values['id'])) { + $values['id'] = $values['field_name']; + unset($values['field_name']); + } + if (!preg_match('/^[_a-z]+[_a-z0-9]*$/', $values['id'])) { throw new FieldException('Attempt to create a field with invalid characters. Only lowercase alphanumeric characters and underscores are allowed, and only lowercase letters and underscore are allowed as the first character'); } - $this->id = $values['field_name']; // Provide defaults. $values += array( @@ -185,7 +182,6 @@ 'uuid', 'status', 'langcode', - 'field_name', 'type', 'settings', 'module', @@ -217,18 +213,18 @@ // Field name cannot be longer than 32 characters. We use drupal_strlen() // because the DB layer assumes that column widths are given in characters, // not bytes. - if (drupal_strlen($this->field_name) > 32) { - throw new FieldException(t('Attempt to create a field with a name longer than 32 characters: %name', - array('%name' => $this->field_name))); + if (drupal_strlen($this->id) > 32) { + throw new FieldException(t('Attempt to create a field with an ID longer than 32 characters: %id', + array('%id' => $this->id))); } // Ensure the field name is unique over active and disabled fields. // We do not care about deleted fields. - $prior_field = field_read_field($this->field_name, array('include_inactive' => TRUE)); + $prior_field = field_read_field($this->id, array('include_inactive' => TRUE)); if (!empty($prior_field)) { $message = $prior_field->active ? - t('Attempt to create field name %name which already exists and is active.', array('%name' => $this->field_name)): - t('Attempt to create field name %name which already exists, although it is inactive.', array('%name' => $this->field_name)); + t('Attempt to create field %id which already exists and is active.', array('%id' => $this->id)): + t('Attempt to create field %id which already exists, although it is inactive.', array('%id' => $this->id)); throw new FieldException($message); } @@ -236,8 +232,8 @@ // collisions with existing entity properties, but some is better // than none. foreach (\Drupal::service('plugin.manager.entity')->getDefinitions() as $type => $info) { - if (in_array($this->field_name, $info['entity_keys'])) { - throw new FieldException(t('Attempt to create field name %name which is reserved by entity type %type.', array('%name' => $this->field_name, '%type' => $type))); + if (in_array($this->id, $info['entity_keys'])) { + throw new FieldException(t('Attempt to create field %id which is reserved by entity type %type.', array('%id' => $this->id, '%type' => $type))); } } @@ -328,7 +324,7 @@ foreach ($bundles as $bundle) { // We need to get inactive instances too (e.g. the entity type is not // known anymore - case of comment.module being uninstalled). - $instance = field_read_instance($entity_type, $this->field_name, $bundle, array('include_inactive' => TRUE)); + $instance = field_read_instance($entity_type, $this->id, $bundle, array('include_inactive' => TRUE)); field_delete_instance($instance, FALSE); } } @@ -404,8 +400,8 @@ public function getBundles() { if (empty($this->deleted)) { $map = field_info_field_map(); - if (isset($map[$this->field_name]['bundles'])) { - return $map[$this->field_name]['bundles']; + if (isset($map[$this->id]['bundles'])) { + return $map[$this->id]['bundles']; } } return array(); @@ -423,6 +419,9 @@ */ public function &offsetGet($offset) { switch ($offset) { + case 'field_name': + return $this->id; + case 'columns': $this->getSchema(); return $this->schema['columns']; diff -u b/core/modules/field/tests/modules/field_test_config/config/field.field.field_test_import.yml b/core/modules/field/tests/modules/field_test_config/config/field.field.field_test_import.yml --- b/core/modules/field/tests/modules/field_test_config/config/field.field.field_test_import.yml +++ b/core/modules/field/tests/modules/field_test_config/config/field.field.field_test_import.yml @@ -1,7 +1,6 @@ id: field_test_import uuid: fb38277f-1fd4-49d5-8d09-9d7037fdcce9 langcode: und -field_name: field_test_import type: text settings: max_length: '255' diff -u b/core/modules/field/tests/modules/field_test_config/staging/field.field.field_test_import_staging.yml b/core/modules/field/tests/modules/field_test_config/staging/field.field.field_test_import_staging.yml --- b/core/modules/field/tests/modules/field_test_config/staging/field.field.field_test_import_staging.yml +++ b/core/modules/field/tests/modules/field_test_config/staging/field.field.field_test_import_staging.yml @@ -1,7 +1,6 @@ id: field_test_import_staging uuid: 0bf654cc-f14a-4881-b94c-76959e47466b langcode: und -field_name: field_test_import_staging type: text settings: max_length: '255'