diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSyncImageTest.php b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSyncImageTest.php index 7bfa73f34833341938f54c724d831be8c34fc5a9..568ee743af2029e69ef289ce2b26ba751dd55f84 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSyncImageTest.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSyncImageTest.php @@ -119,7 +119,7 @@ function testImageFieldSync() { // Generate the item for the current image file entity and attach it to // the entity. $item = array( - 'fid' => $fid, + 'target_id' => $fid, 'alt' => $default_langcode . '_' . $fid . '_' . $this->randomName(), 'title' => $default_langcode . '_' . $fid . '_' . $this->randomName(), ); @@ -144,7 +144,7 @@ function testImageFieldSync() { // the entity. $fid = $this->files[$index]->fid; $item = array( - 'fid' => $fid, + 'target_id' => $fid, 'alt' => $langcode . '_' . $fid . '_' . $this->randomName(), 'title' => $langcode . '_' . $fid . '_' . $this->randomName(), ); @@ -166,11 +166,11 @@ function testImageFieldSync() { // have been retained. $fids = array(); foreach ($entity->{$this->fieldName} as $delta => $item) { - $value = $values[$default_langcode][$item->fid]; + $value = $values[$default_langcode][$item->target_id]; $source_item = $entity->getTranslation($langcode)->{$this->fieldName}->offsetGet($delta); - $assert = $item->fid == $source_item->fid && $item->alt == $value['alt'] && $item->title == $value['title']; - $this->assertTrue($assert, format_string('Field item @fid has been successfully synchronized.', array('@fid' => $item->fid))); - $fids[$item->fid] = TRUE; + $assert = $item->target_id == $source_item->target_id && $item->alt == $value['alt'] && $item->title == $value['title']; + $this->assertTrue($assert, format_string('Field item @fid has been successfully synchronized.', array('@fid' => $item->target_id))); + $fids[$item->target_id] = TRUE; } // Check that the dropped value is the right one. @@ -179,7 +179,7 @@ function testImageFieldSync() { // Add back an item for the dropped value and perform synchronization again. $values[$langcode][$removed_fid] = array( - 'fid' => $removed_fid, + 'target_id' => $removed_fid, 'alt' => $langcode . '_' . $removed_fid . '_' . $this->randomName(), 'title' => $langcode . '_' . $removed_fid . '_' . $this->randomName(), ); @@ -196,11 +196,11 @@ function testImageFieldSync() { // When adding an item its value is copied over all the target languages, // thus in this case the source language needs to be used to check the // values instead of the target one. - $fid_langcode = $item->fid != $removed_fid ? $default_langcode : $langcode; - $value = $values[$fid_langcode][$item->fid]; + $fid_langcode = $item->target_id != $removed_fid ? $default_langcode : $langcode; + $value = $values[$fid_langcode][$item->target_id]; $source_item = $entity->getTranslation($langcode)->{$this->fieldName}->offsetGet($delta); - $assert = $item->fid == $source_item->fid && $item->alt == $value['alt'] && $item->title == $value['title']; - $this->assertTrue($assert, format_string('Field item @fid has been successfully synchronized.', array('@fid' => $item->fid))); + $assert = $item->target_id == $source_item->target_id && $item->alt == $value['alt'] && $item->title == $value['title']; + $this->assertTrue($assert, format_string('Field item @fid has been successfully synchronized.', array('@fid' => $item->target_id))); } } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php index 4535159b04aa68cdd7f24695029806299ab9467b..7406134aace9060aa1318d8c4b6292cfad8299b6 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php @@ -93,7 +93,7 @@ public function getPropertyDefinitions() { * since we cannot extend it. */ public static function schema(Field $field) { - $definition = \Drupal::typedData()->getDefinition('field_item:' . $field->type); + $definition = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field->type); $module = $definition['module']; module_load_install($module); $callback = "{$module}_field_schema"; diff --git a/core/modules/file/file.api.php b/core/modules/file/file.api.php index 49d9af88dc342a119434069df92c614072b440e9..c71321454b3683ff1292720e8dfccd63099fb232 100644 --- a/core/modules/file/file.api.php +++ b/core/modules/file/file.api.php @@ -38,7 +38,7 @@ function hook_file_load($files) { $result = db_query('SELECT * FROM {upload} u WHERE u.fid IN (:fids)', array(':fids' => array_keys($files)))->fetchAll(PDO::FETCH_ASSOC); foreach ($result as $record) { foreach ($record as $key => $value) { - $files[$record['fid']]->$key = $value; + $files[$record['target_id']]->$key = $value; } } } diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc index 289c67f9f94ac66976431ccde49ec6d5aa61fe61..3305a00c8b3f786f4d1cee05d46b16969484e5a9 100644 --- a/core/modules/file/file.field.inc +++ b/core/modules/file/file.field.inc @@ -189,7 +189,7 @@ function _file_generic_settings_file_directory_validate($element, &$form_state) function file_field_insert(EntityInterface $entity, $field, $instance, $langcode, &$items) { // Add a new usage of each uploaded file. foreach ($items as $item) { - file_usage()->add(file_load($item['fid']), 'file', $entity->entityType(), $entity->id()); + file_usage()->add(file_load($item['target_id']), 'file', $entity->entityType(), $entity->id()); } } @@ -203,7 +203,7 @@ function file_field_update(EntityInterface $entity, $field, $instance, $langcode // deletion of previous file usages are necessary. if (!empty($entity->original) && $entity->getRevisionId() != $entity->original->getRevisionId()) { foreach ($items as $item) { - file_usage()->add(file_load($item['fid']), 'file', $entity->entityType(), $entity->id()); + file_usage()->add(file_load($item['target_id']), 'file', $entity->entityType(), $entity->id()); } return; } @@ -211,7 +211,7 @@ function file_field_update(EntityInterface $entity, $field, $instance, $langcode // Build a display of the current FIDs. $current_fids = array(); foreach ($items as $item) { - $current_fids[] = $item['fid']; + $current_fids[] = $item['target_id']; } // Compare the original field values with the ones that are being saved. @@ -219,18 +219,18 @@ function file_field_update(EntityInterface $entity, $field, $instance, $langcode $original_fids = array(); if (!empty($original->{$field['field_name']}[$langcode])) { foreach ($original->{$field['field_name']}[$langcode] as $original_item) { - $original_fids[] = $original_item['fid']; - if (isset($original_item['fid']) && !in_array($original_item['fid'], $current_fids)) { + $original_fids[] = $original_item['target_id']; + if (isset($original_item['target_id']) && !in_array($original_item['target_id'], $current_fids)) { // Decrement the file usage count by 1. - file_usage()->delete(file_load($original_item['fid']), 'file', $entity->entityType(), $entity->id()); + file_usage()->delete(file_load($original_item['target_id']), 'file', $entity->entityType(), $entity->id()); } } } // Add new usage entries for newly added files. foreach ($items as $item) { - if (!in_array($item['fid'], $original_fids)) { - file_usage()->add(file_load($item['fid']), 'file', $entity->entityType(), $entity->id()); + if (!in_array($item['target_id'], $original_fids)) { + file_usage()->add(file_load($item['target_id']), 'file', $entity->entityType(), $entity->id()); } } } @@ -241,7 +241,7 @@ function file_field_update(EntityInterface $entity, $field, $instance, $langcode function file_field_delete(EntityInterface $entity, $field, $instance, $langcode, &$items) { // Delete all file usages within this entity. foreach ($items as $delta => $item) { - file_usage()->delete(file_load($item['fid']), 'file', $entity->entityType(), $entity->id(), 0); + file_usage()->delete(file_load($item['target_id']), 'file', $entity->entityType(), $entity->id(), 0); } } @@ -251,7 +251,7 @@ function file_field_delete(EntityInterface $entity, $field, $instance, $langcode function file_field_delete_revision(EntityInterface $entity, $field, $instance, $langcode, &$items) { foreach ($items as $delta => $item) { // Decrement the file usage count by 1. - file_usage()->delete(file_load($item['fid']), 'file', $entity->entityType(), $entity->id()); + file_usage()->delete(file_load($item['target_id']), 'file', $entity->entityType(), $entity->id()); } } @@ -259,7 +259,7 @@ function file_field_delete_revision(EntityInterface $entity, $field, $instance, * Implements hook_field_is_empty(). */ function file_field_is_empty($item, $field_type) { - return empty($item['fid']); + return empty($item['target_id']); } /** diff --git a/core/modules/file/file.install b/core/modules/file/file.install index 0c97f82eec7fd8400c74fc7bbd8a897965704207..1f31e43a6d921fa8199a9c115f5f37db6fbbf0d1 100644 --- a/core/modules/file/file.install +++ b/core/modules/file/file.install @@ -5,6 +5,8 @@ * Install, update and uninstall functions for File module. */ +use Drupal\field\Plugin\Core\Entity\Field; + /** * Implements hook_schema(). */ @@ -154,10 +156,10 @@ function file_schema() { function file_field_schema($field) { return array( 'columns' => array( - 'fid' => array( - 'description' => 'The {file_managed}.fid being referenced in this field.', + 'target_id' => array( + 'description' => 'The ID of the target entity.', 'type' => 'int', - 'not null' => FALSE, + 'not null' => TRUE, 'unsigned' => TRUE, ), 'display' => array( @@ -175,12 +177,12 @@ function file_field_schema($field) { ), ), 'indexes' => array( - 'fid' => array('fid'), + 'target_id' => array('target_id'), ), 'foreign keys' => array( - 'fid' => array( + 'target_id' => array( 'table' => 'file_managed', - 'columns' => array('fid' => 'fid'), + 'columns' => array('target_id' => 'fid'), ), ), ); @@ -243,6 +245,12 @@ function file_update_dependencies() { $dependencies['field'][8003] = array( 'file' => 8001, ); + + // Convert the 'fid' column of file fields to 'target_id' after fields and + // instances have been moved to the config system. + $dependencies['file'][8003] = array( + 'field' => 8003, + ); return $dependencies; } @@ -288,3 +296,46 @@ function file_update_8002() { db_change_field('file_usage', 'module', 'module', $spec); } } + +/** + * Update file field tables to use target_id instead of fid. + */ +function file_update_8003() { + foreach (config_get_storage_names_with_prefix('field.field.') as $config_name) { + $field_config = config($config_name); + // Only update file fields that use the default SQL storage. + if (in_array($field_config->get('type'), array('file', 'image')) && $field_config->get('storage.type') == 'field_sql_storage') { + $field = new Field($field_config->get()); + + $tables = array( + _field_sql_storage_tablename($field), + _field_sql_storage_revision_tablename($field), + ); + + foreach ($tables as $table_name) { + // Skip fields which were created during the upgrade process. + if (!db_field_exists($table_name, $field->id() . '_fid')) { + continue 2; + } + + db_change_field($table_name, $field->id() . '_fid', $field->id() . '_target_id', array( + 'description' => 'The ID of the target entity.', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + )); + + // Change the index. + db_drop_index($table_name, $field->id() . '_fid'); + db_add_index($table_name, $field->id() . '_target_id', array($field->id() . '_target_id')); + } + + // Update the indexes in field config as well. + $indexes = $field_config->get('indexes'); + unset($indexes['fid']); + $indexes['target_id'] = array('target_id'); + $field_config->set('indexes', $indexes); + $field_config->save(); + } + } +} diff --git a/core/modules/file/file.views.inc b/core/modules/file/file.views.inc index c9e271f11bc346f7afac143b6235bbb9698c9768..5c2743f6d47ba672b1f69adac0bb03f03c4cd39d 100644 --- a/core/modules/file/file.views.inc +++ b/core/modules/file/file.views.inc @@ -455,11 +455,11 @@ function file_field_views_data($field) { $data = field_views_field_default_views_data($field); foreach ($data as $table_name => $table_data) { // Add the relationship only on the fid field. - $data[$table_name][$field['field_name'] . '_fid']['relationship'] = array( + $data[$table_name][$field['field_name'] . '_target_id']['relationship'] = array( 'id' => 'standard', 'base' => 'file_managed', 'entity type' => 'file', - 'base field' => 'fid', + 'base field' => 'target_id', 'label' => t('file from !field_name', array('!field_name' => $field['field_name'])), ); } @@ -489,7 +489,7 @@ function file_field_views_data_views_data_alter(&$data, $field) { 'id' => 'entity_reverse', 'field_name' => $field['field_name'], 'field table' => _field_sql_storage_tablename($field), - 'field field' => $field['field_name'] . '_fid', + 'field field' => $field['field_name'] . '_target_id', 'base' => $entity_info['base_table'], 'base field' => $entity_info['entity_keys']['id'], 'label' => t('!field_name', array('!field_name' => $field['field_name'])), diff --git a/core/modules/file/lib/Drupal/file/Plugin/field/formatter/FileFormatterBase.php b/core/modules/file/lib/Drupal/file/Plugin/field/formatter/FileFormatterBase.php index 358648bfd6ce7417d22fd4bb7bdb73ea360cf297..ccf28d333cf27c28312caa1be9e9274ea5abdad5 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/field/formatter/FileFormatterBase.php +++ b/core/modules/file/lib/Drupal/file/Plugin/field/formatter/FileFormatterBase.php @@ -22,9 +22,9 @@ public function prepareView(array $entities, $langcode, array &$items) { $fids = array(); foreach ($entities as $id => $entity) { foreach ($items[$id] as $delta => $item) { - if ($this->isDisplayed($item) && !empty($item['fid'])) { + if ($this->isDisplayed($item) && !empty($item['target_id'])) { // Load the files from the files table. - $fids[] = $item['fid']; + $fids[] = $item['target_id']; } } } @@ -35,8 +35,8 @@ public function prepareView(array $entities, $langcode, array &$items) { foreach ($entities as $id => $entity) { foreach ($items[$id] as $delta => $item) { // If the file does not exist, mark the entire item as empty. - if (!empty($item['fid'])) { - $items[$id][$delta]['entity'] = isset($files[$item['fid']]) ? $files[$item['fid']] : NULL; + if (!empty($item['target_id'])) { + $items[$id][$delta]['entity'] = isset($files[$item['target_id']]) ? $files[$item['target_id']] : NULL; } } } diff --git a/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php b/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php index 4603288ce9afc7ad0a2d6bf777ddb19ca361e07b..c63df17266ddda94600ab9c6b91783099956503b 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php +++ b/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php @@ -209,8 +209,8 @@ public function formElement(array $items, $delta, array $element, $langcode, arr // Field stores FID value in a single mode, so we need to transform it for // form element to recognize it correctly. - if (!isset($items[$delta]['fids']) && isset($items[$delta]['fid'])) { - $items[$delta]['fids'][0] = $items[$delta]['fid']; + if (!isset($items[$delta]['fids']) && isset($items[$delta]['target_id'])) { + $items[$delta]['fids'][0] = $items[$delta]['target_id']; } $element['#default_value'] = !empty($items[$delta]) ? $items[$delta] : $defaults; @@ -237,7 +237,7 @@ public function massageFormValues(array $values, array $form, array &$form_state foreach ($values as &$value) { foreach ($value['fids'] as $fid) { $new_value = $value; - $new_value['fid'] = $fid; + $new_value['target_id'] = $fid; unset($new_value['fids']); $new_values[] = $new_value; } diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php index 8d733929b070b72905f250037808d7958cc79831..29ba4ef800bea939139a7d224a0c91fdcd91e709 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php @@ -60,7 +60,7 @@ function testNodeDisplay() { // Check that the default formatter is displaying with the file name. $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); $default_output = theme('file_link', array('file' => $node_file)); $this->assertRaw($default_output, 'Default formatter displaying correctly on full node view.'); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php index 9055560ba15609d7ff97f1ab831321429f46fc93..f2c45b670bfd33958c67722a4222ebfb869a21e3 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php @@ -35,7 +35,7 @@ function testUploadPath() { // Check that the file was uploaded to the file root. $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); $this->assertPathMatch('public://' . $test_file->getFilename(), $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path.', array('%file' => $node_file->getFileUri()))); // Change the path to contain multiple subdirectories. @@ -46,7 +46,7 @@ function testUploadPath() { // Check that the file was uploaded into the subdirectory. $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'], TRUE); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'], TRUE); $this->assertPathMatch('public://foo/bar/baz/' . $test_file->getFilename(), $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path.', array('%file' => $node_file->getFileUri()))); // Check the path when used with tokens. @@ -58,7 +58,7 @@ function testUploadPath() { // Check that the file was uploaded into the subdirectory. $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); // Do token replacement using the same user which uploaded the file, not // the user running the test case. $data = array('user' => $this->admin_user); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php index a3b86eabe0a21106eaa6e883f88576ffd472aa67..7847a16b114079850206c882552075a1433ec5db 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php @@ -67,7 +67,7 @@ function testFileFieldRSSContent() { // Get the uploaded file from the node. $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); // Check that the RSS enclosure appears in the RSS feed. $this->drupalGet('rss.xml'); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php index 0a5ffa4b6e04dcbe08828adc1aed1e77d5ace9b1..84e23c3a52e32d9e40d64568e1049af644fc7ae1 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php @@ -47,7 +47,7 @@ function testRevisions() { // Check that the file exists on disk and in the database. $node = node_load($nid, TRUE); - $node_file_r1 = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $node_file_r1 = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); $node_vid_r1 = $node->vid; $this->assertFileExists($node_file_r1, 'New file saved to disk on node creation.'); $this->assertFileEntryExists($node_file_r1, 'File entry exists in database on node creation.'); @@ -56,7 +56,7 @@ function testRevisions() { // Upload another file to the same node in a new revision. $this->replaceNodeFile($test_file, $field_name, $nid); $node = node_load($nid, TRUE); - $node_file_r2 = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $node_file_r2 = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); $node_vid_r2 = $node->vid; $this->assertFileExists($node_file_r2, 'Replacement file exists on disk after creating new revision.'); $this->assertFileEntryExists($node_file_r2, 'Replacement file entry exists in database after creating new revision.'); @@ -64,7 +64,7 @@ function testRevisions() { // Check that the original file is still in place on the first revision. $node = node_revision_load($node_vid_r1); - $current_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $current_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); $this->assertEqual($node_file_r1->id(), $current_file->id(), 'Original file still in place after replacing file in new revision.'); $this->assertFileExists($node_file_r1, 'Original file still in place after replacing file in new revision.'); $this->assertFileEntryExists($node_file_r1, 'Original file entry still in place after replacing file in new revision'); @@ -74,7 +74,7 @@ function testRevisions() { // Check that the file is still the same as the previous revision. $this->drupalPost('node/' . $nid . '/edit', array('revision' => '1'), t('Save and keep published')); $node = node_load($nid, TRUE); - $node_file_r3 = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $node_file_r3 = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); $node_vid_r3 = $node->vid; $this->assertEqual($node_file_r2->id(), $node_file_r3->id(), 'Previous revision file still in place after creating a new revision without a new file.'); $this->assertFileIsPermanent($node_file_r3, 'New revision file is permanent.'); @@ -82,7 +82,7 @@ function testRevisions() { // Revert to the first revision and check that the original file is active. $this->drupalPost('node/' . $nid . '/revisions/' . $node_vid_r1 . '/revert', array(), t('Revert')); $node = node_load($nid, TRUE); - $node_file_r4 = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $node_file_r4 = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); $node_vid_r4 = $node->vid; $this->assertEqual($node_file_r1->id(), $node_file_r4->id(), 'Original revision file still in place after reverting to the original revision.'); $this->assertFileIsPermanent($node_file_r4, 'Original revision file still permanent after reverting to the original revision.'); @@ -96,7 +96,7 @@ function testRevisions() { // Attach the second file to a user. $user = $this->drupalCreateUser(); - $user->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'] = $node_file_r3->id(); + $user->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'] = $node_file_r3->id(); $user->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['display'] = 1; $user->save(); $this->drupalGet('user/' . $user->uid . '/edit'); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php index 19029c45976bc2f801f477d9c5ff6ea37c3a2cbd..a7cf1e57bc0335ca622c50fd72711e9ebbd6f32e 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php @@ -47,7 +47,7 @@ function testRequired() { $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); $this->assertFileExists($node_file, 'File exists after uploading to the required field.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading to the required field.'); @@ -63,7 +63,7 @@ function testRequired() { // Create a new node with the uploaded file into the multivalue field. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); $this->assertFileExists($node_file, 'File exists after uploading to the required multiple value field.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading to the required multiple value field.'); } @@ -93,7 +93,7 @@ function testFileMaxSize() { // Create a new node with the small file, which should pass. $nid = $this->uploadNodeFile($small_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); $this->assertFileExists($node_file, format_string('File exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->getSize()), '%maxsize' => $max_filesize))); $this->assertFileEntryExists($node_file, format_string('File entry exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->getSize()), '%maxsize' => $max_filesize))); @@ -109,7 +109,7 @@ function testFileMaxSize() { // Upload the big file successfully. $nid = $this->uploadNodeFile($large_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); $this->assertFileExists($node_file, format_string('File exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->getSize())))); $this->assertFileEntryExists($node_file, format_string('File entry exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->getSize())))); } @@ -131,7 +131,7 @@ function testFileExtension() { // Check that the file can be uploaded with no extension checking. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); $this->assertFileExists($node_file, 'File exists after uploading a file with no extension checking.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading a file with no extension checking.'); @@ -149,7 +149,7 @@ function testFileExtension() { // Check that the file can be uploaded with extension checking. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); $this->assertFileExists($node_file, 'File exists after uploading a file with extension checking.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading a file with extension checking.'); } diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php index 6a097c6f0af30da8585ffcf826733925370f0630..2389423620e712ffdff17c8ad025d53958012dfa 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php @@ -46,7 +46,7 @@ function testSingleValuedWidget() { // does not yet support file uploads. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); $this->assertFileExists($node_file, 'New file saved to disk on node creation.'); // Ensure the file can be downloaded. @@ -79,7 +79,7 @@ function testSingleValuedWidget() { // Save the node and ensure it does not have the file. $this->drupalPost(NULL, array(), t('Save and keep published')); $node = node_load($nid, TRUE); - $this->assertTrue(empty($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']), 'File was successfully removed from the node.'); + $this->assertTrue(empty($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']), 'File was successfully removed from the node.'); } } @@ -196,7 +196,7 @@ function testMultiValuedWidget() { preg_match('/node\/([0-9]+)/', $this->getUrl(), $matches); $nid = $matches[1]; $node = node_load($nid, TRUE); - $this->assertTrue(empty($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']), 'Node was successfully saved without any files.'); + $this->assertTrue(empty($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']), 'Node was successfully saved without any files.'); } } @@ -216,7 +216,7 @@ function testPrivateFileSetting() { $this->drupalPost("admin/structure/types/manage/$type_name/fields/$instance->id/field", $edit, t('Save field settings')); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); $this->assertFileExists($node_file, 'New file saved to disk on node creation.'); // Ensure the private file is available to the user who uploaded it. diff --git a/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php b/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php index def3a489299190590721c454e9d94caabbfe13f0..fd00c1139af13a6500774c1ae28a7def56036e59 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php @@ -67,7 +67,7 @@ public function setUp() { public function testFileItem() { // Create a test entity with the $entity = entity_create('entity_test', array()); - $entity->file_test->fid = $this->file->id(); + $entity->file_test->target_id = $this->file->id(); $entity->file_test->display = 1; $entity->file_test->description = $description = $this->randomName(); $entity->name->value = $this->randomName(); @@ -76,7 +76,7 @@ public function testFileItem() { $entity = entity_load('entity_test', $entity->id()); $this->assertTrue($entity->file_test instanceof FieldInterface, 'Field implements interface.'); $this->assertTrue($entity->file_test[0] instanceof FieldItemInterface, 'Field item implements interface.'); - $this->assertEqual($entity->file_test->fid, $this->file->id()); + $this->assertEqual($entity->file_test->target_id, $this->file->id()); $this->assertEqual($entity->file_test->display, 1); $this->assertEqual($entity->file_test->description, $description); $this->assertEqual($entity->file_test->entity->getFileUri(), $this->file->getFileUri()); @@ -90,7 +90,7 @@ public function testFileItem() { )); $file2->save(); - $entity->file_test->fid = $file2->id(); + $entity->file_test->target_id = $file2->id(); $this->assertEqual($entity->file_test->entity->id(), $file2->id()); $this->assertEqual($entity->file_test->entity->getFileUri(), $file2->getFileUri()); } diff --git a/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php b/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php index b541953055595248c2644d0c425d836c1d292fd9..1b8a82f651e9ad3f9776a1440017143b46c41735 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php @@ -50,7 +50,7 @@ function testPrivateFile() { $test_file = $this->getTestFile('text'); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name, TRUE, array('private' => TRUE)); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); // Ensure the file can be downloaded. $this->drupalGet(file_create_url($node_file->getFileUri())); $this->assertResponse(200, 'Confirmed that the generated URL is correct by downloading the shipped file.'); @@ -62,7 +62,7 @@ function testPrivateFile() { $this->drupalLogin($this->admin_user); $nid = $this->uploadNodeFile($test_file, $no_access_field_name, $type_name, TRUE, array('private' => TRUE)); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$no_access_field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$no_access_field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); // Ensure the file cannot be downloaded. $this->drupalGet(file_create_url($node_file->getFileUri())); $this->assertResponse(403, 'Confirmed that access is denied for the file without view field access permission.'); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php index 9787554eaf3cbd6de97709edd39d64ac62fd23d0..c154332c9a0b3972dde5b2a13369dd1e3da2bd22 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php @@ -47,7 +47,7 @@ function testFileTokenReplacement() { // Load the node and the file. $node = node_load($nid, TRUE); - $file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); // Generate and test sanitized tokens. $tests = array(); diff --git a/core/modules/file/lib/Drupal/file/Type/FileItem.php b/core/modules/file/lib/Drupal/file/Type/FileItem.php index 34e57538c784fe1d97a16717d177cfb603b812af..9b2cc4cb96f901ca00d13659c9c11ffe3d37be26 100644 --- a/core/modules/file/lib/Drupal/file/Type/FileItem.php +++ b/core/modules/file/lib/Drupal/file/Type/FileItem.php @@ -7,12 +7,12 @@ namespace Drupal\file\Type; -use Drupal\field\Plugin\field\field_type\LegacyConfigFieldItem; +use Drupal\field\Plugin\Type\FieldType\ConfigEntityReferenceItemBase; /** * Defines the 'file_field' entity field item. */ -class FileItem extends LegacyConfigFieldItem { +class FileItem extends ConfigEntityReferenceItemBase { /** * Property definitions of the contained properties. @@ -24,14 +24,14 @@ class FileItem extends LegacyConfigFieldItem { static $propertyDefinitions; /** - * Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinitions(). + * {@inheritdoc} */ public function getPropertyDefinitions() { + $this->definition['settings']['target_type'] = 'file'; + if (!isset(static::$propertyDefinitions)) { - static::$propertyDefinitions['fid'] = array( - 'type' => 'integer', - 'label' => t('Referenced file id.'), - ); + static::$propertyDefinitions = parent::getPropertyDefinitions(); + static::$propertyDefinitions['display'] = array( 'type' => 'boolean', 'label' => t('Flag to control whether this file should be displayed when viewing content.'), @@ -40,39 +40,8 @@ public function getPropertyDefinitions() { 'type' => 'string', 'label' => t('A description of the file.'), ); - static::$propertyDefinitions['entity'] = array( - 'type' => 'entity', - 'constraints' => array( - 'EntityType' => 'file', - ), - 'label' => t('File'), - 'description' => t('The referenced file'), - // The entity object is computed out of the fid. - 'computed' => TRUE, - 'read-only' => FALSE, - 'settings' => array('id source' => 'fid'), - ); } return static::$propertyDefinitions; } - /** - * Overrides \Drupal\Core\Entity\Field\FieldItemBase::get(). - */ - public function setValue($values, $notify = TRUE) { - // Treat the values as value of the entity property, if no array is - // given as this handles entity IDs and objects. - if (isset($values) && !is_array($values)) { - // Directly update the property instead of invoking the parent, so that - // the entity property can take care of updating the ID property. - $this->properties['entity']->setValue($values, $notify); - } - else { - // Make sure that the 'entity' property gets set as 'target_id'. - if (isset($values['fid']) && !isset($values['entity'])) { - $values['entity'] = $values['fid']; - } - parent::setValue($values, $notify); - } - } } diff --git a/core/modules/image/image.field.inc b/core/modules/image/image.field.inc index 7b2f4c6a1c76a89adcfcfb85e948c57ebd957736..9609960d5e6a3c266013fd3b402182878ae1b099 100644 --- a/core/modules/image/image.field.inc +++ b/core/modules/image/image.field.inc @@ -22,7 +22,7 @@ function image_field_info() { 'column_groups' => array( 'file' => array( 'label' => t('File'), - 'columns' => array('fid', 'width', 'height'), + 'columns' => array('target_id', 'width', 'height'), ), 'alt' => array( 'label' => t('Alt'), @@ -230,7 +230,7 @@ function image_field_presave(EntityInterface $entity, $field, $instance, $langco // Determine the dimensions if necessary. foreach ($items as &$item) { if (!isset($item['width']) || !isset($item['height'])) { - $info = image_get_info(file_load($item['fid'])->getFileUri()); + $info = image_get_info(file_load($item['target_id'])->getFileUri()); if (is_array($info)) { $item['width'] = $info['width']; diff --git a/core/modules/image/image.install b/core/modules/image/image.install index 8a0566093400110c7ee160967d39eeb8504d8bc6..fd440da7b306a265461d847a4d5c09fdb0cf6119 100644 --- a/core/modules/image/image.install +++ b/core/modules/image/image.install @@ -6,6 +6,7 @@ */ use Drupal\Component\Uuid\Uuid; +use Drupal\field\Plugin\Core\Entity\Field; /** * Implements hook_install(). @@ -30,10 +31,10 @@ function image_uninstall() { function image_field_schema($field) { return array( 'columns' => array( - 'fid' => array( - 'description' => 'The {file_managed}.fid being referenced in this field.', + 'target_id' => array( + 'description' => 'The ID of the target entity.', 'type' => 'int', - 'not null' => FALSE, + 'not null' => TRUE, 'unsigned' => TRUE, ), 'alt' => array( @@ -60,12 +61,12 @@ function image_field_schema($field) { ), ), 'indexes' => array( - 'fid' => array('fid'), + 'target_id' => array('target_id'), ), 'foreign keys' => array( - 'fid' => array( + 'target_id' => array( 'table' => 'file_managed', - 'columns' => array('fid' => 'fid'), + 'columns' => array('target_id' => 'fid'), ), ), ); diff --git a/core/modules/image/image.views.inc b/core/modules/image/image.views.inc index 77c4ea371a57cc30df9a4a13e63b6ad2960a56d2..2e70c0892e0291a3cde7a59c15b2a4a8a98eb7e9 100644 --- a/core/modules/image/image.views.inc +++ b/core/modules/image/image.views.inc @@ -18,11 +18,11 @@ function image_field_views_data($field) { $data = field_views_field_default_views_data($field); foreach ($data as $table_name => $table_data) { - // Add the relationship only on the fid field. - $data[$table_name][$field['field_name'] . '_fid']['relationship'] = array( + // Add the relationship only on the target_id field. + $data[$table_name][$field['field_name'] . '_target_id']['relationship'] = array( 'id' => 'standard', 'base' => 'file_managed', - 'base field' => 'fid', + 'base field' => 'target_id', 'label' => t('image from !field_name', array('!field_name' => $field['field_name'])), ); } @@ -52,7 +52,7 @@ function image_field_views_data_views_data_alter(&$data, $field) { 'id' => 'entity_reverse', 'field_name' => $field['field_name'], 'field table' => _field_sql_storage_tablename($field), - 'field field' => $field['field_name'] . '_fid', + 'field field' => $field['field_name'] . '_target_id', 'base' => $entity_info['base_table'], 'base field' => $entity_info['entity_keys']['id'], 'label' => t('!field_name', array('!field_name' => $field['field_name'])), diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php index 96941b345eea8b14058aef288d95bb8f18073a05..973a8ef7660f83c2f347c3311ec7b2c9cea166a1 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php @@ -273,7 +273,7 @@ function testStyleReplacement() { // Test that image is displayed using newly created style. $this->drupalGet('node/' . $nid); - $this->assertRaw(image_style_url($style_name, file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->getFileUri()), format_string('Image displayed using style @style.', array('@style' => $style_name))); + $this->assertRaw(image_style_url($style_name, file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'])->getFileUri()), format_string('Image displayed using style @style.', array('@style' => $style_name))); // Rename the style and make sure the image field is updated. $new_style_name = strtolower($this->randomName(10)); @@ -285,7 +285,7 @@ function testStyleReplacement() { $this->drupalPost($style_path . $style_name, $edit, t('Update style')); $this->assertText(t('Changes to the style have been saved.'), format_string('Style %name was renamed to %new_name.', array('%name' => $style_name, '%new_name' => $new_style_name))); $this->drupalGet('node/' . $nid); - $this->assertRaw(image_style_url($new_style_name, file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->getFileUri()), 'Image displayed using style replacement style.'); + $this->assertRaw(image_style_url($new_style_name, file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'])->getFileUri()), 'Image displayed using style replacement style.'); // Delete the style and choose a replacement style. $edit = array( @@ -296,7 +296,7 @@ function testStyleReplacement() { $this->assertRaw($message); $this->drupalGet('node/' . $nid); - $this->assertRaw(image_style_url('thumbnail', file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->getFileUri()), 'Image displayed using style replacement style.'); + $this->assertRaw(image_style_url('thumbnail', file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'])->getFileUri()), 'Image displayed using style replacement style.'); } /** @@ -362,7 +362,7 @@ function testConfigImport() { // Test that image is displayed using newly created style. $this->drupalGet('node/' . $nid); - $this->assertRaw(image_style_url($style_name, file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->getFileUri()), format_string('Image displayed using style @style.', array('@style' => $style_name))); + $this->assertRaw(image_style_url($style_name, file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'])->getFileUri()), format_string('Image displayed using style @style.', array('@style' => $style_name))); // Copy config to staging, and delete the image style. $staging = $this->container->get('config.storage.staging'); diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php index ccc39bd6ca6e6e63b0b73fe8cdcc244d82a0b207..c0f0cfdb7f5458ce71741d201920d082243b7ec0 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php @@ -58,7 +58,7 @@ function _testImageFieldFormatters($scheme) { $node = node_load($nid, TRUE); // Test that the default formatter is being used. - $image_uri = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->getFileUri(); + $image_uri = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'])->getFileUri(); $image_info = array( 'uri' => $image_uri, 'width' => 40, @@ -165,7 +165,7 @@ function testImageFieldSettings() { // style. $node = node_load($nid, TRUE); $image_info = array( - 'uri' => file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->getFileUri(), + 'uri' => file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'])->getFileUri(), 'width' => 220, 'height' => 110, 'style_name' => 'medium', @@ -175,7 +175,7 @@ function testImageFieldSettings() { // Add alt/title fields to the image and verify that they are displayed. $image_info = array( - 'uri' => file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->getFileUri(), + 'uri' => file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'])->getFileUri(), 'alt' => $this->randomName(), 'title' => $this->randomName(), 'width' => 40, @@ -243,7 +243,7 @@ function testImageFieldDefaultImage() { $nid = $this->uploadNodeImage($images[1], $field_name, 'article'); $node = node_load($nid, TRUE); $image_info = array( - 'uri' => file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->getFileUri(), + 'uri' => file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'])->getFileUri(), 'width' => 40, 'height' => 20, ); diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php index 0735bef4e180d25ff49805ae20921026497820b2..5e7472f9617b722d4c5a889733600dad09fcadd2 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php @@ -66,7 +66,7 @@ public function setUp() { public function testImageItem() { // Create a test entity with the image field set. $entity = entity_create('entity_test', array()); - $entity->image_test->fid = $this->image->id(); + $entity->image_test->target_id = $this->image->id(); $entity->image_test->alt = $alt = $this->randomName(); $entity->image_test->title = $title = $this->randomName(); $entity->name->value = $this->randomName(); @@ -75,7 +75,7 @@ public function testImageItem() { $entity = entity_load('entity_test', $entity->id()); $this->assertTrue($entity->image_test instanceof FieldInterface, 'Field implements interface.'); $this->assertTrue($entity->image_test[0] instanceof FieldItemInterface, 'Field item implements interface.'); - $this->assertEqual($entity->image_test->fid, $this->image->id()); + $this->assertEqual($entity->image_test->target_id, $this->image->id()); $this->assertEqual($entity->image_test->alt, $alt); $this->assertEqual($entity->image_test->title, $title); $info = image_get_info('public://example.jpg'); @@ -91,7 +91,7 @@ public function testImageItem() { )); $image2->save(); - $entity->image_test->fid = $image2->id(); + $entity->image_test->target_id = $image2->id(); $entity->image_test->alt = $new_alt = $this->randomName(); // The width and height is only updated when width is not set. $entity->image_test->width = NULL; @@ -105,7 +105,7 @@ public function testImageItem() { // Check that the image item can be set to the referenced file directly. $entity->image_test = $this->image; - $this->assertEqual($entity->image_test->fid, $this->image->id()); + $this->assertEqual($entity->image_test->target_id, $this->image->id()); // Delete the image and try to save the entity again. $this->image->delete(); diff --git a/core/modules/image/lib/Drupal/image/Type/ImageItem.php b/core/modules/image/lib/Drupal/image/Type/ImageItem.php index 2dcf2b48c6c9f72567892a045ddb6b4063ff1fa6..7d441fd2c944951588079e9f815d1a7362261869 100644 --- a/core/modules/image/lib/Drupal/image/Type/ImageItem.php +++ b/core/modules/image/lib/Drupal/image/Type/ImageItem.php @@ -7,12 +7,12 @@ namespace Drupal\image\Type; -use Drupal\field\Plugin\field\field_type\LegacyConfigFieldItem; +use Drupal\field\Plugin\Type\FieldType\ConfigEntityReferenceItemBase; /** * Defines the 'image_field' entity field item. */ -class ImageItem extends LegacyConfigFieldItem { +class ImageItem extends ConfigEntityReferenceItemBase { /** * Property definitions of the contained properties. @@ -24,14 +24,14 @@ class ImageItem extends LegacyConfigFieldItem { static $propertyDefinitions; /** - * Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinitions(). + * {@inheritdoc} */ public function getPropertyDefinitions() { + $this->definition['settings']['target_type'] = 'file'; + if (!isset(static::$propertyDefinitions)) { - static::$propertyDefinitions['fid'] = array( - 'type' => 'integer', - 'label' => t('Referenced file id.'), - ); + static::$propertyDefinitions = parent::getPropertyDefinitions(); + static::$propertyDefinitions['alt'] = array( 'type' => 'string', 'label' => t("Alternative image text, for the image's 'alt' attribute."), @@ -48,39 +48,8 @@ public function getPropertyDefinitions() { 'type' => 'integer', 'label' => t('The height of the image in pixels.'), ); - static::$propertyDefinitions['entity'] = array( - 'type' => 'entity', - 'constraints' => array( - 'EntityType' => 'file', - ), - 'label' => t('Image'), - 'description' => t('The referenced file'), - // The entity object is computed out of the fid. - 'computed' => TRUE, - 'read-only' => FALSE, - 'settings' => array('id source' => 'fid'), - ); } return static::$propertyDefinitions; } - /** - * Overrides \Drupal\Core\Entity\Field\FieldItemBase::get(). - */ - public function setValue($values, $notify = TRUE) { - // Treat the values as value of the entity property, if no array is - // given as this handles entity IDs and objects. - if (isset($values) && !is_array($values)) { - // Directly update the property instead of invoking the parent, so that - // the entity property can take care of updating the ID property. - $this->properties['entity']->setValue($values, $notify); - } - else { - // Make sure that the 'entity' property gets set as 'target_id'. - if (isset($values['fid']) && !isset($values['entity'])) { - $values['entity'] = $values['fid']; - } - parent::setValue($values, $notify); - } - } } diff --git a/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php b/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php index 927097d0da76dda2d8bd952209c1f002616af8bc..b79ad210f715f8be2c4ec3586c23fad5c105fa9b 100644 --- a/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php +++ b/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php @@ -123,7 +123,7 @@ public function _testPictureFieldFormatters($scheme) { $node = node_load($nid, TRUE); // Test that the default formatter is being used. - $image_uri = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->getFileUri(); + $image_uri = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'])->getFileUri(); $image_info = array( 'uri' => $image_uri, 'width' => 40, diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/FileFieldAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/FileFieldAttributesTest.php index 91845cab36ba6856ba43cf738a193bbe78df827e..11176dc5452397da909b9d015d5a4753f69cb019 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/FileFieldAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/FileFieldAttributesTest.php @@ -73,7 +73,7 @@ public function setUp() { $nid = $this->uploadNodeFile($test_file, $this->fieldName, $type_name); $this->node = node_load($nid, TRUE); - $this->file = file_load($this->node->{$this->fieldName}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $this->file = file_load($this->node->{$this->fieldName}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); } diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/ImageFieldAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/ImageFieldAttributesTest.php index 72bf85af8e2d940bd209bfc1862a832b8dbafa50..338ddfbfa001545c5f3d8231f474e0d1fb2656a8 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/ImageFieldAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/ImageFieldAttributesTest.php @@ -73,7 +73,7 @@ public function setUp() { // Save a node with the image. $nid = $this->uploadNodeImage($image, $this->fieldName, 'article'); $this->node = node_load($nid); - $this->file = file_load($this->node->{$this->fieldName}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $this->file = file_load($this->node->{$this->fieldName}[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php index 376f1e9202606322b18166686d12881be8ab9849..dd9bcf90846076385a4ce76c7162bca40543c985 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php @@ -69,7 +69,7 @@ public function testUserPictureUpgrade() { // Check the user picture and file usage record. $user = user_load(1); - $file = file_load($user->user_picture[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); + $file = file_load($user->user_picture[Language::LANGCODE_NOT_SPECIFIED][0]['target_id']); $this->assertEqual('public://user_pictures_dir/faked_image.png', $file->getFileUri()); $usage = file_usage()->listUsage($file); $this->assertEqual(1, $usage['file']['user'][1]); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Type/TaxonomyTermReferenceItem.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Type/TaxonomyTermReferenceItem.php index 082ed5d1fe9d3d9c8112076ce2d1b39dbb0a4d9c..21c210b02c551baf0eea71a47228b08cc4e8c29f 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Type/TaxonomyTermReferenceItem.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Type/TaxonomyTermReferenceItem.php @@ -7,7 +7,6 @@ namespace Drupal\taxonomy\Type; -use Drupal\Core\Entity\Field\Type\EntityReferenceItem; use Drupal\field\Plugin\Type\FieldType\ConfigEntityReferenceItemBase; /** diff --git a/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php b/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php index 633e0cf5ad21a9c64802a88a29ff5ff07c58769a..282dd6505e6f2ae1e3aa9bd8ae827712bb147b9f 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php @@ -135,6 +135,6 @@ function saveUserPicture($image) { // Load actual user data from database. $account = user_load($this->web_user->uid, TRUE); - return file_load($account->user_picture[Language::LANGCODE_NOT_SPECIFIED][0]['fid'], TRUE); + return file_load($account->user_picture[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'], TRUE); } } diff --git a/core/modules/user/user.install b/core/modules/user/user.install index 361a3e44c06f7be3bae8a08fbdfb32f864531c6b..454c62867bdbfdc03acccc9cf6890c8c56b2decd 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -273,7 +273,7 @@ function user_install_picture_field() { 'type' => 'image', 'cardinality' => 1, 'locked' => FALSE, - 'indexes' => array('fid' => array('fid')), + 'indexes' => array('target_id' => array('target_id')), 'settings' => array( 'uri_scheme' => 'public', 'default_image' => FALSE, @@ -660,7 +660,7 @@ function user_update_8011() { 'type' => 'image', 'cardinality' => 1, 'locked' => FALSE, - 'indexes' => array('fid' => array('fid')), + 'indexes' => array('target_id' => array('target_id')), 'settings' => array( 'uri_scheme' => 'public', 'default_image' => FALSE, @@ -783,7 +783,7 @@ function user_update_8012(&$sandbox) { 'revision_id' => $uid, 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'delta' => 0, - 'user_picture_fid' => $fid, + 'user_picture_target_id' => $fid, )) ->execute(); db_insert('field_revision_user_picture') @@ -794,7 +794,7 @@ function user_update_8012(&$sandbox) { 'revision_id' => $uid, 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'delta' => 0, - 'user_picture_fid' => $fid, + 'user_picture_target_id' => $fid, )) ->execute(); diff --git a/core/profiles/standard/config/field.field.field_image.yml b/core/profiles/standard/config/field.field.field_image.yml index 42204e466b57f57c2965b95a693468d26766cdf4..0fc032a37d4a7d52fd1cec7b212cef42056aa249 100644 --- a/core/profiles/standard/config/field.field.field_image.yml +++ b/core/profiles/standard/config/field.field.field_image.yml @@ -9,7 +9,7 @@ settings: file: label: File columns: - - fid + - target_id - width - height alt: @@ -28,7 +28,7 @@ cardinality: '1' translatable: '0' entity_types: { } indexes: - fid: - - fid + target_id: + - target_id status: 1 langcode: und