Commit 42024826 authored by alexpott's avatar alexpott

Issue #2344821 by yched: Unify 'name' / 'field_name' in FieldConfig / FieldStorageConfig.

parent 035393d8
......@@ -81,7 +81,7 @@ function block_content_add_body_field($block_type_id, $label = 'Body') {
$field = FieldConfig::loadByName('block_content', $block_type_id, 'body');
if (empty($field_storage)) {
$field_storage = entity_create('field_storage_config', array(
'name' => 'body',
'field_name' => 'body',
'entity_type' => 'block_content',
'type' => 'text_with_summary',
));
......
......@@ -55,7 +55,7 @@ public function testBlockFields() {
// Create a field with settings to validate.
$this->fieldStorage = entity_create('field_storage_config', array(
'name' => drupal_strtolower($this->randomMachineName()),
'field_name' => drupal_strtolower($this->randomMachineName()),
'entity_type' => 'block_content',
'type' => 'link',
'cardinality' => 2,
......
......@@ -145,7 +145,7 @@ public function addDefaultField($entity_type, $bundle, $field_name = 'comment',
// Add a default comment field for existing node comments.
$field_storage = $this->entityManager->getStorage('field_storage_config')->create(array(
'entity_type' => $entity_type,
'name' => $field_name,
'field_name' => $field_name,
'type' => 'comment',
'translatable' => TRUE,
'settings' => array(
......@@ -221,7 +221,7 @@ public function addBodyField($comment_type_id) {
$field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
if (!$field_storage) {
$field_storage = $this->entityManager->getStorage('field_storage_config')->create(array(
'name' => 'comment_body',
'field_name' => 'comment_body',
'type' => 'text_long',
'entity_type' => 'comment',
));
......
......@@ -51,7 +51,7 @@ public function testCommentFieldNonStringId() {
));
$bundle->save();
$field_storage = entity_create('field_storage_config', array(
'name' => 'foo',
'field_name' => 'foo',
'entity_type' => 'entity_test_string_id',
'settings' => array(
'comment_type' => 'entity_test_string_id',
......
......@@ -48,7 +48,7 @@ public function testValidation() {
// Add comment field to content.
$this->entityManager->getStorage('field_storage_config')->create(array(
'entity_type' => 'node',
'name' => 'comment',
'field_name' => 'comment',
'type' => 'comment',
'settings' => array(
'comment_type' => 'comment',
......
......@@ -46,9 +46,9 @@ function setUp() {
// Make the comment body field translatable. The title is already
// translatable by definition.
$field = FieldStorageConfig::loadByName('comment', 'comment_body');
$field->translatable = TRUE;
$field->save();
$field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
$field_storage->translatable = TRUE;
$field_storage->save();
// Set up comment titles.
$this->comment_titles = array(
......
......@@ -65,7 +65,7 @@ public function testExportImport() {
// Create a field.
$this->fieldName = drupal_strtolower($this->randomMachineName());
$this->fieldStorage = entity_create('field_storage_config', array(
'name' => $this->fieldName,
'field_name' => $this->fieldName,
'entity_type' => 'node',
'type' => 'text',
));
......@@ -104,7 +104,7 @@ public function testExportImport() {
}
$field_storages = entity_load_multiple('field_storage_config');
foreach ($field_storages as $field_storage) {
if ($field_storage->name == $this->fieldName) {
if ($field_storage->field_name == $this->fieldName) {
$field_storage->delete();
}
}
......
......@@ -34,7 +34,7 @@ protected function setUp() {
parent::setUp();
$this->field_storage = entity_create('field_storage_config', array(
'name' => strtolower($this->randomMachineName()),
'field_name' => strtolower($this->randomMachineName()),
'entity_type' => 'contact_message',
'type' => 'text'
));
......
......@@ -80,7 +80,7 @@ protected function setUp() {
// Add a translatable field to the content type.
entity_create('field_storage_config', array(
'name' => 'field_test_text',
'field_name' => 'field_test_text',
'entity_type' => 'node',
'type' => 'text',
'cardinality' => 1,
......
......@@ -228,7 +228,7 @@ function testFieldTranslatableSettingsUI() {
// At least one field needs to be translatable to enable article for
// translation. Create an extra field to be used for this purpose.
$field_storage = array(
'name' => 'article_text',
'field_name' => 'article_text',
'entity_type' => 'node',
'type' => 'text',
);
......
......@@ -50,7 +50,7 @@ protected function setupTestFields() {
$this->cardinality = 3;
entity_create('field_storage_config', array(
'name' => $this->fieldName,
'field_name' => $this->fieldName,
'entity_type' => $this->entityTypeId,
'type' => 'image',
'cardinality' => $this->cardinality,
......
......@@ -179,7 +179,7 @@ protected function setupTestFields() {
$this->fieldName = 'field_test_et_ui_test';
}
entity_create('field_storage_config', array(
'name' => $this->fieldName,
'field_name' => $this->fieldName,
'type' => 'string',
'entity_type' => $this->entityTypeId,
'cardinality' => 1,
......
......@@ -52,8 +52,9 @@ protected function setUp() {
$this->drupalLogin($web_user);
// Create a field with settings to validate.
$field_name = drupal_strtolower($this->randomMachineName());
$this->fieldStorage = entity_create('field_storage_config', array(
'name' => drupal_strtolower($this->randomMachineName()),
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'datetime',
'settings' => array('datetime_type' => 'date'),
......@@ -67,7 +68,7 @@ protected function setUp() {
$this->field->save();
entity_get_form_display($this->field->entity_type, $this->field->bundle, 'default')
->setComponent($this->fieldStorage->name, array(
->setComponent($field_name, array(
'type' => 'datetime_default',
))
->save();
......@@ -78,7 +79,7 @@ protected function setUp() {
'settings' => array('format_type' => 'medium'),
);
entity_get_display($this->field->entity_type, $this->field->bundle, 'full')
->setComponent($this->fieldStorage->name, $this->display_options)
->setComponent($field_name, $this->display_options)
->save();
}
......@@ -86,7 +87,7 @@ protected function setUp() {
* Tests date field functionality.
*/
function testDateField() {
$field_name = $this->fieldStorage->name;
$field_name = $this->fieldStorage->field_name;
// Display creation form.
$this->drupalGet('entity_test/add');
......@@ -151,7 +152,7 @@ function testDateField() {
* Tests date and time field.
*/
function testDatetimeField() {
$field_name = $this->fieldStorage->name;
$field_name = $this->fieldStorage->getName();
// Change the field to a datetime field.
$this->fieldStorage->settings['datetime_type'] = 'datetime';
$this->fieldStorage->save();
......@@ -216,7 +217,7 @@ function testDatetimeField() {
* Tests Date List Widget functionality.
*/
function testDatelistWidget() {
$field_name = $this->fieldStorage->name;
$field_name = $this->fieldStorage->getName();
// Change the field to a datetime field.
$this->fieldStorage->settings['datetime_type'] = 'datetime';
$this->fieldStorage->save();
......@@ -282,8 +283,9 @@ function testDefaultValue() {
$this->drupalCreateContentType(array('type' => 'date_content'));
// Create a field storage with settings to validate.
$field_name = drupal_strtolower($this->randomMachineName());
$field_storage = entity_create('field_storage_config', array(
'name' => drupal_strtolower($this->randomMachineName()),
'field_name' => $field_name,
'entity_type' => 'node',
'type' => 'datetime',
'settings' => array('datetime_type' => 'date'),
......@@ -300,15 +302,15 @@ function testDefaultValue() {
$field_edit = array(
'default_value_input[default_date_type]' => 'now',
);
$this->drupalPostForm('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name, $field_edit, t('Save settings'));
$this->drupalPostForm('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_name, $field_edit, t('Save settings'));
// Check that default value is selected in default value form.
$this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name);
$this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_name);
$this->assertOptionSelected('edit-default-value-input-default-date-type', 'now', 'The default value is selected in instance settings page');
$this->assertFieldByName('default_value_input[default_date]', '', 'The relative default value is empty in instance settings page');
// Check if default_date has been stored successfully.
$config_entity = $this->container->get('config.factory')->get('field.field.node.date_content.' . $field_storage->name)->get();
$config_entity = $this->container->get('config.factory')->get('field.field.node.date_content.' . $field_name)->get();
$this->assertEqual($config_entity['default_value'][0], array('default_date_type' => 'now', 'default_date' => 'now'), 'Default value has been stored successfully');
// Clear field cache in order to avoid stale cache values.
......@@ -317,14 +319,14 @@ function testDefaultValue() {
// Create a new node to check that datetime field default value is today.
$new_node = entity_create('node', array('type' => 'date_content'));
$expected_date = new DrupalDateTime('now', DATETIME_STORAGE_TIMEZONE);
$this->assertEqual($new_node->get($field_storage->name)->offsetGet(0)->value, $expected_date->format(DATETIME_DATE_STORAGE_FORMAT));
$this->assertEqual($new_node->get($field_name)->offsetGet(0)->value, $expected_date->format(DATETIME_DATE_STORAGE_FORMAT));
// Set an invalid relative default_value to test validation.
$field_edit = array(
'default_value_input[default_date_type]' => 'relative',
'default_value_input[default_date]' => 'invalid date',
);
$this->drupalPostForm('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name, $field_edit, t('Save settings'));
$this->drupalPostForm('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_name, $field_edit, t('Save settings'));
$this->assertText('The relative date value entered is invalid.');
......@@ -333,15 +335,15 @@ function testDefaultValue() {
'default_value_input[default_date_type]' => 'relative',
'default_value_input[default_date]' => '+90 days',
);
$this->drupalPostForm('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name, $field_edit, t('Save settings'));
$this->drupalPostForm('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_name, $field_edit, t('Save settings'));
// Check that default value is selected in default value form.
$this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name);
$this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_name);
$this->assertOptionSelected('edit-default-value-input-default-date-type', 'relative', 'The default value is selected in instance settings page');
$this->assertFieldByName('default_value_input[default_date]', '+90 days', 'The relative default value is displayed in instance settings page');
// Check if default_date has been stored successfully.
$config_entity = $this->container->get('config.factory')->get('field.field.node.date_content.' . $field_storage->name)->get();
$config_entity = $this->container->get('config.factory')->get('field.field.node.date_content.' . $field_name)->get();
$this->assertEqual($config_entity['default_value'][0], array('default_date_type' => 'relative', 'default_date' => '+90 days'), 'Default value has been stored successfully');
// Clear field cache in order to avoid stale cache values.
......@@ -350,21 +352,21 @@ function testDefaultValue() {
// Create a new node to check that datetime field default value is +90 days.
$new_node = entity_create('node', array('type' => 'date_content'));
$expected_date = new DrupalDateTime('+90 days', DATETIME_STORAGE_TIMEZONE);
$this->assertEqual($new_node->get($field_storage->name)->offsetGet(0)->value, $expected_date->format(DATETIME_DATE_STORAGE_FORMAT));
$this->assertEqual($new_node->get($field_name)->offsetGet(0)->value, $expected_date->format(DATETIME_DATE_STORAGE_FORMAT));
// Remove default value.
$field_edit = array(
'default_value_input[default_date_type]' => '',
);
$this->drupalPostForm('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name, $field_edit, t('Save settings'));
$this->drupalPostForm('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_name, $field_edit, t('Save settings'));
// Check that default value is selected in default value form.
$this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name);
$this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_name);
$this->assertOptionSelected('edit-default-value-input-default-date-type', '', 'The default value is selected in instance settings page');
$this->assertFieldByName('default_value_input[default_date]', '', 'The relative default value is empty in instance settings page');
// Check if default_date has been stored successfully.
$config_entity = $this->container->get('config.factory')->get('field.field.node.date_content.' . $field_storage->name)->get();
$config_entity = $this->container->get('config.factory')->get('field.field.node.date_content.' . $field_name)->get();
$this->assertTrue(empty($config_entity['default_value']), 'Empty default value has been stored successfully');
// Clear field cache in order to avoid stale cache values.
......@@ -372,7 +374,7 @@ function testDefaultValue() {
// Create a new node to check that datetime field default value is not set.
$new_node = entity_create('node', array('type' => 'date_content'));
$this->assertNull($new_node->get($field_storage->name)->offsetGet(0)->value, 'Default value is not set');
$this->assertNull($new_node->get($field_name)->offsetGet(0)->value, 'Default value is not set');
}
/**
......@@ -383,7 +385,7 @@ function testInvalidField() {
// Change the field to a datetime field.
$this->fieldStorage->settings['datetime_type'] = 'datetime';
$this->fieldStorage->save();
$field_name = $this->fieldStorage->name;
$field_name = $this->fieldStorage->getName();
// Display creation form.
$this->drupalGet('entity_test/add');
......
......@@ -30,7 +30,7 @@ protected function setUp() {
// Create a field with settings to validate.
$field_storage = entity_create('field_storage_config', array(
'name' => 'field_datetime',
'field_name' => 'field_datetime',
'type' => 'datetime',
'entity_type' => 'entity_test',
'settings' => array('datetime_type' => 'date'),
......
......@@ -205,24 +205,19 @@ function entity_reference_query_entity_reference_alter(AlterableInterface $query
*/
function entity_reference_create_field($entity_type, $bundle, $field_name, $field_label, $target_entity_type, $selection_handler = 'default', $selection_handler_settings = array(), $cardinality = 1) {
// Look for or add the specified field to the requested entity bundle.
$field_storage = FieldStorageConfig::loadByName($entity_type, $field_name);
$field = FieldConfig::loadByName($entity_type, $bundle, $field_name);
if (empty($field_storage)) {
$field_storage = array(
'name' => $field_name,
if (!FieldStorageConfig::loadByName($entity_type, $field_name)) {
entity_create('field_storage_config', array(
'field_name' => $field_name,
'type' => 'entity_reference',
'entity_type' => $entity_type,
'cardinality' => $cardinality,
'settings' => array(
'target_type' => $target_entity_type,
),
);
entity_create('field_storage_config', $field_storage)->save();
))->save();
}
if (empty($field)) {
$field = array(
if (!FieldConfig::loadByName($entity_type, $bundle, $field_name)) {
entity_create('field_config', array(
'field_name' => $field_name,
'entity_type' => $entity_type,
'bundle' => $bundle,
......@@ -231,8 +226,7 @@ function entity_reference_create_field($entity_type, $bundle, $field_name, $fiel
'handler' => $selection_handler,
'handler_settings' => $selection_handler_settings,
),
);
entity_create('field_config', $field)->save();
))->save();
}
}
......@@ -30,7 +30,7 @@ protected function setUp() {
$this->referenced_type = $referenced->type;
entity_create('field_storage_config', array(
'name' => 'test_field',
'field_name' => 'test_field',
'entity_type' => 'node',
'translatable' => FALSE,
'entity_types' => array(),
......
......@@ -42,15 +42,16 @@ function testEntityReferenceDefaultValue() {
// Create a node to be referenced.
$referenced_node = $this->drupalCreateNode(array('type' => 'referenced_content'));
$this->fieldStorage = entity_create('field_storage_config', array(
'name' => drupal_strtolower($this->randomMachineName()),
$field_name = drupal_strtolower($this->randomMachineName());
$field_storage = entity_create('field_storage_config', array(
'field_name' => $field_name,
'entity_type' => 'node',
'type' => 'entity_reference',
'settings' => array('target_type' => 'node'),
));
$this->fieldStorage->save();
$this->field = entity_create('field_config', array(
'field_storage' => $this->fieldStorage,
$field_storage->save();
$field = entity_create('field_config', array(
'field_storage' => $field_storage,
'bundle' => 'reference_content',
'settings' => array(
'handler' => 'default',
......@@ -60,20 +61,20 @@ function testEntityReferenceDefaultValue() {
),
),
));
$this->field->save();
$field->save();
// Set created node as default_value.
$field_edit = array(
'default_value_input[' . $this->fieldStorage->name . '][0][target_id]' => $referenced_node->getTitle() . ' (' .$referenced_node->id() . ')',
'default_value_input[' . $field_name . '][0][target_id]' => $referenced_node->getTitle() . ' (' .$referenced_node->id() . ')',
);
$this->drupalPostForm('admin/structure/types/manage/reference_content/fields/node.reference_content.' . $this->fieldStorage->name, $field_edit, t('Save settings'));
$this->drupalPostForm('admin/structure/types/manage/reference_content/fields/node.reference_content.' . $field_name, $field_edit, t('Save settings'));
// Check that default value is selected in default value form.
$this->drupalGet('admin/structure/types/manage/reference_content/fields/node.reference_content.' . $this->fieldStorage->name);
$this->assertRaw('name="default_value_input[' . $this->fieldStorage->name . '][0][target_id]" value="' . $referenced_node->getTitle() .' (' .$referenced_node->id() . ')', 'The default value is selected in instance settings page');
$this->drupalGet('admin/structure/types/manage/reference_content/fields/node.reference_content.' . $field_name);
$this->assertRaw('name="default_value_input[' . $field_name . '][0][target_id]" value="' . $referenced_node->getTitle() .' (' .$referenced_node->id() . ')', 'The default value is selected in instance settings page');
// Check if the ID has been converted to UUID in config entity.
$config_entity = $this->container->get('config.factory')->get('field.field.node.reference_content.' . $this->fieldStorage->name)->get();
$config_entity = $this->container->get('config.factory')->get('field.field.node.reference_content.' . $field_name)->get();
$this->assertTrue(isset($config_entity['default_value'][0]['target_uuid']), 'Default value contains target_uuid property');
$this->assertEqual($config_entity['default_value'][0]['target_uuid'], $referenced_node->uuid(), 'Content uuid and config entity uuid are the same');
......@@ -82,7 +83,7 @@ function testEntityReferenceDefaultValue() {
// Create a new node to check that UUID has been converted to numeric ID.
$new_node = entity_create('node', array('type' => 'reference_content'));
$this->assertEqual($new_node->get($this->fieldStorage->name)->offsetGet(0)->target_id, $referenced_node->id());
$this->assertEqual($new_node->get($field_name)->offsetGet(0)->target_id, $referenced_node->id());
}
}
......@@ -61,7 +61,7 @@ protected function setUp() {
// Set up a field, so that the entity that'll be referenced bubbles up a
// cache tag when rendering it entirely.
entity_create('field_storage_config', array(
'name' => 'body',
'field_name' => 'body',
'entity_type' => $this->entityType,
'type' => 'text',
'settings' => array(),
......
......@@ -57,7 +57,7 @@ protected function assertReferenceable(FieldDefinitionInterface $field_definitio
public function testNodeHandler() {
// Create a field.
$field_storage = entity_create('field_storage_config', array(
'name' => 'test_field',
'field_name' => 'test_field',
'entity_type' => 'entity_test',
'translatable' => FALSE,
'entity_types' => array(),
......@@ -200,7 +200,7 @@ public function testNodeHandler() {
public function testUserHandler() {
// Create a field.
$field_storage = entity_create('field_storage_config', array(
'name' => 'test_field',
'field_name' => 'test_field',
'entity_type' => 'entity_test',
'translatable' => FALSE,
'settings' => array(
......@@ -344,7 +344,7 @@ public function testUserHandler() {
public function testCommentHandler() {
// Create a field.
$field_storage = entity_create('field_storage_config', array(
'name' => 'test_field',
'field_name' => 'test_field',
'entity_type' => 'entity_test',
'translatable' => FALSE,
'entity_types' => array(),
......
......@@ -32,7 +32,7 @@ protected function setUp() {
public function testSort() {
// Add text field to entity, to sort by.
entity_create('field_storage_config', array(
'name' => 'field_text',
'field_name' => 'field_text',
'entity_type' => 'node',
'type' => 'text',
'entity_types' => array('node'),
......@@ -50,7 +50,7 @@ public function testSort() {
// Create a field.
$field_storage = entity_create('field_storage_config', array(
'name' => 'test_field',
'field_name' => 'test_field',
'entity_type' => 'entity_test',
'translatable' => FALSE,
'settings' => array(
......
......@@ -55,12 +55,12 @@ protected function setUp() {
ViewTestData::createTestViews(get_class($this), array('entity_reference_test_views'));
$field_storage = FieldStorageConfig::create(array(
'entity_type' => 'entity_test',
'field_name' => 'field_test',
'type' => 'entity_reference',
'settings' => array(
'target_type' => 'entity_test',
),
'entity_type' => 'entity_test',
'name' => 'field_test',
'type' => 'entity_reference',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
));
$field_storage->save();
......
......@@ -35,7 +35,7 @@ public function testSelectionHandler() {
// Create a field.
$field_storage = entity_create('field_storage_config', array(
'name' => 'test_field',
'field_name' => 'test_field',
'entity_type' => 'entity_test',
'translatable' => FALSE,
'settings' => array(
......
......@@ -15,9 +15,9 @@ field.storage.*.*:
id:
type: string
label: 'ID'
name:
field_name:
type: string
label: 'Name'
label: 'Field name'
entity_type:
type: string
label: 'Entity type'
......
......@@ -124,15 +124,15 @@ function field_system_info_alter(&$info, Extension $file, $type) {
// It is not safe to call entity_load_multiple_by_properties() during
// maintenance mode.
if ($type == 'module' && !defined('MAINTENANCE_MODE')) {
$fields = entity_load_multiple_by_properties('field_storage_config', array('module' => $file->getName(), 'include_deleted' => TRUE));
if ($fields) {
$field_storages = entity_load_multiple_by_properties('field_storage_config', array('module' => $file->getName(), 'include_deleted' => TRUE));
if ($field_storages) {
$info['required'] = TRUE;
// Provide an explanation message (only mention pending deletions if there
// remains no actual, non-deleted fields)
$non_deleted = FALSE;
foreach ($fields as $field) {
if (empty($field->deleted)) {
foreach ($field_storages as $field_storage) {
if (empty($field_storage->deleted)) {
$non_deleted = TRUE;
break;
}
......
......@@ -21,13 +21,13 @@ function field_views_data() {
$data = array();
$module_handler = \Drupal::moduleHandler();
foreach (\Drupal::entityManager()->getStorage('field_storage_config')->loadMultiple() as $field) {
if (_field_views_get_entity_type_storage($field)) {
$result = (array) $module_handler->invoke($field->module, 'field_views_data', array($field));
foreach (\Drupal::entityManager()->getStorage('field_storage_config')->loadMultiple() as $field_storage) {
if (_field_views_get_entity_type_storage($field_storage)) {
$result = (array) $module_handler->invoke($field_storage->module, 'field_views_data', array($field_storage));
if (empty($result)) {
$result = field_views_field_default_views_data($field);
$result = field_views_field_default_views_data($field_storage);
}
$module_handler->alter('field_views_data', $result, $field);
$module_handler->alter('field_views_data', $result, $field_storage);
if (is_array($result)) {
$data = NestedArray::mergeDeep($result, $data);
......@@ -47,11 +47,11 @@ function field_views_data() {
* in field_views_data.
*/
function field_views_data_alter(&$data) {
foreach (\Drupal::entityManager()->getStorage('field_storage_config')->loadMultiple() as $field) {
if (_field_views_get_entity_type_storage($field)) {
$function = $field->module . '_field_views_data_views_data_alter';
foreach (\Drupal::entityManager()->getStorage('field_storage_config')->loadMultiple() as $field_storage) {
if (_field_views_get_entity_type_storage($field_storage)) {
$function = $field_storage->module . '_field_views_data_views_data_alter';
if (function_exists($function)) {
$function($data, $field);
$function($data, $field_storage);
}
}
}
......
......@@ -62,7 +62,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
*
* @var string
*/
public $name;
public $field_name;
/**
* The name of the entity type the field can be attached to.
......@@ -201,17 +201,17 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
*/
public function __construct(array $values, $entity_type = 'field_storage_config') {
// Check required properties.
if (empty($values['name'])) {
throw new FieldException('Attempt to create an unnamed field storage.');
if (empty($values['field_name'])) {
throw new FieldException('Attempt to create a field storage without a field name.');
}
if (!preg_match('/^[_a-z]+[_a-z0-9]*$/', $values['name'])) {
throw new FieldException(String::format('Attempt to create a field storage @field_name with invalid characters. Only lowercase alphanumeric characters and underscores are allowed, and only lowercase letters and underscore are allowed as the first character', array('@field_name' => $values['name'])));
if (!preg_match('/^[_a-z]+[_a-z0-9]*$/', $values['field_name'])) {
throw new FieldException(String::format('Attempt to create a field storage @field_name with invalid characters. Only lowercase alphanumeric characters and underscores are allowed, and only lowercase letters and underscore are allowed as the first character', array('@field_name' => $values['field_name'])));
}
if (empty($values['type'])) {
throw new FieldException(String::format('Attempt to create a field storage @field_name with no type.', array('@field_name' => $values['name'])));
throw new FieldException(String::format('Attempt to create a field storage @field_name with no type.', array('@field_name' => $values['field_name'])));
}
if (empty($values['entity_type'])) {
throw new FieldException(String::format('Attempt to create a field storage @field_name with no entity_type.', array('@field_name' => $values['name'])));
throw new FieldException(String::format('Attempt to create a field storage @field_name with no entity_type.', array('@field_name' => $values['field_name'])));
}
parent::__construct($values, $entity_type);
......@@ -221,7 +221,7 @@ public function __construct(array $values, $entity_type = 'field_storage_config'
* {@inheritdoc}
*/
public function id() {
return $this->entity_type . '.' . $this->name;
return $this->entity_type . '.' . $this->field_name;
}
/**
......@@ -264,19 +264,19 @@ protected function preSaveNew(EntityStorageInterface $storage) {
// Field name cannot be longer than FieldStorageConfig::NAME_MAX_LENGTH characters.
// We use Unicode::strlen() because the DB layer assumes that column widths
// are given in characters rather than bytes.
if (Unicode::strlen($this->name) > static::NAME_MAX_LENGTH) {
if (Unicode::strlen($this->field_name) > static::NAME_MAX_LENGTH) {