summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2013-06-15 08:46:11 (GMT)
committer Alex Pott2013-06-15 08:46:11 (GMT)
commit6d54ed7ac17d13f5d60704a82f6cb1f36e4ba021 (patch)
tree0f586bfb02b6083046f53e5895b1ce76bba85865
parentdb0104f408a3b0486e560350032b884c6237d380 (diff)
Issue #1818568 by Berdir, das-peter: Convert files to the new Entity Field API.
-rw-r--r--core/includes/file.inc24
-rw-r--r--core/modules/aggregator/lib/Drupal/aggregator/Form/OpmlFeedAdd.php2
-rw-r--r--core/modules/file/file.api.php73
-rw-r--r--core/modules/file/file.field.inc10
-rw-r--r--core/modules/file/file.module123
-rw-r--r--core/modules/file/lib/Drupal/file/FileInterface.php122
-rw-r--r--core/modules/file/lib/Drupal/file/FileStorageController.php70
-rw-r--r--core/modules/file/lib/Drupal/file/FileUsage/DatabaseFileUsageBackend.php8
-rw-r--r--core/modules/file/lib/Drupal/file/FileUsage/FileUsageBase.php6
-rw-r--r--core/modules/file/lib/Drupal/file/Plugin/Core/Entity/File.php142
-rw-r--r--core/modules/file/lib/Drupal/file/Plugin/field/formatter/GenericFileFormatter.php2
-rw-r--r--core/modules/file/lib/Drupal/file/Plugin/field/formatter/RSSEnclosureFormatter.php7
-rw-r--r--core/modules/file/lib/Drupal/file/Plugin/field/formatter/UrlPlainFormatter.php2
-rw-r--r--core/modules/file/lib/Drupal/file/Tests/CopyTest.php40
-rw-r--r--core/modules/file/lib/Drupal/file/Tests/DeleteTest.php22
-rw-r--r--core/modules/file/lib/Drupal/file/Tests/DownloadTest.php10
-rw-r--r--core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php8
-rw-r--r--core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php6
-rw-r--r--core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php21
-rw-r--r--core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php29
-rw-r--r--core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php16
-rw-r--r--core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php20
-rw-r--r--core/modules/file/lib/Drupal/file/Tests/FileItemTest.php4
-rw-r--r--core/modules/file/lib/Drupal/file/Tests/FileManagedFileElementTest.php8
-rw-r--r--core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php4
-rw-r--r--core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php6
-rw-r--r--core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php28
-rw-r--r--core/modules/file/lib/Drupal/file/Tests/LoadTest.php20
-rw-r--r--core/modules/file/lib/Drupal/file/Tests/MoveTest.php48
-rw-r--r--core/modules/file/lib/Drupal/file/Tests/SaveDataTest.php60
-rw-r--r--core/modules/file/lib/Drupal/file/Tests/SaveTest.php28
-rw-r--r--core/modules/file/lib/Drupal/file/Tests/SaveUploadTest.php40
-rw-r--r--core/modules/file/lib/Drupal/file/Tests/UsageTest.php36
-rw-r--r--core/modules/file/lib/Drupal/file/Tests/ValidatorTest.php26
-rw-r--r--core/modules/file/tests/file_test/file_test.module14
-rw-r--r--core/modules/file/tests/file_test/lib/Drupal/file_test/Form/FileTestForm.php6
-rw-r--r--core/modules/image/image.field.inc16
-rw-r--r--core/modules/image/image.module8
-rw-r--r--core/modules/image/lib/Drupal/image/Plugin/field/formatter/ImageFormatter.php3
-rw-r--r--core/modules/image/lib/Drupal/image/Tests/FileMoveTest.php (renamed from core/modules/system/lib/Drupal/system/Tests/Image/FileMoveTest.php)16
-rw-r--r--core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php8
-rw-r--r--core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php66
-rw-r--r--core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php18
-rw-r--r--core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php2
-rw-r--r--core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php4
-rw-r--r--core/modules/locale/locale.bulk.inc9
-rw-r--r--core/modules/picture/lib/Drupal/picture/Plugin/field/formatter/PictureFormatter.php2
-rw-r--r--core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php2
-rw-r--r--core/modules/picture/picture.module4
-rw-r--r--core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php4
-rw-r--r--core/modules/rdf/rdf.module6
-rw-r--r--core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php4
-rw-r--r--core/modules/system/lib/Drupal/system/Tests/File/FileTestBase.php41
-rw-r--r--core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php10
-rw-r--r--core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php12
-rw-r--r--core/modules/system/system.admin.inc4
-rw-r--r--core/modules/system/system.tokens.inc23
-rw-r--r--core/modules/update/update.manager.inc2
-rw-r--r--core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php16
59 files changed, 803 insertions, 568 deletions
diff --git a/core/includes/file.inc b/core/includes/file.inc
index 4207ab3..58644ff 100644
--- a/core/includes/file.inc
+++ b/core/includes/file.inc
@@ -1156,22 +1156,22 @@ function file_save_upload($form_field_name, $validators = array(), $destination
if (!empty($extensions)) {
// Munge the filename to protect against possible malicious extension
// hiding within an unknown file type (ie: filename.html.foo).
- $file->filename = file_munge_filename($file->filename, $extensions);
+ $file->setFilename(file_munge_filename($file->getFilename(), $extensions));
}
// Rename potentially executable files, to help prevent exploits (i.e. will
// rename filename.php.foo and filename.php to filename.php.foo.txt and
// filename.php.txt, respectively). Don't rename if 'allow_insecure_uploads'
// evaluates to TRUE.
- if (!config('system.file')->get('allow_insecure_uploads') && preg_match('/\.(php|pl|py|cgi|asp|js)(\.|$)/i', $file->filename) && (substr($file->filename, -4) != '.txt')) {
- $file->filemime = 'text/plain';
- $file->uri .= '.txt';
- $file->filename .= '.txt';
+ if (!config('system.file')->get('allow_insecure_uploads') && preg_match('/\.(php|pl|py|cgi|asp|js)(\.|$)/i', $file->getFilename()) && (substr($file->getFilename(), -4) != '.txt')) {
+ $file->setMimeType('text/plain');
+ $file->setFileUri($file->getFileUri() . '.txt');
+ $file->setFilename($file->getFilename() . '.txt');
// The .txt extension may not be in the allowed list of extensions. We have
// to add it here or else the file upload will fail.
if (!empty($extensions)) {
$validators['file_validate_extensions'][0] .= ' txt';
- drupal_set_message(t('For security reasons, your upload has been renamed to %filename.', array('%filename' => $file->filename)));
+ drupal_set_message(t('For security reasons, your upload has been renamed to %filename.', array('%filename' => $file->getFilename())));
}
}
@@ -1193,7 +1193,7 @@ function file_save_upload($form_field_name, $validators = array(), $destination
if (substr($destination, -1) != '/') {
$destination .= '/';
}
- $file->destination = file_destination($destination . $file->filename, $replace);
+ $file->destination = file_destination($destination . $file->getFilename(), $replace);
// If file_destination() returns FALSE then $replace === FILE_EXISTS_ERROR and
// there's an existing file so we need to bail.
if ($file->destination === FALSE) {
@@ -1210,7 +1210,7 @@ function file_save_upload($form_field_name, $validators = array(), $destination
// Check for errors.
if (!empty($errors)) {
- $message = t('The specified file %name could not be uploaded.', array('%name' => $file->filename));
+ $message = t('The specified file %name could not be uploaded.', array('%name' => $file->getFilename()));
if (count($errors) > 1) {
$message .= theme('item_list', array('items' => $errors));
}
@@ -1226,7 +1226,7 @@ function file_save_upload($form_field_name, $validators = array(), $destination
// directory. This overcomes open_basedir restrictions for future file
// operations.
$file->uri = $file->destination;
- if (!drupal_move_uploaded_file($uploaded_files['files']['tmp_name'][$form_field_name][$i], $file->uri)) {
+ if (!drupal_move_uploaded_file($uploaded_files['files']['tmp_name'][$form_field_name][$i], $file->getFileUri())) {
form_set_error($form_field_name, t('File upload error. Could not move uploaded file.'));
watchdog('file', 'Upload error. Could not move uploaded file %file to destination %destination.', array('%file' => $file->filename, '%destination' => $file->uri));
$files[$i] = FALSE;
@@ -1234,14 +1234,14 @@ function file_save_upload($form_field_name, $validators = array(), $destination
}
// Set the permissions on the new file.
- drupal_chmod($file->uri);
+ drupal_chmod($file->getFileUri());
// If we are replacing an existing file re-use its database record.
if ($replace == FILE_EXISTS_REPLACE) {
- $existing_files = entity_load_multiple_by_properties('file', array('uri' => $file->uri));
+ $existing_files = entity_load_multiple_by_properties('file', array('uri' => $file->getFileUri()));
if (count($existing_files)) {
$existing = reset($existing_files);
- $file->fid = $existing->fid;
+ $file->fid = $existing->id();
}
}
diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/OpmlFeedAdd.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/OpmlFeedAdd.php
index 5035346..60ab96b 100644
--- a/core/modules/aggregator/lib/Drupal/aggregator/Form/OpmlFeedAdd.php
+++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/OpmlFeedAdd.php
@@ -157,7 +157,7 @@ class OpmlFeedAdd implements ControllerInterface, FormInterface {
$data = '';
$validators = array('file_validate_extensions' => array('opml xml'));
if ($file = file_save_upload('upload', $validators, FALSE, 0)) {
- $data = file_get_contents($file->uri);
+ $data = file_get_contents($file->getFileUri());
}
else {
// @todo Move this to a fetcher implementation.
diff --git a/core/modules/file/file.api.php b/core/modules/file/file.api.php
index a6d11d5..49d9af8 100644
--- a/core/modules/file/file.api.php
+++ b/core/modules/file/file.api.php
@@ -49,7 +49,7 @@ function hook_file_load($files) {
* This hook lets modules perform additional validation on files. They're able
* to report a failure by returning one or more error messages.
*
- * @param Drupal\file\File $file
+ * @param \Drupal\file\FileInterface $file
* The file entity being validated.
* @return
* An array of error messages. If there are no problems with the file return
@@ -57,13 +57,13 @@ function hook_file_load($files) {
*
* @see file_validate()
*/
-function hook_file_validate(Drupal\file\File $file) {
+function hook_file_validate(Drupal\file\FileInterface $file) {
$errors = array();
- if (empty($file->filename)) {
+ if (!$file->getFilename()) {
$errors[] = t("The file's name is empty. Please give a name to the file.");
}
- if (strlen($file->filename) > 255) {
+ if (strlen($file->getFilename()) > 255) {
$errors[] = t("The file's name exceeds the 255 characters limit. Please rename the file and try again.");
}
@@ -77,10 +77,10 @@ function hook_file_validate(Drupal\file\File $file) {
* doesn't distinguish between files created as a result of a copy or those
* created by an upload.
*
- * @param Drupal\file\File $file
+ * @param \Drupal\file\FileInterface $file
* The file entity that is about to be created or updated.
*/
-function hook_file_presave(Drupal\file\File $file) {
+function hook_file_presave(Drupal\file\FileInterface $file) {
// Change the file timestamp to an hour prior.
$file->timestamp -= 3600;
}
@@ -92,10 +92,10 @@ function hook_file_presave(Drupal\file\File $file) {
* doesn't distinguish between files created as a result of a copy or those
* created by an upload.
*
- * @param Drupal\file\File $file
+ * @param \Drupal\file\FileInterface $file
* The file that has been added.
*/
-function hook_file_insert(Drupal\file\File $file) {
+function hook_file_insert(Drupal\file\FileInterface $file) {
// Add a message to the log, if the file is a jpg
$validate = file_validate_extensions($file, 'jpg');
if (empty($validate)) {
@@ -108,60 +108,57 @@ function hook_file_insert(Drupal\file\File $file) {
*
* This hook is called when an existing file is saved.
*
- * @param Drupal\file\File $file
+ * @param \Drupal\file\FileInterface $file
* The file that has just been updated.
*/
-function hook_file_update(Drupal\file\File $file) {
- $file_user = user_load($file->uid);
+function hook_file_update(Drupal\file\FileInterface $file) {
// Make sure that the file name starts with the owner's user name.
- if (strpos($file->filename, $file_user->name) !== 0) {
- $old_filename = $file->filename;
- $file->filename = $file_user->name . '_' . $file->filename;
+ if (strpos($file->getFilename(), $file->getOwner()->name) !== 0) {
+ $old_filename = $file->getFilename();
+ $file->setFilename($file->getOwner()->name . '_' . $file->getFilename());
$file->save();
- watchdog('file', t('%source has been renamed to %destination', array('%source' => $old_filename, '%destination' => $file->filename)));
+ watchdog('file', t('%source has been renamed to %destination', array('%source' => $old_filename, '%destination' => $file->getFilename())));
}
}
/**
* Respond to a file that has been copied.
*
- * @param Drupal\file\File $file
+ * @param \Drupal\file\FileInterface $file
* The newly copied file entity.
- * @param Drupal\file\File $source
+ * @param \Drupal\file\FileInterface $source
* The original file before the copy.
*
* @see file_copy()
*/
-function hook_file_copy(Drupal\file\File $file, Drupal\file\File $source) {
- $file_user = user_load($file->uid);
+function hook_file_copy(Drupal\file\FileInterface $file, Drupal\file\FileInterface $source) {
// Make sure that the file name starts with the owner's user name.
- if (strpos($file->filename, $file_user->name) !== 0) {
- $file->filename = $file_user->name . '_' . $file->filename;
+ if (strpos($file->getFilename(), $file->getOwner()->name) !== 0) {
+ $file->setFilename($file->getOwner()->name . '_' . $file->getFilename());
$file->save();
- watchdog('file', t('Copied file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->filename)));
+ watchdog('file', t('Copied file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->getFilename())));
}
}
/**
* Respond to a file that has been moved.
*
- * @param Drupal\file\File $file
+ * @param \Drupal\file\FileInterface $file
* The updated file entity after the move.
- * @param Drupal\file\File $source
+ * @param \Drupal\file\FileInterface $source
* The original file entity before the move.
*
* @see file_move()
*/
-function hook_file_move(Drupal\file\File $file, Drupal\file\File $source) {
- $file_user = user_load($file->uid);
+function hook_file_move(Drupal\file\FileInterface $file, Drupal\file\FileInterface $source) {
// Make sure that the file name starts with the owner's user name.
- if (strpos($file->filename, $file_user->name) !== 0) {
- $file->filename = $file_user->name . '_' . $file->filename;
+ if (strpos($file->getFilename(), $file->getOwner()->name) !== 0) {
+ $file->setFilename($file->getOwner()->name . '_' . $file->getFilename());
$file->save();
- watchdog('file', t('Moved file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->filename)));
+ watchdog('file', t('Moved file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->getFilename())));
}
}
@@ -171,16 +168,16 @@ function hook_file_move(Drupal\file\File $file, Drupal\file\File $source) {
* This hook is invoked when deleting a file before the file is removed from the
* filesystem and before its records are removed from the database.
*
- * @param Drupal\file\File $file
+ * @param \Drupal\file\FileInterface $file
* The file that is about to be deleted.
*
* @see hook_file_delete()
* @see Drupal\file\FileStorageController::delete()
* @see upload_file_delete()
*/
-function hook_file_predelete(Drupal\file\File $file) {
+function hook_file_predelete(Drupal\file\FileInterface $file) {
// Delete all information associated with the file.
- db_delete('upload')->condition('fid', $file->fid)->execute();
+ db_delete('upload')->condition('fid', $file->id())->execute();
}
/**
@@ -189,15 +186,15 @@ function hook_file_predelete(Drupal\file\File $file) {
* This hook is invoked after the file has been removed from
* the filesystem and after its records have been removed from the database.
*
- * @param Drupal\file\File $file
+ * @param \Drupal\file\FileInterface $file
* The file that has just been deleted.
*
* @see hook_file_predelete()
* @see Drupal\file\FileStorageController::delete()
*/
-function hook_file_delete(Drupal\file\File $file) {
+function hook_file_delete(Drupal\file\FileInterface $file) {
// Delete all information associated with the file.
- db_delete('upload')->condition('fid', $file->fid)->execute();
+ db_delete('upload')->condition('fid', $file->id())->execute();
}
/**
@@ -209,9 +206,9 @@ function hook_file_delete(Drupal\file\File $file) {
*
* @param $field
* The field to which the file belongs.
- * @param Drupal\Core\Entity\EntityInterface $entity
+ * @param \Drupal\Core\Entity\EntityInterface $entity
* The entity which references the file.
- * @param Drupal\file\File $file
+ * @param \Drupal\file\FileInterface $file
* The file entity that is being requested.
*
* @return
@@ -221,7 +218,7 @@ function hook_file_delete(Drupal\file\File $file) {
*
* @see hook_field_access().
*/
-function hook_file_download_access($field, Drupal\Core\Entity\EntityInterface $entity, Drupal\file\File $file) {
+function hook_file_download_access($field, Drupal\Core\Entity\EntityInterface $entity, Drupal\file\FileInterface $file) {
if ($entity->entityType() == 'node') {
return node_access('view', $entity);
}
diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc
index d8da611..cb76631 100644
--- a/core/modules/file/file.field.inc
+++ b/core/modules/file/file.field.inc
@@ -211,7 +211,7 @@ function file_field_prepare_view($entity_type, $entities, $field, $instances, $l
$items[$id][$delta] = NULL;
}
else {
- $items[$id][$delta] = array_merge($item, (array) $files[$item['fid']]);
+ $items[$id][$delta]['entity'] = $files[$item['fid']];
}
}
}
@@ -419,7 +419,7 @@ function file_field_widget_multiple_count_validate($element, &$form_state, $form
$removed_names = array();
foreach ($removed_files as $fid) {
$file = file_load($fid);
- $removed_names[] = $file->filename;
+ $removed_names[] = $file->getFilename();
}
drupal_set_message(
t(
@@ -654,7 +654,7 @@ function theme_file_widget($variables) {
if (!empty($element['fids']['#value'])) {
// Add the file size after the file name.
$file = reset($element['#files']);
- $element['file_' . $file->fid]['filename']['#markup'] .= ' <span class="file-size">(' . format_size($file->filesize) . ')</span> ';
+ $element['file_' . $file->id()]['filename']['#markup'] .= ' <span class="file-size">(' . format_size($file->getSize()) . ')</span> ';
}
$output .= drupal_render_children($element);
$output .= '</div>';
@@ -861,8 +861,8 @@ function theme_file_formatter_table($variables) {
$rows = array();
foreach ($variables['items'] as $delta => $item) {
$rows[] = array(
- theme('file_link', array('file' => (object) $item)),
- format_size($item['filesize']),
+ theme('file_link', array('file' => $item['entity'])),
+ format_size($item['entity']->getSize()),
);
}
diff --git a/core/modules/file/file.module b/core/modules/file/file.module
index 65b15e5..3832d80 100644
--- a/core/modules/file/file.module
+++ b/core/modules/file/file.module
@@ -118,7 +118,7 @@ function file_load_multiple(array $fids = NULL, $reset = FALSE) {
* @param $reset
* Whether to reset the internal file_load_multiple() cache.
*
- * @return Drupal\file\File
+ * @return \Drupal\file\FileInterface
* A file entity or FALSE if the file was not found.
*
* @see hook_file_load()
@@ -175,34 +175,33 @@ function file_usage() {
*/
function file_copy(File $source, $destination = NULL, $replace = FILE_EXISTS_RENAME) {
if (!file_valid_uri($destination)) {
- if (($realpath = drupal_realpath($source->uri)) !== FALSE) {
- watchdog('file', 'File %file (%realpath) could not be copied because the destination %destination is invalid. This is often caused by improper use of file_copy() or a missing stream wrapper.', array('%file' => $source->uri, '%realpath' => $realpath, '%destination' => $destination));
+ if (($realpath = drupal_realpath($source->getFileUri())) !== FALSE) {
+ watchdog('file', 'File %file (%realpath) could not be copied because the destination %destination is invalid. This is often caused by improper use of file_copy() or a missing stream wrapper.', array('%file' => $source->getFileUri(), '%realpath' => $realpath, '%destination' => $destination));
}
else {
- watchdog('file', 'File %file could not be copied because the destination %destination is invalid. This is often caused by improper use of file_copy() or a missing stream wrapper.', array('%file' => $source->uri, '%destination' => $destination));
+ watchdog('file', 'File %file could not be copied because the destination %destination is invalid. This is often caused by improper use of file_copy() or a missing stream wrapper.', array('%file' => $source->getFileUri(), '%destination' => $destination));
}
- drupal_set_message(t('The specified file %file could not be copied because the destination is invalid. More information is available in the system log.', array('%file' => $source->uri)), 'error');
+ drupal_set_message(t('The specified file %file could not be copied because the destination is invalid. More information is available in the system log.', array('%file' => $source->getFileUri())), 'error');
return FALSE;
}
- if ($uri = file_unmanaged_copy($source->uri, $destination, $replace)) {
- $file = clone $source;
- $file->fid = NULL;
- $file->uri = $uri;
- $file->filename = drupal_basename($uri);
+ if ($uri = file_unmanaged_copy($source->getFileUri(), $destination, $replace)) {
+ $file = $source->createDuplicate();
+ $file->setFileUri($uri);
+ $file->setFilename(drupal_basename($uri));
// If we are replacing an existing file re-use its database record.
if ($replace == FILE_EXISTS_REPLACE) {
$existing_files = entity_load_multiple_by_properties('file', array('uri' => $uri));
if (count($existing_files)) {
$existing = reset($existing_files);
- $file->fid = $existing->fid;
- $file->filename = $existing->filename;
+ $file->fid = $existing->id();
+ $file->setFilename($existing->getFilename());
}
}
// If we are renaming around an existing file (rather than a directory),
// use its basename for the filename.
elseif ($replace == FILE_EXISTS_RENAME && is_file($destination)) {
- $file->filename = drupal_basename($destination);
+ $file->setFilename(drupal_basename($destination));
}
$file->save();
@@ -250,34 +249,34 @@ function file_copy(File $source, $destination = NULL, $replace = FILE_EXISTS_REN
*/
function file_move(File $source, $destination = NULL, $replace = FILE_EXISTS_RENAME) {
if (!file_valid_uri($destination)) {
- if (($realpath = drupal_realpath($source->uri)) !== FALSE) {
- watchdog('file', 'File %file (%realpath) could not be moved because the destination %destination is invalid. This may be caused by improper use of file_move() or a missing stream wrapper.', array('%file' => $source->uri, '%realpath' => $realpath, '%destination' => $destination));
+ if (($realpath = drupal_realpath($source->getFileUri())) !== FALSE) {
+ watchdog('file', 'File %file (%realpath) could not be moved because the destination %destination is invalid. This may be caused by improper use of file_move() or a missing stream wrapper.', array('%file' => $source->getFileUri(), '%realpath' => $realpath, '%destination' => $destination));
}
else {
- watchdog('file', 'File %file could not be moved because the destination %destination is invalid. This may be caused by improper use of file_move() or a missing stream wrapper.', array('%file' => $source->uri, '%destination' => $destination));
+ watchdog('file', 'File %file could not be moved because the destination %destination is invalid. This may be caused by improper use of file_move() or a missing stream wrapper.', array('%file' => $source->getFileUri(), '%destination' => $destination));
}
- drupal_set_message(t('The specified file %file could not be moved because the destination is invalid. More information is available in the system log.', array('%file' => $source->uri)), 'error');
+ drupal_set_message(t('The specified file %file could not be moved because the destination is invalid. More information is available in the system log.', array('%file' => $source->getFileUri())), 'error');
return FALSE;
}
- if ($uri = file_unmanaged_move($source->uri, $destination, $replace)) {
+ if ($uri = file_unmanaged_move($source->getFileUri(), $destination, $replace)) {
$delete_source = FALSE;
$file = clone $source;
- $file->uri = $uri;
+ $file->setFileUri($uri);
// If we are replacing an existing file re-use its database record.
if ($replace == FILE_EXISTS_REPLACE) {
$existing_files = entity_load_multiple_by_properties('file', array('uri' => $uri));
if (count($existing_files)) {
$existing = reset($existing_files);
$delete_source = TRUE;
- $file->fid = $existing->fid;
+ $file->fid = $existing->id();
}
}
// If we are renaming around an existing file (rather than a directory),
// use its basename for the filename.
elseif ($replace == FILE_EXISTS_RENAME && is_file($destination)) {
- $file->filename = drupal_basename($destination);
+ $file->setFilename(drupal_basename($destination));
}
$file->save();
@@ -342,10 +341,10 @@ function file_validate(File $file, $validators = array()) {
function file_validate_name_length(File $file) {
$errors = array();
- if (empty($file->filename)) {
+ if (!$file->getFilename()) {
$errors[] = t("The file's name is empty. Please give a name to the file.");
}
- if (strlen($file->filename) > 240) {
+ if (strlen($file->getFilename()) > 240) {
$errors[] = t("The file's name exceeds the 240 characters limit. Please rename the file and try again.");
}
return $errors;
@@ -369,7 +368,7 @@ function file_validate_extensions(File $file, $extensions) {
$errors = array();
$regex = '/\.(' . preg_replace('/ +/', '|', preg_quote($extensions)) . ')$/i';
- if (!preg_match($regex, $file->filename)) {
+ if (!preg_match($regex, $file->getFilename())) {
$errors[] = t('Only files with the following extensions are allowed: %files-allowed.', array('%files-allowed' => $extensions));
}
return $errors;
@@ -397,13 +396,13 @@ function file_validate_size(File $file, $file_limit = 0, $user_limit = 0) {
global $user;
$errors = array();
- if ($file_limit && $file->filesize > $file_limit) {
- $errors[] = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size($file->filesize), '%maxsize' => format_size($file_limit)));
+ if ($file_limit && $file->getSize() > $file_limit) {
+ $errors[] = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size($file->getSize()), '%maxsize' => format_size($file_limit)));
}
// Save a query by only calling spaceUsed() when a limit is provided.
- if ($user_limit && (Drupal::entityManager()->getStorageController('file')->spaceUsed($user->uid) + $file->filesize) > $user_limit) {
- $errors[] = t('The file is %filesize which would exceed your disk quota of %quota.', array('%filesize' => format_size($file->filesize), '%quota' => format_size($user_limit)));
+ if ($user_limit && (Drupal::entityManager()->getStorageController('file')->spaceUsed($user->uid) + $file->getSize()) > $user_limit) {
+ $errors[] = t('The file is %filesize which would exceed your disk quota of %quota.', array('%filesize' => format_size($file->getSize()), '%quota' => format_size($user_limit)));
}
return $errors;
@@ -423,7 +422,7 @@ function file_validate_size(File $file, $file_limit = 0, $user_limit = 0) {
function file_validate_is_image(File $file) {
$errors = array();
- $info = image_get_info($file->uri);
+ $info = image_get_info($file->getFileUri());
if (!$info || empty($info['extension'])) {
$errors[] = t('Only JPEG, PNG and GIF images are allowed.');
}
@@ -458,13 +457,13 @@ function file_validate_image_resolution(File $file, $maximum_dimensions = 0, $mi
$errors = array();
// Check first that the file is an image.
- if ($info = image_get_info($file->uri)) {
+ if ($info = image_get_info($file->getFileUri())) {
if ($maximum_dimensions) {
// Check that it is smaller than the given dimensions.
list($width, $height) = explode('x', $maximum_dimensions);
if ($info['width'] > $width || $info['height'] > $height) {
// Try to resize the image to fit the dimensions.
- if ($image = image_load($file->uri)) {
+ if ($image = image_load($file->getFileUri())) {
image_scale($image, $width, $height);
image_save($image);
$file->filesize = $image->info['file_size'];
@@ -506,7 +505,7 @@ function file_validate_image_resolution(File $file, $maximum_dimensions = 0, $mi
* unique.
* - FILE_EXISTS_ERROR - Do nothing and return FALSE.
*
- * @return Drupal\file\File
+ * @return \Drupal\file\FileInterface
* A file entity, or FALSE on error.
*
* @see file_unmanaged_save_data()
@@ -535,14 +534,14 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM
$existing_files = entity_load_multiple_by_properties('file', array('uri' => $uri));
if (count($existing_files)) {
$existing = reset($existing_files);
- $file->fid = $existing->fid;
- $file->filename = $existing->filename;
+ $file->fid = $existing->id();
+ $file->setFilename($existing->getFilename());
}
}
// If we are renaming around an existing file (rather than a directory),
// use its basename for the filename.
elseif ($replace == FILE_EXISTS_RENAME && is_file($destination)) {
- $file->filename = drupal_basename($destination);
+ $file->setFilename(drupal_basename($destination));
}
$file->save();
@@ -562,12 +561,12 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM
* \Symfony\Component\HttpFoundation\StreamedResponse.
*/
function file_get_content_headers(File $file) {
- $name = mime_header_encode($file->filename);
- $type = mime_header_encode($file->filemime);
+ $name = mime_header_encode($file->getFilename());
+ $type = mime_header_encode($file->getMimeType());
return array(
'Content-Type' => $type,
- 'Content-Length' => $file->filesize,
+ 'Content-Length' => $file->getSize(),
'Cache-Control' => 'private',
);
}
@@ -619,7 +618,7 @@ function file_file_download($uri, $field_type = 'file') {
foreach ($files as $item) {
// Since some database servers sometimes use a case-insensitive comparison
// by default, double check that the filename is an exact match.
- if ($item->uri === $uri) {
+ if ($item->getFileUri() === $uri) {
$file = $item;
break;
}
@@ -637,7 +636,7 @@ function file_file_download($uri, $field_type = 'file') {
// temporary files where the host entity has not yet been saved (for example,
// an image preview on a node/add form) in which case, allow download by the
// file's owner.
- if (empty($references) && ($file->status == FILE_STATUS_PERMANENT || $file->uid != $user->uid)) {
+ if (empty($references) && ($file->isPermanent() || $file->getOwner()->id() != $user->uid)) {
return;
}
@@ -709,15 +708,15 @@ function file_cron() {
if ($file = file_load($row->fid)) {
$references = file_usage()->listUsage($file);
if (empty($references)) {
- if (file_exists($file->uri)) {
+ if (file_exists($file->getFileUri())) {
$file->delete();
}
else {
- watchdog('file system', 'Could not delete temporary file "%path" during garbage collection', array('%path' => $file->uri), WATCHDOG_ERROR);
+ watchdog('file system', 'Could not delete temporary file "%path" during garbage collection', array('%path' => $file->getFileUri()), WATCHDOG_ERROR);
}
}
else {
- watchdog('file system', 'Did not delete temporary file "%path" during garbage collection because it is in use by the following modules: %modules.', array('%path' => $file->uri, '%modules' => implode(', ', array_keys($references))), WATCHDOG_INFO);
+ watchdog('file system', 'Did not delete temporary file "%path" during garbage collection because it is in use by the following modules: %modules.', array('%path' => $file->getFileUri(), '%modules' => implode(', ', array_keys($references))), WATCHDOG_INFO);
}
}
}
@@ -1033,7 +1032,7 @@ function file_managed_file_value(&$element, $input = FALSE, $form_state = NULL)
$fids = array();
foreach ($input['fids'] as $key => $fid) {
if ($file = file_load($fid)) {
- $fids[] = $file->fid;
+ $fids[] = $file->id();
}
}
}
@@ -1056,7 +1055,7 @@ function file_managed_file_value(&$element, $input = FALSE, $form_state = NULL)
$fids = array();
foreach ($default_fids as $key => $fid) {
if ($file = file_load($fid)) {
- $fids[] = $file->fid;
+ $fids[] = $file->id();
}
}
}
@@ -1081,7 +1080,7 @@ function file_managed_file_validate(&$element, &$form_state) {
$fids = $element['fids']['#value'];
foreach ($fids as $fid) {
if ($file = file_load($fid)) {
- if ($file->status == FILE_STATUS_PERMANENT) {
+ if ($file->isPermanent()) {
$references = file_usage()->listUsage($file);
if (empty($references)) {
form_error($element, t('The file used in the !name field may not be referenced.', array('!name' => $element['#title'])));
@@ -1145,8 +1144,8 @@ function file_managed_file_submit($form, &$form_state) {
// If it's a temporary file we can safely remove it immediately, otherwise
// it's up to the implementing module to remove usages of files to have them
// removed.
- if ($element['#files'][$fid] && $element['#files'][$fid]->status == 0) {
- file_delete($element['#files'][$fid]->fid);
+ if ($element['#files'][$fid] && $element['#files'][$fid]->isTemporary()) {
+ $element['#files'][$fid]->delete();
}
}
// Update both $form_state['values'] and $form_state['input'] to reflect
@@ -1204,7 +1203,7 @@ function file_managed_file_save_upload($element) {
// Value callback expects FIDs to be keys.
$files = array_filter($files);
- $fids = array_map(function($file) { return $file->fid; }, $files);
+ $fids = array_map(function($file) { return $file->id(); }, $files);
return empty($files) ? array() : array_combine($fids, $files);
}
@@ -1294,7 +1293,7 @@ function theme_file_link($variables) {
$file = $variables['file'];
$icon_directory = $variables['icon_directory'];
- $url = file_create_url($file->uri);
+ $url = file_create_url($file->getFileUri());
// theme_file_icon() requires a file entity, make sure it gets one.
$icon = theme('file_icon', array('file' => $file, 'icon_directory' => $icon_directory));
@@ -1302,17 +1301,17 @@ function theme_file_link($variables) {
// http://microformats.org/wiki/file-format-examples
$options = array(
'attributes' => array(
- 'type' => $file->filemime . '; length=' . $file->filesize,
+ 'type' => $file->getMimeType() . '; length=' . $file->getSize(),
),
);
// Use the description as the link text if available.
if (empty($variables['description'])) {
- $link_text = $file->filename;
+ $link_text = $file->getFilename();
}
else {
$link_text = $variables['description'];
- $options['attributes']['title'] = check_plain($file->filename);
+ $options['attributes']['title'] = check_plain($file->getFilename());
}
return '<span class="file">' . $icon . ' ' . l($link_text, $url, $options) . '</span>';
@@ -1334,7 +1333,7 @@ function theme_file_icon($variables) {
$file = $variables['file'];
$icon_directory = $variables['icon_directory'];
- $mime = check_plain($file->filemime);
+ $mime = check_plain($file->getMimeType());
$icon_url = file_icon_url($file, $icon_directory);
return '<img class="file-icon" alt="" title="' . $mime . '" src="' . $icon_url . '" />';
}
@@ -1378,7 +1377,7 @@ function file_icon_path(File $file, $icon_directory = NULL) {
}
// If there's an icon matching the exact mimetype, go for it.
- $dashed_mime = strtr($file->filemime, array('/' => '-'));
+ $dashed_mime = strtr($file->getMimeType(), array('/' => '-'));
$icon_path = $icon_directory . '/' . $dashed_mime . '.png';
if (file_exists($icon_path)) {
return $icon_path;
@@ -1393,7 +1392,7 @@ function file_icon_path(File $file, $icon_directory = NULL) {
// Use generic icons for each category that provides such icons.
foreach (array('audio', 'image', 'text', 'video') as $category) {
- if (strpos($file->filemime, $category . '/') === 0) {
+ if (strpos($file->getMimeType(), $category . '/') === 0) {
$icon_path = $icon_directory . '/' . $category . '-x-generic.png';
if (file_exists($icon_path)) {
return $icon_path;
@@ -1421,7 +1420,7 @@ function file_icon_path(File $file, $icon_directory = NULL) {
* The generic icon MIME package expected for this file.
*/
function file_icon_map(File $file) {
- switch ($file->filemime) {
+ switch ($file->getMimeType()) {
// Word document types.
case 'application/msword':
case 'application/vnd.ms-word.document.macroEnabled.12':
@@ -1570,8 +1569,8 @@ function file_get_file_references(File $file, $field = NULL, $age = FIELD_LOAD_R
$field_columns = &drupal_static(__FUNCTION__ . ':field_columns', array());
// Fill the static cache, disregard $field and $field_type for now.
- if (!isset($references[$file->fid][$age])) {
- $references[$file->fid][$age] = array();
+ if (!isset($references[$file->id()][$age])) {
+ $references[$file->id()][$age] = array();
$usage_list = file_usage()->listUsage($file);
$file_usage_list = isset($usage_list['file']) ? $usage_list['file'] : array();
foreach ($file_usage_list as $entity_type => $entity_ids) {
@@ -1609,20 +1608,20 @@ function file_get_file_references(File $file, $field = NULL, $age = FIELD_LOAD_R
// revision.
if (!$match && ($field_items = field_get_items($entity, $field_name))) {
foreach ($field_items as $item) {
- if ($file->fid == $item[$field_column]) {
+ if ($file->id() == $item[$field_column]) {
$match = TRUE;
break;
}
}
}
if ($match) {
- $references[$file->fid][$age][$field_name][$entity_type][$entity->id()] = $entity;
+ $references[$file->id()][$age][$field_name][$entity_type][$entity->id()] = $entity;
}
}
}
}
}
- $return = $references[$file->fid][$age];
+ $return = $references[$file->id()][$age];
// Filter the static cache down to the requested entries. The usual static
// cache is very small so this will be very fast.
if ($field || $field_type) {
diff --git a/core/modules/file/lib/Drupal/file/FileInterface.php b/core/modules/file/lib/Drupal/file/FileInterface.php
index 5912491..2339d88 100644
--- a/core/modules/file/lib/Drupal/file/FileInterface.php
+++ b/core/modules/file/lib/Drupal/file/FileInterface.php
@@ -8,10 +8,130 @@
namespace Drupal\file;
use Drupal\Core\Entity\ContentEntityInterface;
+use Drupal\user\UserInterface;
/**
- * Provides an interface defining a file entity.
+ * Defines getter and setter methods for file entity base fields.
*/
interface FileInterface extends ContentEntityInterface {
+ /**
+ * Returns the name of the file.
+ *
+ * This may differ from the basename of the URI if the file is renamed to
+ * avoid overwriting an existing file.
+ *
+ * @return string
+ * Name of the file.
+ */
+ public function getFilename();
+
+ /**
+ * Sets the name of the file.
+ *
+ * @param string $filename
+ * The file name that corresponds to this file. May differ from the basename
+ * of the URI and changing the filename does not change the URI.
+ */
+ public function setFilename($filename);
+
+ /**
+ * Returns the URI of the file.
+ *
+ * @return string
+ * The URI of the file, e.g. public://directory/file.jpg.
+ */
+ public function getFileUri();
+
+ /**
+ * Sets the URI of the file.
+ *
+ * @param string $uri
+ * The URI of the file, e.g. public://directory/file.jpg. Does not change
+ * the location of the file.
+ */
+ public function setFileUri($uri);
+
+ /**
+ * Returns the MIME type of the file.
+ *
+ * @return string
+ * The MIME type of the file, e.g. image/jpeg or text/xml.
+ */
+ public function getMimeType();
+
+ /**
+ * Sets the MIME type of the file.
+ *
+ * @param string $mime
+ * The MIME type of the file, e.g. image/jpeg or text/xml.
+ */
+ public function setMimeType($mime);
+
+ /**
+ * Returns the size of the file.
+ *
+ * @return string
+ * The size of the file in bytes.
+ */
+ public function getSize();
+
+ /**
+ * Sets the size of the file.
+ *
+ * @param int $size
+ * The size of the file in bytes.
+ */
+ public function setSize($size);
+
+ /**
+ * Returns TRUE if the file is permanent.
+ *
+ * @return bool
+ * TRUE if the file status is permanent.
+ */
+ public function isPermanent();
+
+ /**
+ * Returns TRUE if the file is temporary.
+ *
+ * @return bool
+ * TRUE if the file status is temporary.
+ */
+ public function isTemporary();
+
+ /**
+ * Sets the file status to permanent.
+ */
+ public function setPermanent();
+
+ /**
+ * Sets the file status to temporary.
+ */
+ public function setTemporary();
+
+ /**
+ * Returns the timestamp when the file was created.
+ *
+ * @return int
+ * Creation timestamp of the file.
+ */
+ public function getChangedTime();
+
+ /**
+ * Returns the user that owns this file.
+ *
+ * @return \Drupal\user\UserInterface
+ * The user that owns the file.
+ */
+ public function getOwner();
+
+ /**
+ * Sets the user that owns this file.
+ *
+ * @param \Drupal\user\UserInterface $user
+ * The user that owns the file.
+ */
+ public function setOwner(UserInterface $user);
+
}
diff --git a/core/modules/file/lib/Drupal/file/FileStorageController.php b/core/modules/file/lib/Drupal/file/FileStorageController.php
index d3ca601..dd65e6f 100644
--- a/core/modules/file/lib/Drupal/file/FileStorageController.php
+++ b/core/modules/file/lib/Drupal/file/FileStorageController.php
@@ -7,14 +7,14 @@
namespace Drupal\file;
-use Drupal\Core\Entity\DatabaseStorageController;
+use Drupal\Core\Entity\DatabaseStorageControllerNG;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Language\Language;
/**
* File storage controller for files.
*/
-class FileStorageController extends DatabaseStorageController {
+class FileStorageController extends DatabaseStorageControllerNG {
/**
* Overrides Drupal\Core\Entity\DatabaseStorageController::create().
@@ -37,8 +37,8 @@ class FileStorageController extends DatabaseStorageController {
*/
protected function preSave(EntityInterface $entity) {
$entity->timestamp = REQUEST_TIME;
- $entity->filesize = filesize($entity->uri);
- if (!isset($entity->langcode)) {
+ $entity->setSize(filesize($entity->getFileUri()));
+ if (!$entity->langcode->value) {
// Default the file's language code to none, because files are language
// neutral more often than language dependent. Until we have better
// flexible settings.
@@ -55,7 +55,7 @@ class FileStorageController extends DatabaseStorageController {
// Delete the actual file. Failures due to invalid files and files that
// were already deleted are logged to watchdog but ignored, the
// corresponding file entity will be deleted.
- file_unmanaged_delete($entity->uri);
+ file_unmanaged_delete($entity->getFileUri());
}
// Delete corresponding file usage entries.
db_delete('file_usage')
@@ -100,4 +100,64 @@ class FileStorageController extends DatabaseStorageController {
':timestamp' => REQUEST_TIME - DRUPAL_MAXIMUM_TEMP_FILE_AGE
));
}
+
+ /**
+ * {@inheritdoc}
+ */
+ public function baseFieldDefinitions() {
+ $properties['fid'] = array(
+ 'label' => t('File ID'),
+ 'description' => t('The file ID.'),
+ 'type' => 'integer_field',
+ 'read-only' => TRUE,
+ );
+ $properties['uuid'] = array(
+ 'label' => t('UUID'),
+ 'description' => t('The file UUID.'),
+ 'type' => 'string_field',
+ 'read-only' => TRUE,
+ );
+ $properties['langcode'] = array(
+ 'label' => t('Language code'),
+ 'description' => t('The file language code.'),
+ 'type' => 'language_field',
+ );
+ $properties['uid'] = array(
+ 'label' => t('User ID'),
+ 'description' => t('The user ID of the file.'),
+ 'type' => 'entity_reference_field',
+ 'settings' => array('target_type' => 'user'),
+ );
+ $properties['filename'] = array(
+ 'label' => t('Filename'),
+ 'description' => t('Name of the file with no path components.'),
+ 'type' => 'string_field',
+ );
+ $properties['uri'] = array(
+ 'label' => t('URI'),
+ 'description' => t('The URI to access the file (either local or remote).'),
+ 'type' => 'string_field',
+ );
+ $properties['filemime'] = array(
+ 'label' => t('File MIME type'),
+ 'description' => t("The file's MIME type."),
+ 'type' => 'string_field',
+ );
+ $properties['filesize'] = array(
+ 'label' => t('File size'),
+ 'description' => t('The size of the file in bytes.'),
+ 'type' => 'boolean_field',
+ );
+ $properties['status'] = array(
+ 'label' => t('Status'),
+ 'description' => t('The status of the file, temporary (0) and permanent (1)'),
+ 'type' => 'integer_field',
+ );
+ $properties['timestamp'] = array(
+ 'label' => t('Created'),
+ 'description' => t('The time that the node was created.'),
+ 'type' => 'integer_field',
+ );
+ return $properties;
+ }
}
diff --git a/core/modules/file/lib/Drupal/file/FileUsage/DatabaseFileUsageBackend.php b/core/modules/file/lib/Drupal/file/FileUsage/DatabaseFileUsageBackend.php
index eaca4bf..80163c4 100644
--- a/core/modules/file/lib/Drupal/file/FileUsage/DatabaseFileUsageBackend.php
+++ b/core/modules/file/lib/Drupal/file/FileUsage/DatabaseFileUsageBackend.php
@@ -51,7 +51,7 @@ class DatabaseFileUsageBackend extends FileUsageBase {
public function add(File $file, $module, $type, $id, $count = 1) {
$this->connection->merge($this->tableName)
->key(array(
- 'fid' => $file->fid,
+ 'fid' => $file->id(),
'module' => $module,
'type' => $type,
'id' => $id,
@@ -70,7 +70,7 @@ class DatabaseFileUsageBackend extends FileUsageBase {
// Delete rows that have a exact or less value to prevent empty rows.
$query = $this->connection->delete($this->tableName)
->condition('module', $module)
- ->condition('fid', $file->fid);
+ ->condition('fid', $file->id());
if ($type && $id) {
$query
->condition('type', $type)
@@ -85,7 +85,7 @@ class DatabaseFileUsageBackend extends FileUsageBase {
if (!$result && $count > 0) {
$query = $this->connection->update($this->tableName)
->condition('module', $module)
- ->condition('fid', $file->fid);
+ ->condition('fid', $file->id());
if ($type && $id) {
$query
->condition('type', $type)
@@ -104,7 +104,7 @@ class DatabaseFileUsageBackend extends FileUsageBase {
public function listUsage(File $file) {
$result = $this->connection->select($this->tableName, 'f')
->fields('f', array('module', 'type', 'id', 'count'))
- ->condition('fid', $file->fid)
+ ->condition('fid', $file->id())
->condition('count', 0, '>')
->execute();
$references = array();
diff --git a/core/modules/file/lib/Drupal/file/FileUsage/FileUsageBase.php b/core/modules/file/lib/Drupal/file/FileUsage/FileUsageBase.php
index 9ba2ac7..1abe20d 100644
--- a/core/modules/file/lib/Drupal/file/FileUsage/FileUsageBase.php
+++ b/core/modules/file/lib/Drupal/file/FileUsage/FileUsageBase.php
@@ -19,8 +19,8 @@ abstract class FileUsageBase implements FileUsageInterface {
*/
public function add(File $file, $module, $type, $id, $count = 1) {
// Make sure that a used file is permament.
- if ($file->status != FILE_STATUS_PERMANENT) {
- $file->status = FILE_STATUS_PERMANENT;
+ if (!$file->isPermanent()) {
+ $file->setPermanent();
$file->save();
}
}
@@ -33,7 +33,7 @@ abstract class FileUsageBase implements FileUsageInterface {
// which result in a delete through system_cron().
$usage = file_usage()->listUsage($file);
if (empty($usage)) {
- $file->status = 0;
+ $file->setTemporary();
$file->save();
}
}
diff --git a/core/modules/file/lib/Drupal/file/Plugin/Core/Entity/File.php b/core/modules/file/lib/Drupal/file/Plugin/Core/Entity/File.php
index 1390cc7..457e824 100644
--- a/core/modules/file/lib/Drupal/file/Plugin/Core/Entity/File.php
+++ b/core/modules/file/lib/Drupal/file/Plugin/Core/Entity/File.php
@@ -7,11 +7,12 @@
namespace Drupal\file\Plugin\Core\Entity;
-use Drupal\Core\Entity\Entity;
+use Drupal\Core\Entity\EntityNG;
use Drupal\Core\Entity\Annotation\EntityType;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Language\Language;
use Drupal\file\FileInterface;
+use Drupal\user\UserInterface;
/**
* Defines the file entity class.
@@ -32,90 +33,129 @@ use Drupal\file\FileInterface;
* }
* )
*/
-class File extends Entity implements FileInterface {
+class File extends EntityNG implements FileInterface {
/**
- * The file ID.
+ * The plain data values of the contained properties.
*
- * @var integer
+ * Define default values.
+ *
+ * @var array
*/
- public $fid;
+ protected $values = array(
+ 'langcode' => array(Language::LANGCODE_DEFAULT => array(0 => array('value' => Language::LANGCODE_NOT_SPECIFIED))),
+ );
/**
- * The file UUID.
- *
- * @var string
+ * {@inheritdoc}
*/
- public $uuid;
+ public function id() {
+ return $this->get('fid')->value;
+ }
/**
- * The file language code.
- *
- * @var string
+ * {@inheritdoc}
*/
- public $langcode = Language::LANGCODE_NOT_SPECIFIED;
+ public function getFilename() {
+ return $this->get('filename')->value;
+ }
/**
- * The uid of the user who is associated with the file.
- *
- * @var integer
+ * {@inheritdoc}
*/
- public $uid;
+ public function setFilename($filename) {
+ $this->get('filename')->value = $filename;
+ }
/**
- * Name of the file with no path components.
- *
- * This may differ from the basename of the URI if the file is renamed to
- * avoid overwriting an existing file.
- *
- * @var string
+ * {@inheritdoc}
*/
- public $filename;
+ public function getFileUri() {
+ return $this->get('uri')->value;
+ }
/**
- * The URI to access the file (either local or remote).
- *
- * @var string
+ * {@inheritdoc}
*/
- public $uri;
+ public function setFileUri($uri) {
+ $this->get('uri')->value = $uri;
+ }
/**
- * The file's MIME type.
- *
- * @var string
+ * {@inheritdoc}
*/
- public $filemime;
+ public function getMimeType() {
+ return $this->get('filemime')->value;
+ }
/**
- * The size of the file in bytes.
- *
- * @var integer
+ * {@inheritdoc}
*/
- public $filesize;
+ public function setMimeType($mime) {
+ $this->get('filemime')->value = $mime;
+ }
/**
- * A field indicating the status of the file.
- *
- * Two status are defined in core: temporary (0) and permanent (1).
- * Temporary files older than DRUPAL_MAXIMUM_TEMP_FILE_AGE will be removed
- * during a cron run.
- *
- * @var integer
+ * {@inheritdoc}
*/
- public $status;
+ public function getSize() {
+ return $this->get('filesize')->value;
+ }
/**
- * UNIX timestamp for when the file was last saved.
- *
- * @var integer
+ * {@inheritdoc}
*/
- public $timestamp;
+ public function setSize($size) {
+ $this->get('filesize')->value = $size;
+ }
/**
- * Overrides Drupal\Core\Entity\Entity::id().
+ * {@inheritdoc}
*/
- public function id() {
- return $this->fid;
+ public function getChangedTime() {
+ return $this->get('timestamp')->value;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getOwner() {
+ return $this->get('uid')->entity->getBCEntity();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setOwner(UserInterface $user) {
+ return $this->get('uid')->entity = $user;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function isPermanent() {
+ return $this->get('status')->value == FILE_STATUS_PERMANENT;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function isTemporary() {
+ return $this->get('status')->value == 0;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setPermanent() {
+ $this->get('status')->value = FILE_STATUS_PERMANENT;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setTemporary() {
+ $this->get('status')->value = 0;
}
}
diff --git a/core/modules/file/lib/Drupal/file/Plugin/field/formatter/GenericFileFormatter.php b/core/modules/file/lib/Drupal/file/Plugin/field/formatter/GenericFileFormatter.php
index 02d003e..3cb0eda 100644
--- a/core/modules/file/lib/Drupal/file/Plugin/field/formatter/GenericFileFormatter.php
+++ b/core/modules/file/lib/Drupal/file/Plugin/field/formatter/GenericFileFormatter.php
@@ -35,7 +35,7 @@ class GenericFileFormatter extends FormatterBase {
foreach ($items as $delta => $item) {
$elements[$delta] = array(
'#theme' => 'file_link',
- '#file' => file_load($item['fid']),
+ '#file' => $item['entity'],
'#description' => $item['description'],
);
}
diff --git a/core/modules/file/lib/Drupal/file/Plugin/field/formatter/RSSEnclosureFormatter.php b/core/modules/file/lib/Drupal/file/Plugin/field/formatter/RSSEnclosureFormatter.php
index 424df01..d90da6b 100644
--- a/core/modules/file/lib/Drupal/file/Plugin/field/formatter/RSSEnclosureFormatter.php
+++ b/core/modules/file/lib/Drupal/file/Plugin/field/formatter/RSSEnclosureFormatter.php
@@ -35,12 +35,13 @@ class RSSEnclosureFormatter extends FormatterBase {
// enclosure per item. See: http://en.wikipedia.org/wiki/RSS_enclosure
foreach ($items as $item) {
if ($item['display']) {
+ $file = $item['entity'];
$entity->rss_elements[] = array(
'key' => 'enclosure',
'attributes' => array(
- 'url' => file_create_url($item['uri']),
- 'length' => $item['filesize'],
- 'type' => $item['filemime'],
+ 'url' => file_create_url($file->getFileUri()),
+ 'length' => $file->getSize(),
+ 'type' => $file->getMimeType(),
),
);
break;
diff --git a/core/modules/file/lib/Drupal/file/Plugin/field/formatter/UrlPlainFormatter.php b/core/modules/file/lib/Drupal/file/Plugin/field/formatter/UrlPlainFormatter.php
index 7edf940..bd20583 100644
--- a/core/modules/file/lib/Drupal/file/Plugin/field/formatter/UrlPlainFormatter.php
+++ b/core/modules/file/lib/Drupal/file/Plugin/field/formatter/UrlPlainFormatter.php
@@ -33,7 +33,7 @@ class UrlPlainFormatter extends FormatterBase {
$elements = array();
foreach ($items as $delta => $item) {
- $elements[$delta] = array('#markup' => empty($item['uri']) ? '' : file_create_url($item['uri']));
+ $elements[$delta] = array('#markup' => empty($item['entity']) ? '' : file_create_url($item['entity']->getFileUri()));
}
return $elements;
diff --git a/core/modules/file/lib/Drupal/file/Tests/CopyTest.php b/core/modules/file/lib/Drupal/file/Tests/CopyTest.php
index 7f20c9f..6aaa2ca 100644
--- a/core/modules/file/lib/Drupal/file/Tests/CopyTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/CopyTest.php
@@ -33,19 +33,19 @@ class CopyTest extends FileManagedTestBase {
// Check the return status and that the contents changed.
$this->assertTrue($result, t('File copied successfully.'));
- $this->assertEqual($contents, file_get_contents($result->uri), t('Contents of file were copied correctly.'));
+ $this->assertEqual($contents, file_get_contents($result->getFileUri()), t('Contents of file were copied correctly.'));
// Check that the correct hooks were called.
$this->assertFileHooksCalled(array('copy', 'insert'));
$this->assertDifferentFile($source, $result);
- $this->assertEqual($result->uri, $desired_uri, t('The copied file entity has the desired filepath.'));
- $this->assertTrue(file_exists($source->uri), t('The original file still exists.'));
- $this->assertTrue(file_exists($result->uri), t('The copied file exists.'));
+ $this->assertEqual($result->getFileUri(), $desired_uri, t('The copied file entity has the desired filepath.'));
+ $this->assertTrue(file_exists($source->getFileUri()), t('The original file still exists.'));
+ $this->assertTrue(file_exists($result->getFileUri()), t('The copied file exists.'));
// Reload the file from the database and check that the changes were
// actually saved.
- $this->assertFileUnchanged($result, file_load($result->fid, TRUE));
+ $this->assertFileUnchanged($result, file_load($result->id(), TRUE));
}
/**
@@ -60,21 +60,21 @@ class CopyTest extends FileManagedTestBase {
// Clone the object so we don't have to worry about the function changing
// our reference copy.
- $result = file_copy(clone $source, $target->uri, FILE_EXISTS_RENAME);
+ $result = file_copy(clone $source, $target->getFileUri(), FILE_EXISTS_RENAME);
// Check the return status and that the contents changed.
$this->assertTrue($result, t('File copied successfully.'));
- $this->assertEqual($contents, file_get_contents($result->uri), t('Contents of file were copied correctly.'));
- $this->assertNotEqual($result->uri, $source->uri, t('Returned file path has changed from the original.'));
+ $this->assertEqual($contents, file_get_contents($result->getFileUri()), t('Contents of file were copied correctly.'));
+ $this->assertNotEqual($result->getFileUri(), $source->getFileUri(), t('Returned file path has changed from the original.'));
// Check that the correct hooks were called.
$this->assertFileHooksCalled(array('copy', 'insert'));
// Load all the affected files to check the changes that actually made it
// to the database.
- $loaded_source = file_load($source->fid, TRUE);
- $loaded_target = file_load($target->fid, TRUE);
- $loaded_result = file_load($result->fid, TRUE);
+ $loaded_source = file_load($source->id(), TRUE);
+ $loaded_target = file_load($target->id(), TRUE);
+ $loaded_result = file_load($result->id(), TRUE);
// Verify that the source file wasn't changed.
$this->assertFileUnchanged($source, $loaded_source);
@@ -100,11 +100,11 @@ class CopyTest extends FileManagedTestBase {
// Clone the object so we don't have to worry about the function changing
// our reference copy.
- $result = file_copy(clone $source, $target->uri, FILE_EXISTS_REPLACE);
+ $result = file_copy(clone $source, $target->getFileUri(), FILE_EXISTS_REPLACE);
// Check the return status and that the contents changed.
$this->assertTrue($result, t('File copied successfully.'));
- $this->assertEqual($contents, file_get_contents($result->uri), t('Contents of file were overwritten.'));
+ $this->assertEqual($contents, file_get_contents($result->getFileUri()), t('Contents of file were overwritten.'));
$this->assertDifferentFile($source, $result);
// Check that the correct hooks were called.
@@ -112,9 +112,9 @@ class CopyTest extends FileManagedTestBase {
// Load all the affected files to check the changes that actually made it
// to the database.
- $loaded_source = file_load($source->fid, TRUE);
- $loaded_target = file_load($target->fid, TRUE);
- $loaded_result = file_load($result->fid, TRUE);
+ $loaded_source = file_load($source->id(), TRUE);
+ $loaded_target = file_load($target->id(), TRUE);
+ $loaded_result = file_load($result->id(), TRUE);
// Verify that the source file wasn't changed.
$this->assertFileUnchanged($source, $loaded_source);
@@ -138,16 +138,16 @@ class CopyTest extends FileManagedTestBase {
// Clone the object so we don't have to worry about the function changing
// our reference copy.
- $result = file_copy(clone $source, $target->uri, FILE_EXISTS_ERROR);
+ $result = file_copy(clone $source, $target->getFileUri(), FILE_EXISTS_ERROR);
// Check the return status and that the contents were not changed.
$this->assertFalse($result, t('File copy failed.'));
- $this->assertEqual($contents, file_get_contents($target->uri), t('Contents of file were not altered.'));
+ $this->assertEqual($contents, file_get_contents($target->getFileUri()), t('Contents of file were not altered.'));
// Check that the correct hooks were called.
$this->assertFileHooksCalled(array());
- $this->assertFileUnchanged($source, file_load($source->fid, TRUE));
- $this->assertFileUnchanged($target, file_load($target->fid, TRUE));
+ $this->assertFileUnchanged($source, file_load($source->id(), TRUE));
+ $this->assertFileUnchanged($target, file_load($target->id(), TRUE));
}
}
diff --git a/core/modules/file/lib/Drupal/file/Tests/DeleteTest.php b/core/modules/file/lib/Drupal/file/Tests/DeleteTest.php
index ca2f712..3270f8c 100644
--- a/core/modules/file/lib/Drupal/file/Tests/DeleteTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/DeleteTest.php
@@ -26,11 +26,11 @@ class DeleteTest extends FileManagedTestBase {
$file = $this->createFile();
// Check that deletion removes the file and database record.
- $this->assertTrue(is_file($file->uri), t('File exists.'));
+ $this->assertTrue(is_file($file->getFileUri()), t('File exists.'));
$file->delete();
$this->assertFileHooksCalled(array('delete'));
- $this->assertFalse(file_exists($file->uri), t('Test file has actually been deleted.'));
- $this->assertFalse(file_load($file->fid), t('File was removed from the database.'));
+ $this->assertFalse(file_exists($file->getFileUri()), t('Test file has actually been deleted.'));
+ $this->assertFalse(file_load($file->id()), t('File was removed from the database.'));
}
/**
@@ -44,8 +44,8 @@ class DeleteTest extends FileManagedTestBase {
file_usage()->delete($file, 'testing', 'test', 1);
$usage = file_usage()->listUsage($file);
$this->assertEqual($usage['testing']['test'], array(1 => 1), t('Test file is still in use.'));
- $this->assertTrue(file_exists($file->uri), t('File still exists on the disk.'));
- $this->assertTrue(file_load($file->fid), t('File still exists in the database.'));
+ $this->assertTrue(file_exists($file->getFileUri()), t('File still exists on the disk.'));
+ $this->assertTrue(file_load($file->id()), t('File still exists in the database.'));
// Clear out the call to hook_file_load().
file_test_reset();
@@ -54,10 +54,10 @@ class DeleteTest extends FileManagedTestBase {
$usage = file_usage()->listUsage($file);
$this->assertFileHooksCalled(array('load', 'update'));
$this->assertTrue(empty($usage), t('File usage data was removed.'));
- $this->assertTrue(file_exists($file->uri), 'File still exists on the disk.');
- $file = file_load($file->fid);
+ $this->assertTrue(file_exists($file->getFileUri()), 'File still exists on the disk.');
+ $file = file_load($file->id());
$this->assertTrue($file, 'File still exists in the database.');
- $this->assertEqual($file->status, 0, 'File is temporary.');
+ $this->assertTrue($file->isTemporary(), 'File is temporary.');
file_test_reset();
// Call system_cron() to clean up the file. Make sure the timestamp
@@ -66,13 +66,13 @@ class DeleteTest extends FileManagedTestBase {
->fields(array(
'timestamp' => REQUEST_TIME - (DRUPAL_MAXIMUM_TEMP_FILE_AGE + 1),
))
- ->condition('fid', $file->fid)
+ ->condition('fid', $file->id())
->execute();
drupal_cron_run();
// system_cron() loads
$this->assertFileHooksCalled(array('delete'));
- $this->assertFalse(file_exists($file->uri), t('File has been deleted after its last usage was removed.'));
- $this->assertFalse(file_load($file->fid), t('File was removed from the database.'));
+ $this->assertFalse(file_exists($file->getFileUri()), t('File has been deleted after its last usage was removed.'));
+ $this->assertFalse(file_load($file->id()), t('File was removed from the database.'));
}
}
diff --git a/core/modules/file/lib/Drupal/file/Tests/DownloadTest.php b/core/modules/file/lib/Drupal/file/Tests/DownloadTest.php
index 2c1278f..41cad99 100644
--- a/core/modules/file/lib/Drupal/file/Tests/DownloadTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/DownloadTest.php
@@ -33,10 +33,10 @@ class DownloadTest extends FileManagedTestBase {
function testPublicFileTransfer() {
// Test generating an URL to a created file.
$file = $this->createFile();
- $url = file_create_url($file->uri);
+ $url = file_create_url($file->getFileUri());
// URLs can't contain characters outside the ASCII set so $filename has to be
// encoded.
- $filename = $GLOBALS['base_url'] . '/' . file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath() . '/' . rawurlencode($file->filename);
+ $filename = $GLOBALS['base_url'] . '/' . file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath() . '/' . rawurlencode($file->getFilename());
$this->assertEqual($filename, $url, t('Correctly generated a URL for a created file.'));
$this->drupalHead($url);
$this->assertResponse(200, t('Confirmed that the generated URL is correct by downloading the created file.'));
@@ -59,7 +59,7 @@ class DownloadTest extends FileManagedTestBase {
// Create a file.
$contents = $this->randomName(8);
$file = $this->createFile(NULL, $contents, 'private');
- $url = file_create_url($file->uri);
+ $url = file_create_url($file->getFileUri());
// Set file_test access header to allow the download.
file_test_set_return('download', array('x-foo' => 'Bar'));
@@ -140,7 +140,7 @@ class DownloadTest extends FileManagedTestBase {
file_prepare_directory($directory_uri, FILE_CREATE_DIRECTORY);
$file = $this->createFile($filepath, NULL, $scheme);
- $url = file_create_url($file->uri);
+ $url = file_create_url($file->getFileUri());
$this->assertEqual($url, $expected_url, t('Generated URL matches expected URL.'));
if ($scheme == 'private') {
@@ -151,7 +151,7 @@ class DownloadTest extends FileManagedTestBase {
$this->drupalGet($url);
if ($this->assertResponse(200) == 'pass') {
- $this->assertRaw(file_get_contents($file->uri), t('Contents of the file are correct.'));
+ $this->assertRaw(file_get_contents($file->getFileUri()), t('Contents of the file are correct.'));
}
$file->delete();
diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php
index 8fcd58f..efe7aa0 100644
--- a/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php
@@ -36,7 +36,7 @@ class FileFieldPathTest extends FileFieldTestBase {
// 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']);
- $this->assertPathMatch('public://' . $test_file->filename, $node_file->uri, t('The file %file was uploaded to the correct path.', array('%file' => $node_file->uri)));
+ $this->assertPathMatch('public://' . $test_file->getFilename(), $node_file->getFileUri(), t('The file %file was uploaded to the correct path.', array('%file' => $node_file->getFileUri())));
// Change the path to contain multiple subdirectories.
$this->updateFileField($field_name, $type_name, array('file_directory' => 'foo/bar/baz'));
@@ -46,8 +46,8 @@ class FileFieldPathTest extends FileFieldTestBase {
// 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']);
- $this->assertPathMatch('public://foo/bar/baz/' . $test_file->filename, $node_file->uri, t('The file %file was uploaded to the correct path.', array('%file' => $node_file->uri)));
+ $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'], TRUE);
+ $this->assertPathMatch('public://foo/bar/baz/' . $test_file->getFilename(), $node_file->getFileUri(), t('The file %file was uploaded to the correct path.', array('%file' => $node_file->getFileUri())));
// Check the path when used with tokens.
// Change the path to contain multiple token directories.
@@ -63,7 +63,7 @@ class FileFieldPathTest extends FileFieldTestBase {
// the user running the test case.
$data = array('user' => $this->admin_user);
$subdirectory = \Drupal::token()->replace('[user:uid]/[user:name]', $data);
- $this->assertPathMatch('public://' . $subdirectory . '/' . $test_file->filename, $node_file->uri, t('The file %file was uploaded to the correct path with token replacements.', array('%file' => $node_file->uri)));
+ $this->assertPathMatch('public://' . $subdirectory . '/' . $test_file->getFilename(), $node_file->getFileUri(), t('The file %file was uploaded to the correct path with token replacements.', array('%file' => $node_file->getFileUri())));
}
/**
diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php
index 17c414b..a3b86ea 100644
--- a/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php
@@ -71,14 +71,14 @@ class FileFieldRSSContentTest extends FileFieldTestBase {
// Check that the RSS enclosure appears in the RSS feed.
$this->drupalGet('rss.xml');
- $uploaded_filename = str_replace('public://', '', $node_file->uri);
+ $uploaded_filename = str_replace('public://', '', $node_file->getFileUri());
$test_element = array(
'key' => 'enclosure',
'value' => "",
'attributes' => array(
'url' => url("$this->public_files_directory/$uploaded_filename", array('absolute' => TRUE)),
- 'length' => $node_file->filesize,
- 'type' => $node_file->filemime
+ 'length' => $node_file->getSize(),
+ 'type' => $node_file->getMimeType()
),
);
$this->assertRaw(format_xml_elements(array($test_element)), 'File field RSS enclosure is displayed when viewing the RSS feed.');
diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php
index f5c41ef..2d8cc3a 100644
--- a/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php
@@ -64,7 +64,8 @@ class FileFieldRevisionTest extends FileFieldTestBase {
// Check that the original file is still in place on the first revision.
$node = node_revision_load($node_vid_r1);
- $this->assertEqual($node_file_r1, file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']), t('Original file still in place after replacing file in new revision.'));
+ $current_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']);
+ $this->assertEqual($node_file_r1->id(), $current_file->id(), t('Original file still in place after replacing file in new revision.'));
$this->assertFileExists($node_file_r1, t('Original file still in place after replacing file in new revision.'));
$this->assertFileEntryExists($node_file_r1, t('Original file entry still in place after replacing file in new revision'));
$this->assertFileIsPermanent($node_file_r1, t('Original file is still permanent.'));
@@ -75,7 +76,7 @@ class FileFieldRevisionTest extends FileFieldTestBase {
$node = node_load($nid, TRUE);
$node_file_r3 = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']);
$node_vid_r3 = $node->vid;
- $this->assertEqual($node_file_r2, $node_file_r3, t('Previous revision file still in place after creating a new revision without a new file.'));
+ $this->assertEqual($node_file_r2->id(), $node_file_r3->id(), t('Previous revision file still in place after creating a new revision without a new file.'));
$this->assertFileIsPermanent($node_file_r3, t('New revision file is permanent.'));
// Revert to the first revision and check that the original file is active.
@@ -83,7 +84,7 @@ class FileFieldRevisionTest extends FileFieldTestBase {
$node = node_load($nid, TRUE);
$node_file_r4 = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']);
$node_vid_r4 = $node->vid;
- $this->assertEqual($node_file_r1, $node_file_r4, t('Original revision file still in place after reverting to the original revision.'));
+ $this->assertEqual($node_file_r1->id(), $node_file_r4->id(), t('Original revision file still in place after reverting to the original revision.'));
$this->assertFileIsPermanent($node_file_r4, t('Original revision file still permanent after reverting to the original revision.'));
// Delete the second revision and check that the file is kept (since it is
@@ -95,7 +96,7 @@ class FileFieldRevisionTest extends FileFieldTestBase {
// Attach the second file to a user.
$user = $this->drupalCreateUser();
- $user->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'] = $node_file_r3->fid;
+ $user->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'] = $node_file_r3->id();
$user->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['display'] = 1;
$user->save();
$this->drupalGet('user/' . $user->uid . '/edit');
@@ -111,10 +112,10 @@ class FileFieldRevisionTest extends FileFieldTestBase {
// TODO: This seems like a bug in File API. Clearing the stat cache should
// not be necessary here. The file really is deleted, but stream wrappers
// doesn't seem to think so unless we clear the PHP file stat() cache.
- clearstatcache($node_file_r1->uri);
- clearstatcache($node_file_r2->uri);
- clearstatcache($node_file_r3->uri);
- clearstatcache($node_file_r4->uri);
+ clearstatcache($node_file_r1->getFileUri());
+ clearstatcache($node_file_r2->getFileUri());
+ clearstatcache($node_file_r3->getFileUri());
+ clearstatcache($node_file_r4->getFileUri());
// Call system_cron() to clean up the file. Make sure the timestamp
// of the file is older than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
@@ -122,7 +123,7 @@ class FileFieldRevisionTest extends FileFieldTestBase {
->fields(array(
'timestamp' => REQUEST_TIME - (DRUPAL_MAXIMUM_TEMP_FILE_AGE + 1),
))
- ->condition('fid', $node_file_r3->fid)
+ ->condition('fid', $node_file_r3->id())
->execute();
drupal_cron_run();
@@ -137,7 +138,7 @@ class FileFieldRevisionTest extends FileFieldTestBase {
->fields(array(
'timestamp' => REQUEST_TIME - (DRUPAL_MAXIMUM_TEMP_FILE_AGE + 1),
))
- ->condition('fid', $node_file_r1->fid)
+ ->condition('fid', $node_file_r1->id())
->execute();
drupal_cron_run();
$this->assertFileNotExists($node_file_r1, t('Original file is deleted after deleting the entire node with two revisions remaining.'));
diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php
index a26e464..d82c3f0 100644
--- a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php
+++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php
@@ -8,6 +8,7 @@
namespace Drupal\file\Tests;
use Drupal\Core\Language\Language;
+use Drupal\file\FileInterface;
use Drupal\simpletest\WebTestBase;
/**
@@ -162,7 +163,7 @@ abstract class FileFieldTestBase extends WebTestBase {
if ($field['cardinality'] != 1) {
$name .= '[]';
}
- $edit[$name] = drupal_realpath($file->uri);
+ $edit[$name] = drupal_realpath($file->getFileUri());
$this->drupalPost("node/$nid/edit", $edit, t('Save and keep published'));
return $nid;
@@ -187,7 +188,7 @@ abstract class FileFieldTestBase extends WebTestBase {
*/
function replaceNodeFile($file, $field_name, $nid, $new_revision = TRUE) {
$edit = array(
- 'files[' . $field_name . '_' . Language::LANGCODE_NOT_SPECIFIED . '_0]' => drupal_realpath($file->uri),
+ 'files[' . $field_name . '_' . Language::LANGCODE_NOT_SPECIFIED . '_0]' => drupal_realpath($file->getFileUri()),
'revision' => (string) (int) $new_revision,
);
@@ -199,8 +200,8 @@ abstract class FileFieldTestBase extends WebTestBase {
* Asserts that a file exists physically on disk.
*/
function assertFileExists($file, $message = NULL) {
- $message = isset($message) ? $message : t('File %file exists on the disk.', array('%file' => $file->uri));
- $this->assertTrue(is_file($file->uri), $message);
+ $message = isset($message) ? $message : t('File %file exists on the disk.', array('%file' => $file->getFileUri()));
+ $this->assertTrue(is_file($file->getFileUri()), $message);
}
/**
@@ -208,17 +209,17 @@ abstract class FileFieldTestBase extends WebTestBase {
*/
function assertFileEntryExists($file, $message = NULL) {
$this->container->get('plugin.manager.entity')->getStorageController('file')->resetCache();
- $db_file = file_load($file->fid);
- $message = isset($message) ? $message : t('File %file exists in database at the correct path.', array('%file' => $file->uri));
- $this->assertEqual($db_file->uri, $file->uri, $message);
+ $db_file = file_load($file->id());
+ $message = isset($message) ? $message : t('File %file exists in database at the correct path.', array('%file' => $file->getFileUri()));
+ $this->assertEqual($db_file->getFileUri(), $file->getFileUri(), $message);
}
/**
* Asserts that a file does not exist on disk.
*/
function assertFileNotExists($file, $message = NULL) {
- $message = isset($message) ? $message : t('File %file exists on the disk.', array('%file' => $file->uri));
- $this->assertFalse(is_file($file->uri), $message);
+ $message = isset($message) ? $message : t('File %file exists on the disk.', array('%file' => $file->getFileUri()));
+ $this->assertFalse(is_file($file->getFileUri()), $message);
}
/**
@@ -226,15 +227,15 @@ abstract class FileFieldTestBase extends WebTestBase {
*/
function assertFileEntryNotExists($file, $message) {
$this->container->get('plugin.manager.entity')->getStorageController('file')->resetCache();
- $message = isset($message) ? $message : t('File %file exists in database at the correct path.', array('%file' => $file->uri));
- $this->assertFalse(file_load($file->fid), $message);
+ $message = isset($message) ? $message : t('File %file exists in database at the correct path.', array('%file' => $file->getFileUri()));
+ $this->assertFalse(file_load($file->id()), $message);
}
/**
* Asserts that a file's status is set to permanent in the database.
*/
- function assertFileIsPermanent($file, $message = NULL) {
- $message = isset($message) ? $message : t('File %file is permanent.', array('%file' => $file->uri));
- $this->assertTrue($file->status == FILE_STATUS_PERMANENT, $message);
+ function assertFileIsPermanent(FileInterface $file, $message = NULL) {
+ $message = isset($message) ? $message : t('File %file is permanent.', array('%file' => $file->getFileUri()));
+ $this->assertTrue($file->isPermanent(), $message);
}
}
diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php
index 403ef45..93bf379 100644
--- a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php
@@ -43,7 +43,7 @@ class FileFieldValidateTest extends FileFieldTestBase {
// Create a new node with the uploaded file.
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
- $this->assertTrue($nid !== FALSE, t('uploadNodeFile(@test_file, @field_name, @type_name) succeeded', array('@test_file' => $test_file->uri, '@field_name' => $field_name, '@type_name' => $type_name)));
+ $this->assertTrue($nid !== FALSE, t('uploadNodeFile(@test_file, @field_name, @type_name) succeeded', array('@test_file' => $test_file->getFileUri(), '@field_name' => $field_name, '@type_name' => $type_name)));
$node = node_load($nid, TRUE);
@@ -94,13 +94,13 @@ class FileFieldValidateTest extends FileFieldTestBase {
$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']);
- $this->assertFileExists($node_file, t('File exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->filesize), '%maxsize' => $max_filesize)));
- $this->assertFileEntryExists($node_file, t('File entry exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->filesize), '%maxsize' => $max_filesize)));
+ $this->assertFileExists($node_file, t('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, t('File entry exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->getSize()), '%maxsize' => $max_filesize)));
// Check that uploading the large file fails (1M limit).
$nid = $this->uploadNodeFile($large_file, $field_name, $type_name);
- $error_message = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size($large_file->filesize), '%maxsize' => format_size($file_limit)));
- $this->assertRaw($error_message, t('Node save failed when file (%filesize) exceeded the max upload size (%maxsize).', array('%filesize' => format_size($large_file->filesize), '%maxsize' => $max_filesize)));
+ $error_message = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size($large_file->getSize()), '%maxsize' => format_size($file_limit)));
+ $this->assertRaw($error_message, t('Node save failed when file (%filesize) exceeded the max upload size (%maxsize).', array('%filesize' => format_size($large_file->getSize()), '%maxsize' => $max_filesize)));
}
// Turn off the max filesize.
@@ -110,8 +110,8 @@ class FileFieldValidateTest extends FileFieldTestBase {
$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']);
- $this->assertFileExists($node_file, t('File exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->filesize))));
- $this->assertFileEntryExists($node_file, t('File entry exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->filesize))));
+ $this->assertFileExists($node_file, t('File exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->getSize()))));
+ $this->assertFileEntryExists($node_file, t('File entry exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->getSize()))));
}
/**
@@ -123,7 +123,7 @@ class FileFieldValidateTest extends FileFieldTestBase {
$this->createFileField($field_name, $type_name);
$test_file = $this->getTestFile('image');
- list(, $test_file_extension) = explode('.', $test_file->filename);
+ list(, $test_file_extension) = explode('.', $test_file->getFilename());
// Disable extension checking.
$this->updateFileField($field_name, $type_name, array('file_extensions' => ''));
diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php
index 0b652c7..702c8a2 100644
--- a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php
@@ -50,7 +50,7 @@ class FileFieldWidgetTest extends FileFieldTestBase {
$this->assertFileExists($node_file, t('New file saved to disk on node creation.'));
// Ensure the file can be downloaded.
- $this->drupalGet(file_create_url($node_file->uri));
+ $this->drupalGet(file_create_url($node_file->getFileUri()));
$this->assertResponse(200, t('Confirmed that the generated URL is correct by downloading the shipped file.'));
// Ensure the edit page has a remove button instead of an upload button.
@@ -113,7 +113,7 @@ class FileFieldWidgetTest extends FileFieldTestBase {
$this->drupalGet("node/add/$type_name");
foreach (array($field_name2, $field_name) as $each_field_name) {
for ($delta = 0; $delta < 3; $delta++) {
- $edit = array('files[' . $each_field_name . '_' . Language::LANGCODE_NOT_SPECIFIED . '_' . $delta . '][]' => drupal_realpath($test_file->uri));
+ $edit = array('files[' . $each_field_name . '_' . Language::LANGCODE_NOT_SPECIFIED . '_' . $delta . '][]' => drupal_realpath($test_file->getFileUri()));
// If the Upload button doesn't exist, drupalPost() will automatically
// fail with an assertion message.
$this->drupalPost(NULL, $edit, t('Upload'));
@@ -220,7 +220,7 @@ class FileFieldWidgetTest extends FileFieldTestBase {
$this->assertFileExists($node_file, t('New file saved to disk on node creation.'));
// Ensure the private file is available to the user who uploaded it.
- $this->drupalGet(file_create_url($node_file->uri));
+ $this->drupalGet(file_create_url($node_file->getFileUri()));
$this->assertResponse(200, t('Confirmed that the generated URL is correct by downloading the shipped file.'));
// Ensure we can't change 'uri_scheme' field settings while there are some
@@ -274,7 +274,7 @@ class FileFieldWidgetTest extends FileFieldTestBase {
// Add a comment with a file.
$text_file = $this->getTestFile('text');
$edit = array(
- 'files[field_' . $name . '_' . Language::LANGCODE_NOT_SPECIFIED . '_' . 0 . ']' => drupal_realpath($text_file->uri),
+ 'files[field_' . $name . '_' . Language::LANGCODE_NOT_SPECIFIED . '_' . 0 . ']' => drupal_realpath($text_file->getFileUri()),
'comment_body[' . Language::LANGCODE_NOT_SPECIFIED . '][0][value]' => $comment_body = $this->randomName(),
);
$this->drupalPost(NULL, $edit, t('Save'));
@@ -290,14 +290,14 @@ class FileFieldWidgetTest extends FileFieldTestBase {
$comment_file = $comment->{'field_' . $name}->entity;
$this->assertFileExists($comment_file, t('New file saved to disk on node creation.'));
// Test authenticated file download.
- $url = file_create_url($comment_file->uri);
+ $url = file_create_url($comment_file->getFileUri());
$this->assertNotEqual($url, NULL, t('Confirmed that the URL is valid'));
- $this->drupalGet(file_create_url($comment_file->uri));
+ $this->drupalGet(file_create_url($comment_file->getFileUri()));
$this->assertResponse(200, t('Confirmed that the generated URL is correct by downloading the shipped file.'));
// Test anonymous file download.
$this->drupalLogout();
- $this->drupalGet(file_create_url($comment_file->uri));
+ $this->drupalGet(file_create_url($comment_file->getFileUri()));
$this->assertResponse(403, t('Confirmed that access is denied for the file without the needed permission.'));
// Unpublishes node.
@@ -306,7 +306,7 @@ class FileFieldWidgetTest extends FileFieldTestBase {
// Ensures normal user can no longer download the file.
$this->drupalLogin($user);
- $this->drupalGet(file_create_url($comment_file->uri));
+ $this->drupalGet(file_create_url($comment_file->getFileUri()));
$this->assertResponse(403, t('Confirmed that access is denied for the file without the needed permission.'));
}
@@ -330,7 +330,7 @@ class FileFieldWidgetTest extends FileFieldTestBase {
$name = 'files[' . $field_name . '_' . Language::LANGCODE_NOT_SPECIFIED . '_0]';
// Upload file with incorrect extension, check for validation error.
- $edit[$name] = drupal_realpath($test_file_image->uri);
+ $edit[$name] = drupal_realpath($test_file_image->getFileUri());
switch ($type) {
case 'nojs':
$this->drupalPost(NULL, $edit, t('Upload'));
@@ -344,7 +344,7 @@ class FileFieldWidgetTest extends FileFieldTestBase {
$this->assertRaw($error_message, t('Validation error when file with wrong extension uploaded (JSMode=%type).', array('%type' => $type)));
// Upload file with correct extension, check that error message is removed.
- $edit[$name] = drupal_realpath($test_file_text->uri);
+ $edit[$name] = drupal_realpath($test_file_text->getFileUri());
switch ($type) {
case 'nojs':
$this->drupalPost(NULL, $edit, t('Upload'));
diff --git a/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php b/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php
index 2ec9dfa..ee27703 100644
--- a/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php
@@ -81,7 +81,7 @@ class FileItemTest extends FieldUnitTestBase {
$this->assertEqual($entity->file_test->fid, $this->file->id());
$this->assertEqual($entity->file_test->display, 1);
$this->assertEqual($entity->file_test->description, $description);
- $this->assertEqual($entity->file_test->entity->uri, $this->file->uri);
+ $this->assertEqual($entity->file_test->entity->getFileUri(), $this->file->getFileUri());
$this->assertEqual($entity->file_test->entity->id(), $this->file->id());
$this->assertEqual($entity->file_test->entity->uuid(), $this->file->uuid());
@@ -94,7 +94,7 @@ class FileItemTest extends FieldUnitTestBase {
$entity->file_test->fid = $file2->id();
$this->assertEqual($entity->file_test->entity->id(), $file2->id());
- $this->assertEqual($entity->file_test->entity->uri, $file2->uri);
+ $this->assertEqual($entity->file_test->entity->getFileUri(), $file2->getFileUri());
}
}
diff --git a/core/modules/file/lib/Drupal/file/Tests/FileManagedFileElementTest.php b/core/modules/file/lib/Drupal/file/Tests/FileManagedFileElementTest.php
index 6e43fc1..6fb65e4 100644
--- a/core/modules/file/lib/Drupal/file/Tests/FileManagedFileElementTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/FileManagedFileElementTest.php
@@ -46,7 +46,7 @@ class FileManagedFileElementTest extends FileFieldTestBase {
// Submit a new file, without using the Upload button.
$last_fid_prior = $this->getLastFileId();
- $edit = array($file_field_name => drupal_realpath($test_file->uri));
+ $edit = array($file_field_name => drupal_realpath($test_file->getFileUri()));
$this->drupalPost($path, $edit, t('Save'));
$last_fid = $this->getLastFileId();
$this->assertTrue($last_fid > $last_fid_prior, t('New file got saved.'));
@@ -61,7 +61,7 @@ class FileManagedFileElementTest extends FileFieldTestBase {
// Upload, then Submit.
$last_fid_prior = $this->getLastFileId();
$this->drupalGet($path);
- $edit = array($file_field_name => drupal_realpath($test_file->uri));
+ $edit = array($file_field_name => drupal_realpath($test_file->getFileUri()));
if ($ajax) {
$this->drupalPostAJAX(NULL, $edit, $input_base_name . '_upload_button');
}
@@ -92,7 +92,7 @@ class FileManagedFileElementTest extends FileFieldTestBase {
// Upload, then Remove, then Submit.
$this->drupalGet($path);
- $edit = array($file_field_name => drupal_realpath($test_file->uri));
+ $edit = array($file_field_name => drupal_realpath($test_file->getFileUri()));
if ($ajax) {
$this->drupalPostAJAX(NULL, $edit, $input_base_name . '_upload_button');
}
@@ -120,7 +120,7 @@ class FileManagedFileElementTest extends FileFieldTestBase {
// The multiple file upload has additional conditions that need checking.
$path = 'file/test/1/1/1';
- $edit = array('files[nested_file][]' => drupal_realpath($test_file->uri));
+ $edit = array('files[nested_file][]' => drupal_realpath($test_file->getFileUri()));
$fid_list = array();
$this->drupalGet($path);
diff --git a/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php
index b449f8f..51cc239 100644
--- a/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php
+++ b/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php
@@ -100,8 +100,8 @@ abstract class FileManagedTestBase extends FileTestBase {
* @param $scheme
* Optional string indicating the stream scheme to use. Drupal core includes
* public, private, and temporary. The public wrapper is the default.
- * @return
- * File object.
+ * @return \Drupal\file\FileInterface
+ * File entity.
*/
function createFile($filepath = NULL, $contents = NULL, $scheme = NULL) {
$file = new stdClass();
diff --git a/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php b/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php
index 68f695b..b509b07 100644
--- a/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php
@@ -52,10 +52,10 @@ class FilePrivateTest extends FileFieldTestBase {
$node = node_load($nid, TRUE);
$node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']);
// Ensure the file can be downloaded.
- $this->drupalGet(file_create_url($node_file->uri));
+ $this->drupalGet(file_create_url($node_file->getFileUri()));
$this->assertResponse(200, t('Confirmed that the generated URL is correct by downloading the shipped file.'));
$this->drupalLogOut();
- $this->drupalGet(file_create_url($node_file->uri));
+ $this->drupalGet(file_create_url($node_file->getFileUri()));
$this->assertResponse(403, t('Confirmed that access is denied for the file without the needed permission.'));
// Test with the field that should deny access through field access.
@@ -64,7 +64,7 @@ class FilePrivateTest extends FileFieldTestBase {
$node = node_load($nid, TRUE);
$node_file = file_load($node->{$no_access_field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']);
// Ensure the file cannot be downloaded.
- $this->drupalGet(file_create_url($node_file->uri));
+ $this->drupalGet(file_create_url($node_file->getFileUri()));
$this->assertResponse(403, t('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 65b7570..b7d3e9f 100644
--- a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php
@@ -39,7 +39,7 @@ class FileTokenReplaceTest extends FileFieldTestBase {
$test_file = $this->getTestFile('text');
// Coping a file to test uploads with non-latin filenames.
- $filename = drupal_dirname($test_file->uri) . '/текстовый файл.txt';
+ $filename = drupal_dirname($test_file->getFileUri()) . '/текстовый файл.txt';
$test_file = file_copy($test_file, $filename);
// Create a new node with the uploaded file.
@@ -51,16 +51,16 @@ class FileTokenReplaceTest extends FileFieldTestBase {
// Generate and test sanitized tokens.
$tests = array();
- $tests['[file:fid]'] = $file->fid;
- $tests['[file:name]'] = check_plain($file->filename);
- $tests['[file:path]'] = check_plain($file->uri);
- $tests['[file:mime]'] = check_plain($file->filemime);
- $tests['[file:size]'] = format_size($file->filesize);
- $tests['[file:url]'] = check_plain(file_create_url($file->uri));
- $tests['[file:timestamp]'] = format_date($file->timestamp, 'medium', '', NULL, $language_interface->langcode);
- $tests['[file:timestamp:short]'] = format_date($file->timestamp, 'short', '', NULL, $language_interface->langcode);
+ $tests['[file:fid]'] = $file->id();
+ $tests['[file:name]'] = check_plain($file->getFilename());
+ $tests['[file:path]'] = check_plain($file->getFileUri());
+ $tests['[file:mime]'] = check_plain($file->getMimeType());
+ $tests['[file:size]'] = format_size($file->getSize());
+ $tests['[file:url]'] = check_plain(file_create_url($file->getFileUri()));
+ $tests['[file:timestamp]'] = format_date($file->getChangedTime(), 'medium', '', NULL, $language_interface->langcode);
+ $tests['[file:timestamp:short]'] = format_date($file->getChangedTime(), 'short', '', NULL, $language_interface->langcode);
$tests['[file:owner]'] = check_plain(user_format_name($this->admin_user));
- $tests['[file:owner:uid]'] = $file->uid;
+ $tests['[file:owner:uid]'] = $file->getOwner()->id();
// Test to make sure that we generated something for each token.
$this->assertFalse(in_array(0, array_map('strlen', $tests)), t('No empty tokens generated.'));
@@ -71,10 +71,10 @@ class FileTokenReplaceTest extends FileFieldTestBase {
}
// Generate and test unsanitized tokens.
- $tests['[file:name]'] = $file->filename;
- $tests['[file:path]'] = $file->uri;
- $tests['[file:mime]'] = $file->filemime;
- $tests['[file:size]'] = format_size($file->filesize);
+ $tests['[file:name]'] = $file->getFilename();
+ $tests['[file:path]'] = $file->getFileUri();
+ $tests['[file:mime]'] = $file->getMimeType();
+ $tests['[file:size]'] = format_size($file->getSize());
foreach ($tests as $input => $expected) {
$output = $token_service->replace($input, array('file' => $file), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE));
diff --git a/core/modules/file/lib/Drupal/file/Tests/LoadTest.php b/core/modules/file/lib/Drupal/file/Tests/LoadTest.php
index aaaec27..7a7f9c1 100644
--- a/core/modules/file/lib/Drupal/file/Tests/LoadTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/LoadTest.php
@@ -52,14 +52,14 @@ class LoadTest extends FileManagedTestBase {
// Create a new file entity from scratch so we know the values.
$file = $this->createFile('druplicon.txt', NULL, 'public');
- $by_fid_file = file_load($file->fid);
+ $by_fid_file = file_load($file->id());
$this->assertFileHookCalled('load');
$this->assertTrue(is_object($by_fid_file), t('file_load() returned an object.'));
- $this->assertEqual($by_fid_file->fid, $file->fid, t("Loading by fid got the same fid."), 'File');
- $this->assertEqual($by_fid_file->uri, $file->uri, t("Loading by fid got the correct filepath."), 'File');
- $this->assertEqual($by_fid_file->filename, $file->filename, t("Loading by fid got the correct filename."), 'File');
- $this->assertEqual($by_fid_file->filemime, $file->filemime, t("Loading by fid got the correct MIME type."), 'File');
- $this->assertEqual($by_fid_file->status, $file->status, t("Loading by fid got the correct status."), 'File');
+ $this->assertEqual($by_fid_file->id(), $file->id(), t("Loading by fid got the same fid."), 'File');
+ $this->assertEqual($by_fid_file->getFileUri(), $file->getFileUri(), t("Loading by fid got the correct filepath."), 'File');
+ $this->assertEqual($by_fid_file->getFilename(), $file->getFilename(), t("Loading by fid got the correct filename."), 'File');
+ $this->assertEqual($by_fid_file->getMimeType(), $file->getMimeType(), t("Loading by fid got the correct MIME type."), 'File');
+ $this->assertEqual($by_fid_file->isPermanent(), $file->isPermanent(), t("Loading by fid got the correct status."), 'File');
$this->assertTrue($by_fid_file->file_test['loaded'], t('file_test_file_load() was able to modify the file during load.'));
}
@@ -72,20 +72,20 @@ class LoadTest extends FileManagedTestBase {
// Load by path.
file_test_reset();
- $by_path_files = entity_load_multiple_by_properties('file', array('uri' => $file->uri));
+ $by_path_files = entity_load_multiple_by_properties('file', array('uri' => $file->getFileUri()));
$this->assertFileHookCalled('load');
$this->assertEqual(1, count($by_path_files), t('file_load_multiple() returned an array of the correct size.'));
$by_path_file = reset($by_path_files);
$this->assertTrue($by_path_file->file_test['loaded'], t('file_test_file_load() was able to modify the file during load.'));
- $this->assertEqual($by_path_file->fid, $file->fid, t("Loading by filepath got the correct fid."), 'File');
+ $this->assertEqual($by_path_file->id(), $file->id(), t("Loading by filepath got the correct fid."), 'File');
// Load by fid.
file_test_reset();
- $by_fid_files = file_load_multiple(array($file->fid));
+ $by_fid_files = file_load_multiple(array($file->id()));
$this->assertFileHooksCalled(array());
$this->assertEqual(1, count($by_fid_files), t('file_load_multiple() returned an array of the correct size.'));
$by_fid_file = reset($by_fid_files);
$this->assertTrue($by_fid_file->file_test['loaded'], t('file_test_file_load() was able to modify the file during load.'));
- $this->assertEqual($by_fid_file->uri, $file->uri, t("Loading by fid got the correct filepath."), 'File');
+ $this->assertEqual($by_fid_file->getFileUri(), $file->getFileUri(), t("Loading by fid got the correct filepath."), 'File');
}
}
diff --git a/core/modules/file/lib/Drupal/file/Tests/MoveTest.php b/core/modules/file/lib/Drupal/file/Tests/MoveTest.php
index 15868b1..5014fec 100644
--- a/core/modules/file/lib/Drupal/file/Tests/MoveTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/MoveTest.php
@@ -33,18 +33,18 @@ class MoveTest extends FileManagedTestBase {
// Check the return status and that the contents changed.
$this->assertTrue($result, t('File moved successfully.'));
- $this->assertFalse(file_exists($source->uri));
- $this->assertEqual($contents, file_get_contents($result->uri), t('Contents of file correctly written.'));
+ $this->assertFalse(file_exists($source->getFileUri()));
+ $this->assertEqual($contents, file_get_contents($result->getFileUri()), t('Contents of file correctly written.'));
// Check that the correct hooks were called.
$this->assertFileHooksCalled(array('move', 'load', 'update'));
// Make sure we got the same file back.
- $this->assertEqual($source->fid, $result->fid, t("Source file id's' %fid is unchanged after move.", array('%fid' => $source->fid)));
+ $this->assertEqual($source->id(), $result->id(), t("Source file id's' %fid is unchanged after move.", array('%fid' => $source->id())));
// Reload the file from the database and check that the changes were
// actually saved.
- $loaded_file = file_load($result->fid, TRUE);
+ $loaded_file = file_load($result->id(), TRUE);
$this->assertTrue($loaded_file, t('File can be loaded from the database.'));
$this->assertFileUnchanged($result, $loaded_file);
}
@@ -61,27 +61,27 @@ class MoveTest extends FileManagedTestBase {
// Clone the object so we don't have to worry about the function changing
// our reference copy.
- $result = file_move(clone $source, $target->uri, FILE_EXISTS_RENAME);
+ $result = file_move(clone $source, $target->getFileUri(), FILE_EXISTS_RENAME);
// Check the return status and that the contents changed.
$this->assertTrue($result, t('File moved successfully.'));
- $this->assertFalse(file_exists($source->uri));
- $this->assertEqual($contents, file_get_contents($result->uri), t('Contents of file correctly written.'));
+ $this->assertFalse(file_exists($source->getFileUri()));
+ $this->assertEqual($contents, file_get_contents($result->getFileUri()), t('Contents of file correctly written.'));
// Check that the correct hooks were called.
$this->assertFileHooksCalled(array('move', 'load', 'update'));
// Compare the returned value to what made it into the database.
- $this->assertFileUnchanged($result, file_load($result->fid, TRUE));
+ $this->assertFileUnchanged($result, file_load($result->id(), TRUE));
// The target file should not have been altered.
- $this->assertFileUnchanged($target, file_load($target->fid, TRUE));
+ $this->assertFileUnchanged($target, file_load($target->id(), TRUE));
// Make sure we end up with two distinct files afterwards.
$this->assertDifferentFile($target, $result);
// Compare the source and results.
- $loaded_source = file_load($source->fid, TRUE);
- $this->assertEqual($loaded_source->fid, $result->fid, t("Returned file's id matches the source."));
- $this->assertNotEqual($loaded_source->uri, $source->uri, t("Returned file path has changed from the original."));
+ $loaded_source = file_load($source->id(), TRUE);
+ $this->assertEqual($loaded_source->id(), $result->id(), t("Returned file's id matches the source."));
+ $this->assertNotEqual($loaded_source->getFileUri(), $source->getFileUri(), t("Returned file path has changed from the original."));
}
/**
@@ -96,11 +96,11 @@ class MoveTest extends FileManagedTestBase {
// Clone the object so we don't have to worry about the function changing
// our reference copy.
- $result = file_move(clone $source, $target->uri, FILE_EXISTS_REPLACE);
+ $result = file_move(clone $source, $target->getFileUri(), FILE_EXISTS_REPLACE);
// Look at the results.
- $this->assertEqual($contents, file_get_contents($result->uri), t('Contents of file were overwritten.'));
- $this->assertFalse(file_exists($source->uri));
+ $this->assertEqual($contents, file_get_contents($result->getFileUri()), t('Contents of file were overwritten.'));
+ $this->assertFalse(file_exists($source->getFileUri()));
$this->assertTrue($result, t('File moved successfully.'));
// Check that the correct hooks were called.
@@ -108,7 +108,7 @@ class MoveTest extends FileManagedTestBase {
// Reload the file from the database and check that the changes were
// actually saved.
- $loaded_result = file_load($result->fid, TRUE);
+ $loaded_result = file_load($result->id(), TRUE);
$this->assertFileUnchanged($result, $loaded_result);
// Check that target was re-used.
$this->assertSameFile($target, $loaded_result);
@@ -126,16 +126,16 @@ class MoveTest extends FileManagedTestBase {
// Copy the file over itself. Clone the object so we don't have to worry
// about the function changing our reference copy.
- $result = file_move(clone $source, $source->uri, FILE_EXISTS_REPLACE);
+ $result = file_move(clone $source, $source->getFileUri(), FILE_EXISTS_REPLACE);
$this->assertFalse($result, t('File move failed.'));
- $this->assertEqual($contents, file_get_contents($source->uri), t('Contents of file were not altered.'));
+ $this->assertEqual($contents, file_get_contents($source->getFileUri()), t('Contents of file were not altered.'));
// Check that no hooks were called while failing.
$this->assertFileHooksCalled(array());
// Load the file from the database and make sure it is identical to what
// was returned.
- $this->assertFileUnchanged($source, file_load($source->fid, TRUE));
+ $this->assertFileUnchanged($source, file_load($source->id(), TRUE));
}
/**
@@ -150,19 +150,19 @@ class MoveTest extends FileManagedTestBase {
// Clone the object so we don't have to worry about the function changing
// our reference copy.
- $result = file_move(clone $source, $target->uri, FILE_EXISTS_ERROR);
+ $result = file_move(clone $source, $target->getFileUri(), FILE_EXISTS_ERROR);
// Check the return status and that the contents did not change.
$this->assertFalse($result, t('File move failed.'));
- $this->assertTrue(file_exists($source->uri));
- $this->assertEqual($contents, file_get_contents($target->uri), t('Contents of file were not altered.'));
+ $this->assertTrue(file_exists($source->getFileUri()));
+ $this->assertEqual($contents, file_get_contents($target->getFileUri()), t('Contents of file were not altered.'));
// Check that no hooks were called while failing.
$this->assertFileHooksCalled(array());
// Load the file from the database and make sure it is identical to what
// was returned.
- $this->assertFileUnchanged($source, file_load($source->fid, TRUE));
- $this->assertFileUnchanged($target, file_load($target->fid, TRUE));
+ $this->assertFileUnchanged($source, file_load($source->id(), TRUE));
+ $this->assertFileUnchanged($target, file_load($target->id(), TRUE));
}
}
diff --git a/core/modules/file/lib/Drupal/file/Tests/SaveDataTest.php b/core/modules/file/lib/Drupal/file/Tests/SaveDataTest.php
index ecdb201..cc91598 100644
--- a/core/modules/file/lib/Drupal/file/Tests/SaveDataTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/SaveDataTest.php
@@ -28,17 +28,17 @@ class SaveDataTest extends FileManagedTestBase {
$result = file_save_data($contents);
$this->assertTrue($result, t('Unnamed file saved correctly.'));
- $this->assertEqual(file_default_scheme(), file_uri_scheme($result->uri), t("File was placed in Drupal's files directory."));
- $this->assertEqual($result->filename, drupal_basename($result->uri), t("Filename was set to the file's basename."));
- $this->assertEqual($contents, file_get_contents($result->uri), t('Contents of the file are correct.'));
- $this->assertEqual($result->filemime, 'application/octet-stream', t('A MIME type was set.'));
- $this->assertEqual($result->status, FILE_STATUS_PERMANENT, t("The file's status was set to permanent."));
+ $this->assertEqual(file_default_scheme(), file_uri_scheme($result->getFileUri()), t("File was placed in Drupal's files directory."));
+ $this->assertEqual($result->getFilename(), drupal_basename($result->getFileUri()), t("Filename was set to the file's basename."));
+ $this->assertEqual($contents, file_get_contents($result->getFileUri()), t('Contents of the file are correct.'));
+ $this->assertEqual($result->getMimeType(), 'application/octet-stream', t('A MIME type was set.'));
+ $this->assertTrue($result->isPermanent(), t("The file's status was set to permanent."));
// Check that the correct hooks were called.
$this->assertFileHooksCalled(array('insert'));
// Verify that what was returned is what's in the database.
- $this->assertFileUnchanged($result, file_load($result->fid, TRUE));
+ $this->assertFileUnchanged($result, file_load($result->id(), TRUE));
}
/**
@@ -53,17 +53,17 @@ class SaveDataTest extends FileManagedTestBase {
$result = file_save_data($contents, 'public://' . $filename);
$this->assertTrue($result, t('Unnamed file saved correctly.'));
- $this->assertEqual('public', file_uri_scheme($result->uri), t("File was placed in Drupal's files directory."));
- $this->assertEqual($filename, drupal_basename($result->uri), t('File was named correctly.'));
- $this->assertEqual($contents, file_get_contents($result->uri), t('Contents of the file are correct.'));
- $this->assertEqual($result->filemime, 'text/plain', t('A MIME type was set.'));
- $this->assertEqual($result->status, FILE_STATUS_PERMANENT, t("The file's status was set to permanent."));
+ $this->assertEqual('public', file_uri_scheme($result->getFileUri()), t("File was placed in Drupal's files directory."));
+ $this->assertEqual($filename, drupal_basename($result->getFileUri()), t('File was named correctly.'));
+ $this->assertEqual($contents, file_get_contents($result->getFileUri()), t('Contents of the file are correct.'));
+ $this->assertEqual($result->getMimeType(), 'text/plain', t('A MIME type was set.'));
+ $this->assertTrue($result->isPermanent(), t("The file's status was set to permanent."));
// Check that the correct hooks were called.
$this->assertFileHooksCalled(array('insert'));
// Verify that what was returned is what's in the database.
- $this->assertFileUnchanged($result, file_load($result->fid, TRUE));
+ $this->assertFileUnchanged($result, file_load($result->id(), TRUE));
}
/**
@@ -74,24 +74,24 @@ class SaveDataTest extends FileManagedTestBase {
$existing = $this->createFile();
$contents = $this->randomName(8);
- $result = file_save_data($contents, $existing->uri, FILE_EXISTS_RENAME);
+ $result = file_save_data($contents, $existing->getFileUri(), FILE_EXISTS_RENAME);
$this->assertTrue($result, t("File saved successfully."));
- $this->assertEqual('public', file_uri_scheme($result->uri), t("File was placed in Drupal's files directory."));
- $this->assertEqual($result->filename, $existing->filename, t("Filename was set to the basename of the source, rather than that of the renamed file."));
- $this->assertEqual($contents, file_get_contents($result->uri), t("Contents of the file are correct."));
- $this->assertEqual($result->filemime, 'application/octet-stream', t("A MIME type was set."));
- $this->assertEqual($result->status, FILE_STATUS_PERMANENT, t("The file's status was set to permanent."));
+ $this->assertEqual('public', file_uri_scheme($result->getFileUri()), t("File was placed in Drupal's files directory."));
+ $this->assertEqual($result->getFilename(), $existing->getFilename(), t("Filename was set to the basename of the source, rather than that of the renamed file."));
+ $this->assertEqual($contents, file_get_contents($result->getFileUri()), t("Contents of the file are correct."));
+ $this->assertEqual($result->getMimeType(), 'application/octet-stream', t("A MIME type was set."));
+ $this->assertTrue($result->isPermanent(), t("The file's status was set to permanent."));
// Check that the correct hooks were called.
$this->assertFileHooksCalled(array('insert'));
// Ensure that the existing file wasn't overwritten.
$this->assertDifferentFile($existing, $result);
- $this->assertFileUnchanged($existing, file_load($existing->fid, TRUE));
+ $this->assertFileUnchanged($existing, file_load($existing->id(), TRUE));
// Verify that was returned is what's in the database.
- $this->assertFileUnchanged($result, file_load($result->fid, TRUE));
+ $this->assertFileUnchanged($result, file_load($result->id(), TRUE));
}
/**
@@ -102,14 +102,14 @@ class SaveDataTest extends FileManagedTestBase {
$existing = $this->createFile();
$contents = $this->randomName(8);
- $result = file_save_data($contents, $existing->uri, FILE_EXISTS_REPLACE);
+ $result = file_save_data($contents, $existing->getFileUri(), FILE_EXISTS_REPLACE);
$this->assertTrue($result, t('File saved successfully.'));
- $this->assertEqual('public', file_uri_scheme($result->uri), t("File was placed in Drupal's files directory."));
- $this->assertEqual($result->filename, $existing->filename, t('Filename was set to the basename of the existing file, rather than preserving the original name.'));
- $this->assertEqual($contents, file_get_contents($result->uri), t('Contents of the file are correct.'));
- $this->assertEqual($result->filemime, 'application/octet-stream', t('A MIME type was set.'));
- $this->assertEqual($result->status, FILE_STATUS_PERMANENT, t("The file's status was set to permanent."));
+ $this->assertEqual('public', file_uri_scheme($result->getFileUri()), t("File was placed in Drupal's files directory."));
+ $this->assertEqual($result->getFilename(), $existing->getFilename(), t('Filename was set to the basename of the existing file, rather than preserving the original name.'));
+ $this->assertEqual($contents, file_get_contents($result->getFileUri()), t('Contents of the file are correct.'));
+ $this->assertEqual($result->getMimeType(), 'application/octet-stream', t('A MIME type was set.'));
+ $this->assertTrue($result->isPermanent(), t("The file's status was set to permanent."));
// Check that the correct hooks were called.
$this->assertFileHooksCalled(array('load', 'update'));
@@ -118,7 +118,7 @@ class SaveDataTest extends FileManagedTestBase {
$this->assertSameFile($existing, $result);
// Verify that what was returned is what's in the database.
- $this->assertFileUnchanged($result, file_load($result->fid, TRUE));
+ $this->assertFileUnchanged($result, file_load($result->id(), TRUE));
}
/**
@@ -129,14 +129,14 @@ class SaveDataTest extends FileManagedTestBase {
$existing = $this->createFile(NULL, $contents);
// Check the overwrite error.
- $result = file_save_data('asdf', $existing->uri, FILE_EXISTS_ERROR);
+ $result = file_save_data('asdf', $existing->getFileUri(), FILE_EXISTS_ERROR);
$this->assertFalse($result, t('Overwriting a file fails when FILE_EXISTS_ERROR is specified.'));
- $this->assertEqual($contents, file_get_contents($existing->uri), t('Contents of existing file were unchanged.'));
+ $this->assertEqual($contents, file_get_contents($existing->getFileUri()), t('Contents of existing file were unchanged.'));
// Check that no hooks were called while failing.
$this->assertFileHooksCalled(array());
// Ensure that the existing file wasn't overwritten.
- $this->assertFileUnchanged($existing, file_load($existing->fid, TRUE));
+ $this->assertFileUnchanged($existing, file_load($existing->id(), TRUE));
}
}
diff --git a/core/modules/file/lib/Drupal/file/Tests/SaveTest.php b/core/modules/file/lib/Drupal/file/Tests/SaveTest.php
index eeb9f77..1161421 100644
--- a/core/modules/file/lib/Drupal/file/Tests/SaveTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/SaveTest.php
@@ -31,7 +31,7 @@ class SaveTest extends FileManagedTestBase {
'timestamp' => 1,
'status' => FILE_STATUS_PERMANENT,
));
- file_put_contents($file->uri, 'hello world');
+ file_put_contents($file->getFileUri(), 'hello world');
// Save it, inserting a new record.
$file->save();
@@ -39,29 +39,29 @@ class SaveTest extends FileManagedTestBase {
// Check that the correct hooks were called.
$this->assertFileHooksCalled(array('insert'));
- $this->assertTrue($file->fid > 0, t("A new file ID is set when saving a new file to the database."), 'File');
- $loaded_file = db_query('SELECT * FROM {file_managed} f WHERE f.fid = :fid', array(':fid' => $file->fid))->fetchObject();
+ $this->assertTrue($file->id() > 0, t("A new file ID is set when saving a new file to the database."), 'File');
+ $loaded_file = file_load($file->id());
$this->assertNotNull($loaded_file, t("Record exists in the database."));
- $this->assertEqual($loaded_file->status, $file->status, t("Status was saved correctly."));
- $this->assertEqual($file->filesize, filesize($file->uri), t("File size was set correctly."), 'File');
- $this->assertTrue($file->timestamp > 1, t("File size was set correctly."), 'File');
- $this->assertEqual($loaded_file->langcode, Language::LANGCODE_NOT_SPECIFIED, t("Langcode was defaulted correctly."));
+ $this->assertEqual($loaded_file->isPermanent(), $file->isPermanent(), t("Status was saved correctly."));
+ $this->assertEqual($file->getSize(), filesize($file->getFileUri()), t("File size was set correctly."), 'File');
+ $this->assertTrue($file->getChangedTime() > 1, t("File size was set correctly."), 'File');
+ $this->assertEqual($loaded_file->langcode->value, Language::LANGCODE_NOT_SPECIFIED, t("Langcode was defaulted correctly."));
// Resave the file, updating the existing record.
file_test_reset();
- $file->status = 7;
+ $file->status->value = 7;
$file->langcode = 'en';
$file->save();
// Check that the correct hooks were called.
$this->assertFileHooksCalled(array('load', 'update'));
- $this->assertEqual($file->fid, $file->fid, t("The file ID of an existing file is not changed when updating the database."), 'File');
- $this->assertTrue($file->timestamp >= $file->timestamp, t("Timestamp didn't go backwards."), 'File');
- $loaded_file = db_query('SELECT * FROM {file_managed} f WHERE f.fid = :fid', array(':fid' => $file->fid))->fetchObject();
+ $this->assertEqual($file->id(), $file->id(), t("The file ID of an existing file is not changed when updating the database."), 'File');
+ $this->assertTrue($file->getChangedTime() >= $file->getChangedTime(), t("Timestamp didn't go backwards."), 'File');
+ $loaded_file = file_load($file->id());
$this->assertNotNull($loaded_file, t("Record still exists in the database."), 'File');
- $this->assertEqual($loaded_file->status, $file->status, t("Status was saved correctly."));
- $this->assertEqual($loaded_file->langcode, 'en', t("Langcode was saved correctly."));
+ $this->assertEqual($loaded_file->isPermanent(), $file->isPermanent(), t("Status was saved correctly."));
+ $this->assertEqual($loaded_file->langcode->value, 'en', t("Langcode was saved correctly."));
// Try to insert a second file with the same name apart from case insensitivity
// to ensure the 'uri' index allows for filenames with different cases.
@@ -73,7 +73,7 @@ class SaveTest extends FileManagedTestBase {
'timestamp' => 1,
'status' => FILE_STATUS_PERMANENT,
));
- file_put_contents($file->uri, 'hello world');
+ file_put_contents($file->getFileUri(), 'hello world');
$file->save();
}
}
diff --git a/core/modules/file/lib/Drupal/file/Tests/SaveUploadTest.php b/core/modules/file/lib/Drupal/file/Tests/SaveUploadTest.php
index 90fec9d..6e9b359 100644
--- a/core/modules/file/lib/Drupal/file/Tests/SaveUploadTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/SaveUploadTest.php
@@ -42,8 +42,8 @@ class SaveUploadTest extends FileManagedTestBase {
$image_files = $this->drupalGetTestFiles('image');
$this->image = entity_create('file', (array) current($image_files));
- list(, $this->image_extension) = explode('.', $this->image->filename);
- $this->assertTrue(is_file($this->image->uri), t("The image file we're going to upload exists."));
+ list(, $this->image_extension) = explode('.', $this->image->getFilename());
+ $this->assertTrue(is_file($this->image->getFileUri()), t("The image file we're going to upload exists."));
$this->phpfile = current($this->drupalGetTestFiles('php'));
$this->assertTrue(is_file($this->phpfile->uri), t("The PHP file we're going to upload exists."));
@@ -53,7 +53,7 @@ class SaveUploadTest extends FileManagedTestBase {
// Upload with replace to guarantee there's something there.
$edit = array(
'file_test_replace' => FILE_EXISTS_REPLACE,
- 'files[file_test_upload]' => drupal_realpath($this->image->uri),
+ 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()),
);
$this->drupalPost('file-test/upload', $edit, t('Submit'));
$this->assertResponse(200, t('Received a 200 response for posted test file.'));
@@ -74,7 +74,7 @@ class SaveUploadTest extends FileManagedTestBase {
$file1 = file_load($max_fid_after);
$this->assertTrue($file1, t('Loaded the file.'));
// MIME type of the uploaded image may be either image/jpeg or image/png.
- $this->assertEqual(substr($file1->filemime, 0, 5), 'image', 'A MIME type was set.');
+ $this->assertEqual(substr($file1->getMimeType(), 0, 5), 'image', 'A MIME type was set.');
// Reset the hook counters to get rid of the 'load' we just called.
file_test_reset();
@@ -92,14 +92,14 @@ class SaveUploadTest extends FileManagedTestBase {
$this->assertFileHooksCalled(array('validate', 'insert'));
$file2 = file_load($max_fid_after);
- $this->assertTrue($file2);
+ $this->assertTrue($file2, 'Loaded the file');
// MIME type of the uploaded image may be either image/jpeg or image/png.
- $this->assertEqual(substr($file2->filemime, 0, 5), 'image', 'A MIME type was set.');
+ $this->assertEqual(substr($file2->getMimeType(), 0, 5), 'image', 'A MIME type was set.');
// Load both files using file_load_multiple().
- $files = file_load_multiple(array($file1->fid, $file2->fid));
- $this->assertTrue(isset($files[$file1->fid]), t('File was loaded successfully'));
- $this->assertTrue(isset($files[$file2->fid]), t('File was loaded successfully'));
+ $files = file_load_multiple(array($file1->id(), $file2->id()));
+ $this->assertTrue(isset($files[$file1->id()]), t('File was loaded successfully'));
+ $this->assertTrue(isset($files[$file2->id()]), t('File was loaded successfully'));
// Upload a third file to a subdirectory.
$image3 = current($this->drupalGetTestFiles('image'));
@@ -126,7 +126,7 @@ class SaveUploadTest extends FileManagedTestBase {
$extensions = 'foo';
$edit = array(
'file_test_replace' => FILE_EXISTS_REPLACE,
- 'files[file_test_upload]' => drupal_realpath($this->image->uri),
+ 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()),
'extensions' => $extensions,
);
@@ -146,7 +146,7 @@ class SaveUploadTest extends FileManagedTestBase {
// Now tell file_save_upload() to allow the extension of our test image.
$edit = array(
'file_test_replace' => FILE_EXISTS_REPLACE,
- 'files[file_test_upload]' => drupal_realpath($this->image->uri),
+ 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()),
'extensions' => $extensions,
);
@@ -164,7 +164,7 @@ class SaveUploadTest extends FileManagedTestBase {
// Now tell file_save_upload() to allow any extension.
$edit = array(
'file_test_replace' => FILE_EXISTS_REPLACE,
- 'files[file_test_upload]' => drupal_realpath($this->image->uri),
+ 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()),
'allow_all_extensions' => TRUE,
);
$this->drupalPost('file-test/upload', $edit, t('Submit'));
@@ -225,18 +225,18 @@ class SaveUploadTest extends FileManagedTestBase {
function testHandleFileMunge() {
// Ensure insecure uploads are disabled for this test.
config('system.file')->set('allow_insecure_uploads', 0)->save();
- $this->image = file_move($this->image, $this->image->uri . '.foo.' . $this->image_extension);
+ $this->image = file_move($this->image, $this->image->getFileUri() . '.foo.' . $this->image_extension);
// Reset the hook counters to get rid of the 'move' we just called.
file_test_reset();
$extensions = $this->image_extension;
$edit = array(
- 'files[file_test_upload]' => drupal_realpath($this->image->uri),
+ 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()),
'extensions' => $extensions,
);
- $munged_filename = $this->image->filename;
+ $munged_filename = $this->image->getFilename();
$munged_filename = substr($munged_filename, 0, strrpos($munged_filename, '.'));
$munged_filename .= '_.' . $this->image_extension;
@@ -254,14 +254,14 @@ class SaveUploadTest extends FileManagedTestBase {
file_test_reset();
$edit = array(
- 'files[file_test_upload]' => drupal_realpath($this->image->uri),
+ 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()),
'allow_all_extensions' => TRUE,
);
$this->drupalPost('file-test/upload', $edit, t('Submit'));
$this->assertResponse(200, t('Received a 200 response for posted test file.'));
$this->assertNoRaw(t('For security reasons, your upload has been renamed'), t('Found no security message.'));
- $this->assertRaw(t('File name is !filename', array('!filename' => $this->image->filename)), t('File was not munged when allowing any extension.'));
+ $this->assertRaw(t('File name is !filename', array('!filename' => $this->image->getFilename())), t('File was not munged when allowing any extension.'));
$this->assertRaw(t('You WIN!'), t('Found the success message.'));
// Check that the correct hooks were called.
@@ -274,7 +274,7 @@ class SaveUploadTest extends FileManagedTestBase {
function testExistingRename() {
$edit = array(
'file_test_replace' => FILE_EXISTS_RENAME,
- 'files[file_test_upload]' => drupal_realpath($this->image->uri)
+ 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri())
);
$this->drupalPost('file-test/upload', $edit, t('Submit'));
$this->assertResponse(200, t('Received a 200 response for posted test file.'));
@@ -290,7 +290,7 @@ class SaveUploadTest extends FileManagedTestBase {
function testExistingReplace() {
$edit = array(
'file_test_replace' => FILE_EXISTS_REPLACE,
- 'files[file_test_upload]' => drupal_realpath($this->image->uri)
+ 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri())
);
$this->drupalPost('file-test/upload', $edit, t('Submit'));
$this->assertResponse(200, t('Received a 200 response for posted test file.'));
@@ -306,7 +306,7 @@ class SaveUploadTest extends FileManagedTestBase {
function testExistingError() {
$edit = array(
'file_test_replace' => FILE_EXISTS_ERROR,
- 'files[file_test_upload]' => drupal_realpath($this->image->uri)
+ 'files[file_test_upload]' => drupal_realpath($this->image->getFileUri())
);
$this->drupalPost('file-test/upload', $edit, t('Submit'));
$this->assertResponse(200, t('Received a 200 response for posted test file.'));
diff --git a/core/modules/file/lib/Drupal/file/Tests/UsageTest.php b/core/modules/file/lib/Drupal/file/Tests/UsageTest.php
index 00c82ef..d76f9d8 100644
--- a/core/modules/file/lib/Drupal/file/Tests/UsageTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/UsageTest.php
@@ -26,7 +26,7 @@ class UsageTest extends FileManagedTestBase {
$file = $this->createFile();
db_insert('file_usage')
->fields(array(
- 'fid' => $file->fid,
+ 'fid' => $file->id(),
'module' => 'testing',
'type' => 'foo',
'id' => 1,
@@ -35,7 +35,7 @@ class UsageTest extends FileManagedTestBase {
->execute();
db_insert('file_usage')
->fields(array(
- 'fid' => $file->fid,
+ 'fid' => $file->id(),
'module' => 'testing',
'type' => 'bar',
'id' => 2,
@@ -65,7 +65,7 @@ class UsageTest extends FileManagedTestBase {
$usage = db_select('file_usage', 'f')
->fields('f')
- ->condition('f.fid', $file->fid)
+ ->condition('f.fid', $file->id())
->execute()
->fetchAllAssoc('id');
$this->assertEqual(count($usage), 2, t('Created two records'));
@@ -84,7 +84,7 @@ class UsageTest extends FileManagedTestBase {
$file = $this->createFile();
db_insert('file_usage')
->fields(array(
- 'fid' => $file->fid,
+ 'fid' => $file->id(),
'module' => 'testing',
'type' => 'bar',
'id' => 2,
@@ -96,7 +96,7 @@ class UsageTest extends FileManagedTestBase {
file_usage()->delete($file, 'testing', 'bar', 2);
$count = db_select('file_usage', 'f')
->fields('f', array('count'))
- ->condition('f.fid', $file->fid)
+ ->condition('f.fid', $file->id())
->execute()
->fetchField();
$this->assertEqual(2, $count, t('The count was decremented correctly.'));
@@ -105,7 +105,7 @@ class UsageTest extends FileManagedTestBase {
file_usage()->delete($file, 'testing', 'bar', 2, 2);
$count = db_select('file_usage', 'f')
->fields('f', array('count'))
- ->condition('f.fid', $file->fid)
+ ->condition('f.fid', $file->id())
->execute()
->fetchField();
$this->assertIdentical(FALSE, $count, t('The count was removed entirely when empty.'));
@@ -114,7 +114,7 @@ class UsageTest extends FileManagedTestBase {
file_usage()->delete($file, 'testing', 'bar', 2);
$count = db_select('file_usage', 'f')
->fields('f', array('count'))
- ->condition('f.fid', $file->fid)
+ ->condition('f.fid', $file->id())
->execute()
->fetchField();
$this->assertIdentical(FALSE, $count, t('Decrementing non-exist record complete.'));
@@ -134,35 +134,35 @@ class UsageTest extends FileManagedTestBase {
'status' => 0,
'timestamp' => 1,
))
- ->condition('fid', $temp_old->fid)
+ ->condition('fid', $temp_old->id())
->execute();
- $this->assertTrue(file_exists($temp_old->uri), t('Old temp file was created correctly.'));
+ $this->assertTrue(file_exists($temp_old->getFileUri()), t('Old temp file was created correctly.'));
// Temporary file that is less than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
$temp_new = file_save_data('');
db_update('file_managed')
->fields(array('status' => 0))
- ->condition('fid', $temp_new->fid)
+ ->condition('fid', $temp_new->id())
->execute();
- $this->assertTrue(file_exists($temp_new->uri), t('New temp file was created correctly.'));
+ $this->assertTrue(file_exists($temp_new->getFileUri()), t('New temp file was created correctly.'));
// Permanent file that is older than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
$perm_old = file_save_data('');
db_update('file_managed')
->fields(array('timestamp' => 1))
- ->condition('fid', $temp_old->fid)
+ ->condition('fid', $temp_old->id())
->execute();
- $this->assertTrue(file_exists($perm_old->uri), t('Old permanent file was created correctly.'));
+ $this->assertTrue(file_exists($perm_old->getFileUri()), t('Old permanent file was created correctly.'));
// Permanent file that is newer than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
$perm_new = file_save_data('');
- $this->assertTrue(file_exists($perm_new->uri), t('New permanent file was created correctly.'));
+ $this->assertTrue(file_exists($perm_new->getFileUri()), t('New permanent file was created correctly.'));
// Run cron and then ensure that only the old, temp file was deleted.
$this->cronRun();
- $this->assertFalse(file_exists($temp_old->uri), t('Old temp file was correctly removed.'));
- $this->assertTrue(file_exists($temp_new->uri), t('New temp file was correctly ignored.'));
- $this->assertTrue(file_exists($perm_old->uri), t('Old permanent file was correctly ignored.'));
- $this->assertTrue(file_exists($perm_new->uri), t('New permanent file was correctly ignored.'));
+ $this->assertFalse(file_exists($temp_old->getFileUri()), t('Old temp file was correctly removed.'));
+ $this->assertTrue(file_exists($temp_new->getFileUri()), t('New temp file was correctly ignored.'));
+ $this->assertTrue(file_exists($perm_old->getFileUri()), t('Old permanent file was correctly ignored.'));
+ $this->assertTrue(file_exists($perm_new->getFileUri()), t('New permanent file was correctly ignored.'));
}
}
diff --git a/core/modules/file/lib/Drupal/file/Tests/ValidatorTest.php b/core/modules/file/lib/Drupal/file/Tests/ValidatorTest.php
index d8164c1..dc6c2ed 100644
--- a/core/modules/file/lib/Drupal/file/Tests/ValidatorTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/ValidatorTest.php
@@ -23,12 +23,12 @@ class ValidatorTest extends FileManagedTestBase {
parent::setUp();
$this->image = entity_create('file', array());
- $this->image->uri = 'core/misc/druplicon.png';
- $this->image->filename = drupal_basename($this->image->uri);
+ $this->image->setFileUri('core/misc/druplicon.png');
+ $this->image->setFilename(drupal_basename($this->image->getFileUri()));
$this->non_image = entity_create('file', array());
- $this->non_image->uri = 'core/misc/jquery.js';
- $this->non_image->filename = drupal_basename($this->non_image->uri);
+ $this->non_image->setFileUri('core/misc/jquery.js');
+ $this->non_image->setFilename(drupal_basename($this->non_image->getFileUri()));
}
/**
@@ -39,7 +39,7 @@ class ValidatorTest extends FileManagedTestBase {
$errors = file_validate_extensions($file, 'asdf txt pork');
$this->assertEqual(count($errors), 0, t('Valid extension accepted.'), 'File');
- $file->filename = 'asdf.txt';
+ $file->setFilename('asdf.txt');
$errors = file_validate_extensions($file, 'exe png');
$this->assertEqual(count($errors), 1, t('Invalid extension blocked.'), 'File');
}
@@ -48,11 +48,11 @@ class ValidatorTest extends FileManagedTestBase {
* This ensures a specific file is actually an image.
*/
function testFileValidateIsImage() {
- $this->assertTrue(file_exists($this->image->uri), t('The image being tested exists.'), 'File');
+ $this->assertTrue(file_exists($this->image->getFileUri()), t('The image being tested exists.'), 'File');
$errors = file_validate_is_image($this->image);
$this->assertEqual(count($errors), 0, t('No error reported for our image file.'), 'File');
- $this->assertTrue(file_exists($this->non_image->uri), t('The non-image being tested exists.'), 'File');
+ $this->assertTrue(file_exists($this->non_image->getFileUri()), t('The non-image being tested exists.'), 'File');
$errors = file_validate_is_image($this->non_image);
$this->assertEqual(count($errors), 1, t('An error reported for our non-image file.'), 'File');
}
@@ -82,12 +82,12 @@ class ValidatorTest extends FileManagedTestBase {
if ($this->container->has('image.toolkit')) {
// Copy the image so that the original doesn't get resized.
copy('core/misc/druplicon.png', 'temporary://druplicon.png');
- $this->image->uri = 'temporary://druplicon.png';
+ $this->image->setFileUri('temporary://druplicon.png');
$errors = file_validate_image_resolution($this->image, '10x5');
$this->assertEqual(count($errors), 0, t('No errors should be reported when an oversized image can be scaled down.'), 'File');
- $info = image_get_info($this->image->uri);
+ $info = image_get_info($this->image->getFileUri());
$this->assertTrue($info['width'] <= 10, t('Image scaled to correct width.'), 'File');
$this->assertTrue($info['height'] <= 5, t('Image scaled to correct height.'), 'File');
@@ -108,18 +108,18 @@ class ValidatorTest extends FileManagedTestBase {
$file = entity_create('file', array());
// Add a filename with an allowed length and test it.
- $file->filename = str_repeat('x', 240);
- $this->assertEqual(strlen($file->filename), 240);
+ $file->setFilename(str_repeat('x', 240));
+ $this->assertEqual(strlen($file->getFilename()), 240);
$errors = file_validate_name_length($file);
$this->assertEqual(count($errors), 0, t('No errors reported for 240 length filename.'), 'File');
// Add a filename with a length too long and test it.
- $file->filename = str_repeat('x', 241);
+ $file->setFilename(str_repeat('x', 241));
$errors = file_validate_name_length($file);
$this->assertEqual(count($errors), 1, t('An error reported for 241 length filename.'), 'File');
// Add a filename with an empty string and test it.
- $file->filename = '';
+ $file->setFilename('');
$errors = file_validate_name_length($file);
$this->assertEqual(count($errors), 1, t('An error reported for 0 length filename.'), 'File');
}
diff --git a/core/modules/file/tests/file_test/file_test.module b/core/modules/file/tests/file_test/file_test.module
index 5f71a60..b6b88dc 100644
--- a/core/modules/file/tests/file_test/file_test.module
+++ b/core/modules/file/tests/file_test/file_test.module
@@ -152,7 +152,7 @@ function file_test_set_return($op, $value) {
*/
function file_test_file_load($files) {
foreach ($files as $file) {
- _file_test_log_call('load', array($file->fid));
+ _file_test_log_call('load', array($file->id()));
// Assign a value on the object so that we can test that the $file is passed
// by reference.
$file->file_test['loaded'] = TRUE;
@@ -163,7 +163,7 @@ function file_test_file_load($files) {
* Implements hook_file_validate().
*/
function file_test_file_validate(File $file) {
- _file_test_log_call('validate', array($file->fid));
+ _file_test_log_call('validate', array($file->id()));
return _file_test_get_return('validate');
}
@@ -179,35 +179,35 @@ function file_test_file_download($uri) {
* Implements hook_file_insert().
*/
function file_test_file_insert(File $file) {
- _file_test_log_call('insert', array($file->fid));
+ _file_test_log_call('insert', array($file->id()));
}
/**
* Implements hook_file_update().
*/
function file_test_file_update(File $file) {
- _file_test_log_call('update', array($file->fid));
+ _file_test_log_call('update', array($file->id()));
}
/**
* Implements hook_file_copy().
*/
function file_test_file_copy(File $file, $source) {
- _file_test_log_call('copy', array($file->fid, $source->fid));
+ _file_test_log_call('copy', array($file->id(), $source->id()));
}
/**
* Implements hook_file_move().
*/
function file_test_file_move(File $file, File $source) {
- _file_test_log_call('move', array($file->fid, $source->fid));
+ _file_test_log_call('move', array($file->id(), $source->id()));
}
/**
* Implements hook_file_predelete().
*/
function file_test_file_predelete(File $file) {
- _file_test_log_call('delete', array($file->fid));
+ _file_test_log_call('delete', array($file->id()));
}
/**
diff --git a/core/modules/file/tests/file_test/lib/Drupal/file_test/Form/FileTestForm.php b/core/modules/file/tests/file_test/lib/Drupal/file_test/Form/FileTestForm.php
index 890a410..b15bc1c 100644
--- a/core/modules/file/tests/file_test/lib/Drupal/file_test/Form/FileTestForm.php
+++ b/core/modules/file/tests/file_test/lib/Drupal/file_test/Form/FileTestForm.php
@@ -104,9 +104,9 @@ class FileTestForm implements FormInterface {
$file = file_save_upload('file_test_upload', $validators, $destination, 0, $form_state['values']['file_test_replace']);
if ($file) {
$form_state['values']['file_test_upload'] = $file;
- drupal_set_message(t('File @filepath was uploaded.', array('@filepath' => $file->uri)));
- drupal_set_message(t('File name is @filename.', array('@filename' => $file->filename)));
- drupal_set_message(t('File MIME type is @mimetype.', array('@mimetype' => $file->filemime)));
+ drupal_set_message(t('File @filepath was uploaded.', array('@filepath' => $file->getFileUri())));
+ drupal_set_message(t('File name is @filename.', array('@filename' => $file->getFilename())));
+ drupal_set_message(t('File MIME type is @mimetype.', array('@mimetype' => $file->getMimeType())));
drupal_set_message(t('You WIN!'));
}
elseif ($file === FALSE) {
diff --git a/core/modules/image/image.field.inc b/core/modules/image/image.field.inc
index 705bcf3..6158679 100644
--- a/core/modules/image/image.field.inc
+++ b/core/modules/image/image.field.inc
@@ -243,10 +243,12 @@ function image_field_prepare_view($entity_type, $entities, $field, $instances, $
// Add the default image if one is found.
if ($fid && ($file = file_load($fid[0]))) {
- $items[$id][0] = (array) $file + array(
+ $items[$id][0] = array(
'is_default' => TRUE,
'alt' => '',
'title' => '',
+ 'entity' => $file,
+ 'fid' => $file->id(),
);
}
}
@@ -261,7 +263,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'])->uri);
+ $info = image_get_info(file_load($item['fid'])->getFileUri());
if (is_array($info)) {
$item['width'] = $info['width'];
@@ -323,7 +325,7 @@ function image_field_widget_process($element, &$form_state, $form) {
$file = reset($element['#files']);
$variables = array(
'style_name' => $element['#preview_image_style'],
- 'uri' => $file->uri,
+ 'uri' => $file->getFileUri(),
);
// Determine image dimensions.
@@ -332,7 +334,7 @@ function image_field_widget_process($element, &$form_state, $form) {
$variables['height'] = $element['#value']['height'];
}
else {
- $info = image_get_info($file->uri);
+ $info = image_get_info($file->getFileUri());
if (is_array($info)) {
$variables['width'] = $info['width'];
@@ -440,7 +442,7 @@ function theme_image_widget($variables) {
$output .= '<div class="image-widget-data">';
if (!empty($element['fids']['#value'])) {
$file = reset($element['#files']);
- $element['file_' . $file->fid]['filename']['#markup'] .= ' <span class="file-size">(' . format_size($file->filesize) . ')</span> ';
+ $element['file_' . $file->id()]['filename']['#markup'] .= ' <span class="file-size">(' . format_size($file->getSize()) . ')</span> ';
}
$output .= drupal_render_children($element);
$output .= '</div>';
@@ -468,6 +470,10 @@ function theme_image_formatter($variables) {
unset($item['title']);
}
+ if (isset($item['entity']) && empty($item['uri'])) {
+ $item['uri'] = $item['entity']->getFileUri();
+ }
+
if ($variables['image_style']) {
$item['style_name'] = $variables['image_style'];
$output = theme('image_style', $item);
diff --git a/core/modules/image/image.module b/core/modules/image/image.module
index 47b2e21..e8dc3d4 100644
--- a/core/modules/image/image.module
+++ b/core/modules/image/image.module
@@ -335,7 +335,7 @@ function image_file_download($uri) {
*/
function image_file_move(File $file, File $source) {
// Delete any image derivatives at the original image path.
- image_path_flush($source->uri);
+ image_path_flush($source->getFileUri());
}
/**
@@ -343,7 +343,7 @@ function image_file_move(File $file, File $source) {
*/
function image_file_predelete(File $file) {
// Delete any image derivatives of this image.
- image_path_flush($file->uri);
+ image_path_flush($file->getFileUri());
}
/**
@@ -391,7 +391,7 @@ function image_field_update_field($field, $prior_field, $has_data) {
}
// If the upload destination changed, then move the file.
- if ($file_new && (file_uri_scheme($file_new->uri) != $field['settings']['uri_scheme'])) {
+ if ($file_new && (file_uri_scheme($file_new->getFileUri()) != $field['settings']['uri_scheme'])) {
$directory = $field['settings']['uri_scheme'] . '://default_images/';
file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
file_move($file_new, $directory . $file_new->filename);
@@ -458,7 +458,7 @@ function image_field_update_instance($instance, $prior_instance) {
}
// If the upload destination changed, then move the file.
- if ($file_new && (file_uri_scheme($file_new->uri) != $field['settings']['uri_scheme'])) {
+ if ($file_new && (file_uri_scheme($file_new->getFileUri()) != $field['settings']['uri_scheme'])) {
$directory = $field['settings']['uri_scheme'] . '://default_images/';
file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
file_move($file_new, $directory . $file_new->filename);
diff --git a/core/modules/image/lib/Drupal/image/Plugin/field/formatter/ImageFormatter.php b/core/modules/image/lib/Drupal/image/Plugin/field/formatter/ImageFormatter.php
index 1f8405e..11fc4ea 100644
--- a/core/modules/image/lib/Drupal/image/Plugin/field/formatter/ImageFormatter.php
+++ b/core/modules/image/lib/Drupal/image/Plugin/field/formatter/ImageFormatter.php
@@ -108,8 +108,9 @@ class ImageFormatter extends FormatterBase {
$image_style_setting = $this->getSetting('image_style');
foreach ($items as $delta => $item) {
if (isset($link_file)) {
+ $image_uri = $item['entity']->getFileUri();
$uri = array(
- 'path' => file_create_url($item['uri']),
+ 'path' => file_create_url($image_uri),
'options' => array(),
);
}
diff --git a/core/modules/system/lib/Drupal/system/Tests/Image/FileMoveTest.php b/core/modules/image/lib/Drupal/image/Tests/FileMoveTest.php
index 336888e..f085f2d 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Image/FileMoveTest.php
+++ b/core/modules/image/lib/Drupal/image/Tests/FileMoveTest.php
@@ -2,15 +2,15 @@
/**
* @file
- * Definition of Drupal\system\Tests\Image\FileMoveTest.
+ * Contains \Drupal\image\Tests\FileMoveTest.
*/
-namespace Drupal\system\Tests\Image;
+namespace Drupal\image\Tests;
+
+use Drupal\system\Tests\Image\ToolkitTestBase;
/**
- * Tests the file move function for managed files.
- *
- * @todo This test belongs to File module.
+ * Tests the file move function for images and image styles.
*/
class FileMoveTest extends ToolkitTestBase {
@@ -39,8 +39,8 @@ class FileMoveTest extends ToolkitTestBase {
// Create derivative image.
$styles = entity_load_multiple('image_style');
$style = image_style_load(key($styles));
- $derivative_uri = image_style_path($style->id(), $file->uri);
- image_style_create_derivative($style, $file->uri, $derivative_uri);
+ $derivative_uri = image_style_path($style->id(), $file->getFileUri());
+ image_style_create_derivative($style, $file->getFileUri(), $derivative_uri);
// Check if derivative image exists.
$this->assertTrue(file_exists($derivative_uri), 'Make sure derivative image is generated successfully.');
@@ -51,7 +51,7 @@ class FileMoveTest extends ToolkitTestBase {
$result = file_move(clone $file, $desired_filepath, FILE_EXISTS_ERROR);
// Check if image has been moved.
- $this->assertTrue(file_exists($result->uri), 'Make sure image is moved successfully.');
+ $this->assertTrue(file_exists($result->getFileUri()), 'Make sure image is moved successfully.');
// Check if derivative image has been flushed.
$this->assertFalse(file_exists($derivative_uri), 'Make sure derivative image has been flushed.');
diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php
index f7e5d35..96941b3 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 @@ class ImageAdminStylesTest extends ImageFieldTestBase {
// 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'])->uri), 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]['fid'])->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 @@ class ImageAdminStylesTest extends ImageFieldTestBase {
$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'])->uri), 'Image displayed using style replacement style.');
+ $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.');
// Delete the style and choose a replacement style.
$edit = array(
@@ -296,7 +296,7 @@ class ImageAdminStylesTest extends ImageFieldTestBase {
$this->assertRaw($message);
$this->drupalGet('node/' . $nid);
- $this->assertRaw(image_style_url('thumbnail', file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->uri), 'Image displayed using style replacement style.');
+ $this->assertRaw(image_style_url('thumbnail', file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->getFileUri()), 'Image displayed using style replacement style.');
}
/**
@@ -362,7 +362,7 @@ class ImageAdminStylesTest extends ImageFieldTestBase {
// 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'])->uri), 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]['fid'])->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/ImageFieldDefaultImagesTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php
index 78a957f..c2c2f62 100644
--- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php
+++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php
@@ -43,10 +43,10 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
// Create an image field and add an instance to the article content type.
$field_name = strtolower($this->randomName());
$field_settings = array(
- 'default_image' => $default_images['field']->fid,
+ 'default_image' => $default_images['field']->id(),
);
$instance_settings = array(
- 'default_image' => $default_images['instance']->fid,
+ 'default_image' => $default_images['instance']->id(),
);
$widget_settings = array(
'preview_image_style' => 'medium',
@@ -63,7 +63,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
'label' => $instance['label'],
'required' => $instance['required'],
'settings' => array(
- 'default_image' => $default_images['instance2']->fid,
+ 'default_image' => $default_images['instance2']->id(),
),
);
field_create_instance($instance2);
@@ -81,20 +81,20 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
$this->drupalGet("admin/structure/types/manage/article/fields/$instance->id/field");
$this->assertFieldByXpath(
'//input[@name="field[settings][default_image][fids]"]',
- $default_images['field']->fid,
+ $default_images['field']->id(),
format_string(
'Article image field default equals expected file ID of @fid.',
- array('@fid' => $default_images['field']->fid)
+ array('@fid' => $default_images['field']->id())
)
);
// Confirm the defaults are present on the article field edit form.
$this->drupalGet("admin/structure/types/manage/article/fields/$instance->id");
$this->assertFieldByXpath(
'//input[@name="instance[settings][default_image][fids]"]',
- $default_images['instance']->fid,
+ $default_images['instance']->id(),
format_string(
'Article image field instance default equals expected file ID of @fid.',
- array('@fid' => $default_images['instance']->fid)
+ array('@fid' => $default_images['instance']->id())
)
);
@@ -102,20 +102,20 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
$this->drupalGet("admin/structure/types/manage/page/fields/$instance->id/field");
$this->assertFieldByXpath(
'//input[@name="field[settings][default_image][fids]"]',
- $default_images['field']->fid,
+ $default_images['field']->id(),
format_string(
'Page image field default equals expected file ID of @fid.',
- array('@fid' => $default_images['field']->fid)
+ array('@fid' => $default_images['field']->id())
)
);
// Confirm the defaults are present on the page field edit form.
$this->drupalGet("admin/structure/types/manage/page/fields/$instance2->id");
$this->assertFieldByXpath(
'//input[@name="instance[settings][default_image][fids]"]',
- $default_images['instance2']->fid,
+ $default_images['instance2']->id(),
format_string(
'Page image field instance default equals expected file ID of @fid.',
- array('@fid' => $default_images['instance2']->fid)
+ array('@fid' => $default_images['instance2']->id())
)
);
@@ -124,10 +124,10 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
$article_built = node_view($article);
$this->assertEqual(
$article_built[$field_name]['#items'][0]['fid'],
- $default_images['instance']->fid,
+ $default_images['instance']->id(),
format_string(
'A new article node without an image has the expected default image file ID of @fid.',
- array('@fid' => $default_images['instance']->fid)
+ array('@fid' => $default_images['instance']->id())
)
);
@@ -136,25 +136,25 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
$page_built = node_view($page);
$this->assertEqual(
$page_built[$field_name]['#items'][0]['fid'],
- $default_images['instance2']->fid,
+ $default_images['instance2']->id(),
format_string(
'A new page node without an image has the expected default image file ID of @fid.',
- array('@fid' => $default_images['instance2']->fid)
+ array('@fid' => $default_images['instance2']->id())
)
);
// Upload a new default for the field.
- $field['settings']['default_image'] = array($default_images['field_new']->fid);
+ $field['settings']['default_image'] = array($default_images['field_new']->id());
field_update_field($field);
// Confirm that the new default is used on the article field settings form.
$this->drupalGet("admin/structure/types/manage/article/fields/$instance->id/field");
$this->assertFieldByXpath(
'//input[@name="field[settings][default_image][fids]"]',
- $default_images['field_new']->fid,
+ $default_images['field_new']->id(),
format_string(
'Updated image field default equals expected file ID of @fid.',
- array('@fid' => $default_images['field_new']->fid)
+ array('@fid' => $default_images['field_new']->id())
)
);
@@ -163,23 +163,23 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
$page_built = node_view($page = node_load($page->nid, TRUE));
$this->assertEqual(
$article_built[$field_name]['#items'][0]['fid'],
- $default_images['instance']->fid,
+ $default_images['instance']->id(),
format_string(
'An existing article node without an image has the expected default image file ID of @fid.',
- array('@fid' => $default_images['instance']->fid)
+ array('@fid' => $default_images['instance']->id())
)
);
$this->assertEqual(
$page_built[$field_name]['#items'][0]['fid'],
- $default_images['instance2']->fid,
+ $default_images['instance2']->id(),
format_string(
'An existing page node without an image has the expected default image file ID of @fid.',
- array('@fid' => $default_images['instance2']->fid)
+ array('@fid' => $default_images['instance2']->id())
)
);
// Upload a new default for the article's field instance.
- $instance['settings']['default_image'] = $default_images['instance_new']->fid;
+ $instance['settings']['default_image'] = $default_images['instance_new']->id();
field_update_instance($instance);
// Confirm the new field instance default is used on the article field
@@ -187,10 +187,10 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
$this->drupalGet("admin/structure/types/manage/article/fields/$instance->id");
$this->assertFieldByXpath(
'//input[@name="instance[settings][default_image][fids]"]',
- $default_images['instance_new']->fid,
+ $default_images['instance_new']->id(),
format_string(
'Updated article image field instance default equals expected file ID of @fid.',
- array('@fid' => $default_images['instance_new']->fid)
+ array('@fid' => $default_images['instance_new']->id())
)
);
@@ -201,19 +201,19 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
// Confirm the article uses the new default.
$this->assertEqual(
$article_built[$field_name]['#items'][0]['fid'],
- $default_images['instance_new']->fid,
+ $default_images['instance_new']->id(),
format_string(
'An existing article node without an image has the expected default image file ID of @fid.',
- array('@fid' => $default_images['instance_new']->fid)
+ array('@fid' => $default_images['instance_new']->id())
)
);
// Confirm the page remains unchanged.
$this->assertEqual(
$page_built[$field_name]['#items'][0]['fid'],
- $default_images['instance2']->fid,
+ $default_images['instance2']->id(),
format_string(
'An existing page node without an image has the expected default image file ID of @fid.',
- array('@fid' => $default_images['instance2']->fid)
+ array('@fid' => $default_images['instance2']->id())
)
);
@@ -235,19 +235,19 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
// Confirm the article uses the new field (not instance) default.
$this->assertEqual(
$article_built[$field_name]['#items'][0]['fid'],
- $default_images['field_new']->fid,
+ $default_images['field_new']->id(),
format_string(
'An existing article node without an image has the expected default image file ID of @fid.',
- array('@fid' => $default_images['field_new']->fid)
+ array('@fid' => $default_images['field_new']->id())
)
);
// Confirm the page remains unchanged.
$this->assertEqual(
$page_built[$field_name]['#items'][0]['fid'],
- $default_images['instance2']->fid,
+ $default_images['instance2']->id(),
format_string(
'An existing page node without an image has the expected default image file ID of @fid.',
- array('@fid' => $default_images['instance2']->fid)
+ array('@fid' => $default_images['instance2']->id())
)
);
}
diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php
index 3aaf93e..ccc39bd 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 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
$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'])->uri;
+ $image_uri = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->getFileUri();
$image_info = array(
'uri' => $image_uri,
'width' => 40,
@@ -165,7 +165,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
// style.
$node = node_load($nid, TRUE);
$image_info = array(
- 'uri' => file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->uri,
+ 'uri' => file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->getFileUri(),
'width' => 220,
'height' => 110,
'style_name' => 'medium',
@@ -175,7 +175,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
// 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'])->uri,
+ 'uri' => file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->getFileUri(),
'alt' => $this->randomName(),
'title' => $this->randomName(),
'width' => 40,
@@ -233,8 +233,8 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
field_info_cache_clear();
$field = field_info_field($field_name);
$image = file_load($field['settings']['default_image']);
- $this->assertTrue($image->status == FILE_STATUS_PERMANENT, 'The default image status is permanent.');
- $default_output = theme('image', array('uri' => $image->uri));
+ $this->assertTrue($image->isPermanent(), 'The default image status is permanent.');
+ $default_output = theme('image', array('uri' => $image->getFileUri()));
$this->drupalGet('node/' . $node->nid);
$this->assertRaw($default_output, 'Default image displayed when no user supplied image is present.');
@@ -243,7 +243,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
$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'])->uri,
+ 'uri' => file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->getFileUri(),
'width' => 40,
'height' => 20,
);
@@ -275,12 +275,12 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
$private_field = field_info_field($private_field_name);
$image = file_load($private_field['settings']['default_image']);
- $this->assertEqual('private', file_uri_scheme($image->uri), 'Default image uses private:// scheme.');
- $this->assertTrue($image->status == FILE_STATUS_PERMANENT, 'The default image status is permanent.');
+ $this->assertEqual('private', file_uri_scheme($image->getFileUri()), 'Default image uses private:// scheme.');
+ $this->assertTrue($image->isPermanent(), 'The default image status is permanent.');
// Create a new node with no image attached and ensure that default private
// image is displayed.
$node = $this->drupalCreateNode(array('type' => 'article'));
- $default_output = theme('image', array('uri' => $image->uri));
+ $default_output = theme('image', array('uri' => $image->getFileUri()));
$this->drupalGet('node/' . $node->nid);
$this->assertRaw($default_output, 'Default private image displayed when no user supplied image is present.');
}
diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php
index 9cb28cb..bed3d3a 100644
--- a/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php
+++ b/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php
@@ -99,7 +99,7 @@ class ImageItemTest extends FieldUnitTestBase {
$entity->image_test->width = NULL;
$entity->save();
$this->assertEqual($entity->image_test->entity->id(), $image2->id());
- $this->assertEqual($entity->image_test->entity->uri, $image2->uri);
+ $this->assertEqual($entity->image_test->entity->getFileUri(), $image2->getFileUri());
$info = image_get_info('public://example-2.jpg');
$this->assertEqual($entity->image_test->width, $info['width']);
$this->assertEqual($entity->image_test->height, $info['height']);
diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php
index 67a25d2..f85be0f 100644
--- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php
+++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateTest.php
@@ -147,8 +147,8 @@ EOF;
'timestamp' => $timestamp,
'status' => FILE_STATUS_PERMANENT,
));
- file_put_contents($file->uri, $po_header . $text);
- touch(drupal_realpath($file->uri), $timestamp);
+ file_put_contents($file->getFileUri(), $po_header . $text);
+ touch(drupal_realpath($file->getFileUri()), $timestamp);
$file->save();
}
diff --git a/core/modules/locale/locale.bulk.inc b/core/modules/locale/locale.bulk.inc
index 6f011af..26f816d 100644
--- a/core/modules/locale/locale.bulk.inc
+++ b/core/modules/locale/locale.bulk.inc
@@ -10,6 +10,7 @@ use Drupal\locale\Gettext;
use Drupal\locale\PoDatabaseReader;
use Drupal\Core\Language\Language;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
+use Drupal\file\FileInterface;
/**
* Form constructor for the translation import screen.
@@ -685,6 +686,14 @@ function locale_translate_file_create($filepath) {
* Modified file object.
*/
function locale_translate_file_attach_properties($file, $options = array()) {
+ // If $file is a file entity, convert it to a stdClass.
+ if ($file instanceof FileInterface) {
+ $file = (object) array(
+ 'filename' => $file->getFilename(),
+ 'uri' => $file->getFileUri(),
+ );
+ }
+
// Extract project, verion and language code from the file name. Supported:
// {project}-{version}.{langcode}.po, {prefix}.{langcode}.po or {langcode}.po
preg_match('!
diff --git a/core/modules/picture/lib/Drupal/picture/Plugin/field/formatter/PictureFormatter.php b/core/modules/picture/lib/Drupal/picture/Plugin/field/formatter/PictureFormatter.php
index 93ab7fc..0647a39 100644
--- a/core/modules/picture/lib/Drupal/picture/Plugin/field/formatter/PictureFormatter.php
+++ b/core/modules/picture/lib/Drupal/picture/Plugin/field/formatter/PictureFormatter.php
@@ -167,7 +167,7 @@ class PictureFormatter extends FormatterBase {
foreach ($items as $delta => $item) {
if (isset($link_file)) {
$uri = array(
- 'path' => file_create_url($item['uri']),
+ 'path' => file_create_url($item['entity']->getFileUri()),
'options' => array(),
);
}
diff --git a/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php b/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php
index 3d61841..927097d 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 @@ class PictureFieldDisplayTest extends ImageFieldTestBase {
$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'])->uri;
+ $image_uri = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->getFileUri();
$image_info = array(
'uri' => $image_uri,
'width' => 40,
diff --git a/core/modules/picture/picture.module b/core/modules/picture/picture.module
index 7dbbaee..e2902ce 100644
--- a/core/modules/picture/picture.module
+++ b/core/modules/picture/picture.module
@@ -197,8 +197,8 @@ function theme_picture_formatter($variables) {
$item['style_name'] = $variables['image_style'];
$item['breakpoints'] = $variables['breakpoints'];
- if (!isset($item['path']) && isset($variables['uri'])) {
- $item['path'] = $variables['uri'];
+ if (!isset($item['uri']) && isset($item['entity'])) {
+ $item['uri'] = $item['entity']->getFileUri();
}
$output = theme('picture', $item);
diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php
index 2f517e1..320126c 100644
--- a/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php
+++ b/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php
@@ -156,8 +156,8 @@ class RdfaMarkupTest extends WebTestBase {
// Prepares filenames for lookup in RDF graph.
$node = node_load($node->nid);
$node_uri = url('node/' . $node->nid, array('absolute' => TRUE));
- $file_uri = file_create_url(file_load($node->file_test['und'][0]['fid'])->uri);
- $image_uri = image_style_url('medium', file_load($node->field_image['und'][0]['fid'])->uri);
+ $file_uri = file_create_url(file_load($node->file_test['und'][0]['fid'])->getFileUri());
+ $image_uri = image_style_url('medium', file_load($node->field_image['und'][0]['fid'])->getFileUri());
$base_uri = url('<front>', array('absolute' => TRUE));
// Edits the node to add tags.
diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module
index f1eb7e7..3ae6ff5 100644
--- a/core/modules/rdf/rdf.module
+++ b/core/modules/rdf/rdf.module
@@ -590,12 +590,12 @@ function rdf_preprocess_field(&$variables) {
// not output correctly if the filetype icon comes before the link to the
// file. We correct this by adding a resource attribute to the div if
// this field has a URI.
- if (isset($item['uri'])) {
+ if (isset($item['entity']->uri)) {
if (!empty($element[$delta]['#image_style'])) {
- $variables['item_attributes'][$delta]['resource'] = image_style_url($element[$delta]['#image_style'], $item['uri']);
+ $variables['item_attributes'][$delta]['resource'] = image_style_url($element[$delta]['#image_style'], $item['entity']->getFileUri());
}
else {
- $variables['item_attributes'][$delta]['resource'] = file_create_url($item['uri']);
+ $variables['item_attributes'][$delta]['resource'] = file_create_url($item['entity']->getFileUri());
}
}
}
diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php
index 7cb18bd..3649529 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php
@@ -241,7 +241,7 @@ class EntityCrudHookTest extends EntityUnitTestBase {
));
$_SESSION['entity_crud_hook_test'] = array();
- $file = file_load($file->fid);
+ $file = file_load($file->id());
$this->assertHookMessageOrder(array(
'entity_crud_hook_test_entity_load called for type file',
@@ -249,7 +249,7 @@ class EntityCrudHookTest extends EntityUnitTestBase {
));
$_SESSION['entity_crud_hook_test'] = array();
- $file->filename = 'new.entity_crud_hook_test.file';
+ $file->setFilename('new.entity_crud_hook_test.file');
$file->save();
$this->assertHookMessageOrder(array(
diff --git a/core/modules/system/lib/Drupal/system/Tests/File/FileTestBase.php b/core/modules/system/lib/Drupal/system/Tests/File/FileTestBase.php
index 77a2ff0..540c19a 100644
--- a/core/modules/system/lib/Drupal/system/Tests/File/FileTestBase.php
+++ b/core/modules/system/lib/Drupal/system/Tests/File/FileTestBase.php
@@ -7,6 +7,7 @@
namespace Drupal\system\Tests\File;
+use Drupal\file\FileInterface;
use Drupal\simpletest\WebTestBase;
/**
@@ -29,45 +30,45 @@ abstract class FileTestBase extends WebTestBase {
* Check that two files have the same values for all fields other than the
* timestamp.
*
- * @param $before
+ * @param \Drupal\file\FileInterface $before
* File object to compare.
- * @param $after
+ * @param \Drupal\file\FileInterface $after
* File object to compare.
*/
- function assertFileUnchanged($before, $after) {
- $this->assertEqual($before->fid, $after->fid, t('File id is the same: %file1 == %file2.', array('%file1' => $before->fid, '%file2' => $after->fid)), 'File unchanged');
- $this->assertEqual($before->uid, $after->uid, t('File owner is the same: %file1 == %file2.', array('%file1' => $before->uid, '%file2' => $after->uid)), 'File unchanged');
- $this->assertEqual($before->filename, $after->filename, t('File name is the same: %file1 == %file2.', array('%file1' => $before->filename, '%file2' => $after->filename)), 'File unchanged');
- $this->assertEqual($before->uri, $after->uri, t('File path is the same: %file1 == %file2.', array('%file1' => $before->uri, '%file2' => $after->uri)), 'File unchanged');
- $this->assertEqual($before->filemime, $after->filemime, t('File MIME type is the same: %file1 == %file2.', array('%file1' => $before->filemime, '%file2' => $after->filemime)), 'File unchanged');
- $this->assertEqual($before->filesize, $after->filesize, t('File size is the same: %file1 == %file2.', array('%file1' => $before->filesize, '%file2' => $after->filesize)), 'File unchanged');
- $this->assertEqual($before->status, $after->status, t('File status is the same: %file1 == %file2.', array('%file1' => $before->status, '%file2' => $after->status)), 'File unchanged');
+ function assertFileUnchanged(FileInterface $before, FileInterface $after) {
+ $this->assertEqual($before->id(), $after->id(), t('File id is the same: %file1 == %file2.', array('%file1' => $before->id(), '%file2' => $after->id())), 'File unchanged');
+ $this->assertEqual($before->getOwner()->id(), $after->getOwner()->id(), t('File owner is the same: %file1 == %file2.', array('%file1' => $before->getOwner()->id(), '%file2' => $after->getOwner()->id())), 'File unchanged');
+ $this->assertEqual($before->getFilename(), $after->getFilename(), t('File name is the same: %file1 == %file2.', array('%file1' => $before->getFilename(), '%file2' => $after->getFilename())), 'File unchanged');
+ $this->assertEqual($before->getFileUri(), $after->getFileUri(), t('File path is the same: %file1 == %file2.', array('%file1' => $before->getFileUri(), '%file2' => $after->getFileUri())), 'File unchanged');
+ $this->assertEqual($before->getMimeType(), $after->getMimeType(), t('File MIME type is the same: %file1 == %file2.', array('%file1' => $before->getMimeType(), '%file2' => $after->getMimeType())), 'File unchanged');
+ $this->assertEqual($before->getSize(), $after->getSize(), t('File size is the same: %file1 == %file2.', array('%file1' => $before->getSize(), '%file2' => $after->getSize())), 'File unchanged');
+ $this->assertEqual($before->isPermanent(), $after->isPermanent(), t('File status is the same: %file1 == %file2.', array('%file1' => $before->isPermanent(), '%file2' => $after->isPermanent())), 'File unchanged');
}
/**
* Check that two files are not the same by comparing the fid and filepath.
*
- * @param $file1
+ * @param \Drupal\file\FileInterface $file1
* File object to compare.
- * @param $file2
+ * @param \Drupal\file\FileInterface $file2
* File object to compare.
*/
- function assertDifferentFile($file1, $file2) {
- $this->assertNotEqual($file1->fid, $file2->fid, t('Files have different ids: %file1 != %file2.', array('%file1' => $file1->fid, '%file2' => $file2->fid)), 'Different file');
- $this->assertNotEqual($file1->uri, $file2->uri, t('Files have different paths: %file1 != %file2.', array('%file1' => $file1->uri, '%file2' => $file2->uri)), 'Different file');
+ function assertDifferentFile(FileInterface $file1, FileInterface $file2) {
+ $this->assertNotEqual($file1->id(), $file2->id(), t('Files have different ids: %file1 != %file2.', array('%file1' => $file1->id(), '%file2' => $file2->id())), 'Different file');
+ $this->assertNotEqual($file1->getFileUri(), $file2->getFileUri(), t('Files have different paths: %file1 != %file2.', array('%file1' => $file1->getFileUri(), '%file2' => $file2->getFileUri())), 'Different file');
}
/**
* Check that two files are the same by comparing the fid and filepath.
*
- * @param $file1
+ * @param \Drupal\file\FileInterface $file1
* File object to compare.
- * @param $file2
+ * @param \Drupal\file\FileInterface $file2
* File object to compare.
*/
- function assertSameFile($file1, $file2) {
- $this->assertEqual($file1->fid, $file2->fid, t('Files have the same ids: %file1 == %file2.', array('%file1' => $file1->fid, '%file2-fid' => $file2->fid)), 'Same file');
- $this->assertEqual($file1->uri, $file2->uri, t('Files have the same path: %file1 == %file2.', array('%file1' => $file1->uri, '%file2' => $file2->uri)), 'Same file');
+ function assertSameFile(FileInterface $file1, FileInterface $file2) {
+ $this->assertEqual($file1->id(), $file2->id(), t('Files have the same ids: %file1 == %file2.', array('%file1' => $file1->id(), '%file2-fid' => $file2->id())), 'Same file');
+ $this->assertEqual($file1->getFileUri(), $file2->getFileUri(), t('Files have the same path: %file1 == %file2.', array('%file1' => $file1->getFileUri(), '%file2' => $file2->getFileUri())), 'Same file');
}
/**
diff --git a/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php b/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php
index 28c5d5a..fca6f88 100644
--- a/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php
@@ -215,17 +215,17 @@ class TypedDataTest extends DrupalUnitTestBase {
$this->assertEqual($typed_data->validate()->count(), 1, 'Validation detected invalid value.');
// Binary type.
- $typed_data = $this->createTypedData(array('type' => 'binary'), $files[0]->uri);
+ $typed_data = $this->createTypedData(array('type' => 'binary'), $files[0]->getFileUri());
$this->assertTrue(is_resource($typed_data->getValue()), 'Binary value was fetched.');
$this->assertEqual($typed_data->validate()->count(), 0);
// Try setting by URI.
- $typed_data->setValue($files[1]->uri);
- $this->assertEqual(is_resource($typed_data->getValue()), fopen($files[1]->uri, 'r'), 'Binary value was changed.');
+ $typed_data->setValue($files[1]->getFileUri());
+ $this->assertEqual(is_resource($typed_data->getValue()), fopen($files[1]->getFileUri(), 'r'), 'Binary value was changed.');
$this->assertTrue(is_string($typed_data->getString()), 'Binary value was converted to string');
$this->assertEqual($typed_data->validate()->count(), 0);
// Try setting by resource.
- $typed_data->setValue(fopen($files[2]->uri, 'r'));
- $this->assertEqual(is_resource($typed_data->getValue()), fopen($files[2]->uri, 'r'), 'Binary value was changed.');
+ $typed_data->setValue(fopen($files[2]->getFileUri(), 'r'));
+ $this->assertEqual(is_resource($typed_data->getValue()), fopen($files[2]->getFileUri(), 'r'), 'Binary value was changed.');
$this->assertTrue(is_string($typed_data->getString()), 'Binary value was converted to string');
$this->assertEqual($typed_data->validate()->count(), 0);
$typed_data->setValue(NULL);
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 c85f5e4..376f1e9 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php
@@ -44,11 +44,11 @@ class UserPictureUpgradePathTest extends UpgradePathTestBase {
$instance = field_info_instance('user', 'user_picture', 'user');
$file = entity_load('file', $instance['settings']['default_image'][0]);
$this->assertIdentical($instance['settings']['default_image'][0], $file->id(), 'Default user picture has been migrated.');
- $this->assertEqual($file->uri, 'public://user_pictures_dir/druplicon.png', 'File id matches the uri expected.');
- $this->assertEqual($file->filename, 'druplicon.png');
- $this->assertEqual($file->langcode, Language::LANGCODE_NOT_SPECIFIED);
- $this->assertEqual($file->filemime, 'image/png');
- $this->assertFalse(empty($file->uuid));
+ $this->assertEqual($file->getFileUri(), 'public://user_pictures_dir/druplicon.png', 'File id matches the uri expected.');
+ $this->assertEqual($file->getFilename(), 'druplicon.png');
+ $this->assertEqual($file->langcode->value, Language::LANGCODE_NOT_SPECIFIED);
+ $this->assertEqual($file->getMimeType(), 'image/png');
+ $this->assertFalse(empty($file->uuid->value));
// Check file usage for the default image.
$usage = file_usage()->listUsage($file);
@@ -70,7 +70,7 @@ class UserPictureUpgradePathTest extends UpgradePathTestBase {
// Check the user picture and file usage record.
$user = user_load(1);
$file = file_load($user->user_picture[Language::LANGCODE_NOT_SPECIFIED][0]['fid']);
- $this->assertEqual('public://user_pictures_dir/faked_image.png', $file->uri);
+ $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/system/system.admin.inc b/core/modules/system/system.admin.inc
index 6d3a89b..1cfea0c 100644
--- a/core/modules/system/system.admin.inc
+++ b/core/modules/system/system.admin.inc
@@ -651,14 +651,14 @@ function system_theme_settings_submit($form, &$form_state) {
if (module_exists('file')) {
if ($file = $values['logo_upload']) {
unset($values['logo_upload']);
- $filename = file_unmanaged_copy($file->uri);
+ $filename = file_unmanaged_copy($file->getFileUri());
$values['default_logo'] = 0;
$values['logo_path'] = $filename;
$values['toggle_logo'] = 1;
}
if ($file = $values['favicon_upload']) {
unset($values['favicon_upload']);
- $filename = file_unmanaged_copy($file->uri);
+ $filename = file_unmanaged_copy($file->getFileUri());
$values['default_favicon'] = 0;
$values['favicon_path'] = $filename;
$values['toggle_favicon'] = 1;
diff --git a/core/modules/system/system.tokens.inc b/core/modules/system/system.tokens.inc
index 241ed54..8cb1d7b 100644
--- a/core/modules/system/system.tokens.inc
+++ b/core/modules/system/system.tokens.inc
@@ -221,49 +221,48 @@ function system_tokens($type, $tokens, array $data = array(), array $options = a
switch ($name) {
// Basic keys and values.
case 'fid':
- $replacements[$original] = $file->fid;
+ $replacements[$original] = $file->id();
break;
// Essential file data
case 'name':
- $replacements[$original] = $sanitize ? check_plain($file->filename) : $file->filename;
+ $replacements[$original] = $sanitize ? check_plain($file->getFilename()) : $file->getFilename();
break;
case 'path':
- $replacements[$original] = $sanitize ? check_plain($file->uri) : $file->uri;
+ $replacements[$original] = $sanitize ? check_plain($file->getFileUri()) : $file->getFileUri();
break;
case 'mime':
- $replacements[$original] = $sanitize ? check_plain($file->filemime) : $file->filemime;
+ $replacements[$original] = $sanitize ? check_plain($file->getMimeType()) : $file->getMimeType();
break;
case 'size':
- $replacements[$original] = format_size($file->filesize);
+ $replacements[$original] = format_size($file->getSize());
break;
case 'url':
- $replacements[$original] = $sanitize ? check_plain(file_create_url($file->uri)) : file_create_url($file->uri);
+ $replacements[$original] = $sanitize ? check_plain(file_create_url($file->getFileUri())) : file_create_url($file->getFileUri());
break;
// These tokens are default variations on the chained tokens handled below.
case 'timestamp':
- $replacements[$original] = format_date($file->timestamp, 'medium', '', NULL, $langcode);
+ $replacements[$original] = format_date($file->getChangedTime(), 'medium', '', NULL, $langcode);
break;
case 'owner':
- $account = user_load($file->uid);
- $name = user_format_name($account);
+ $name = $file->getOwner()->label();
$replacements[$original] = $sanitize ? check_plain($name) : $name;
break;
}
}
if ($date_tokens = $token_service->findWithPrefix($tokens, 'timestamp')) {
- $replacements += $token_service->generate('date', $date_tokens, array('date' => $file->timestamp), $options);
+ $replacements += $token_service->generate('date', $date_tokens, array('date' => $file->getChangedTime()), $options);
}
- if (($owner_tokens = $token_service->findWithPrefix($tokens, 'owner')) && $account = user_load($file->uid)) {
- $replacements += $token_service->generate('user', $owner_tokens, array('user' => $account), $options);
+ if (($owner_tokens = $token_service->findWithPrefix($tokens, 'owner')) && $file->getOwner()) {
+ $replacements += $token_service->generate('user', $owner_tokens, array('user' => $file->getOwner()), $options);
}
}
diff --git a/core/modules/update/update.manager.inc b/core/modules/update/update.manager.inc
index c7502a2..bc73db0 100644
--- a/core/modules/update/update.manager.inc
+++ b/core/modules/update/update.manager.inc
@@ -650,7 +650,7 @@ function update_manager_install_form_submit($form, &$form_state) {
// failure.
return;
}
- $local_cache = $finfo->uri;
+ $local_cache = $finfo->getFileUri();
}
$directory = _update_manager_extract_directory();
diff --git a/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php b/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php
index a07006f..633e0cf 100644
--- a/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php
+++ b/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php
@@ -61,7 +61,7 @@ class UserPictureTest extends WebTestBase {
// Verify that the image is displayed on the user account page.
$this->drupalGet('user');
- $this->assertRaw(file_uri_target($file->uri), 'User picture found on user account page.');
+ $this->assertRaw(file_uri_target($file->getFileUri()), 'User picture found on user account page.');
// Delete the picture.
$edit = array();
@@ -74,15 +74,15 @@ class UserPictureTest extends WebTestBase {
->fields(array(
'timestamp' => REQUEST_TIME - (DRUPAL_MAXIMUM_TEMP_FILE_AGE + 1),
))
- ->condition('fid', $file->fid)
+ ->condition('fid', $file->id())
->execute();
drupal_cron_run();
// Verify that the image has been deleted.
- $this->assertFalse(file_load($file->fid, TRUE), 'File was removed from the database.');
+ $this->assertFalse(file_load($file->id(), TRUE), 'File was removed from the database.');
// Clear out PHP's file stat cache so we see the current value.
- clearstatcache(TRUE, $file->uri);
- $this->assertFalse(is_file($file->uri), 'File was removed from the file system.');
+ clearstatcache(TRUE, $file->getFileUri());
+ $this->assertFalse(is_file($file->getFileUri()), 'File was removed from the file system.');
}
/**
@@ -102,7 +102,7 @@ class UserPictureTest extends WebTestBase {
// Verify that the image is displayed on the user account page.
$this->drupalGet('node/' . $node->nid);
- $this->assertRaw(file_uri_target($file->uri), 'User picture found on node page.');
+ $this->assertRaw(file_uri_target($file->getFileUri()), 'User picture found on node page.');
// Enable user pictures on comments, instead of nodes.
$this->container->get('config.factory')->get('system.theme.global')
@@ -114,7 +114,7 @@ class UserPictureTest extends WebTestBase {
'comment_body[' . Language::LANGCODE_NOT_SPECIFIED . '][0][value]' => $this->randomString(),
);
$this->drupalPost('comment/reply/' . $node->nid, $edit, t('Save'));
- $this->assertRaw(file_uri_target($file->uri), 'User picture found on comment.');
+ $this->assertRaw(file_uri_target($file->getFileUri()), 'User picture found on comment.');
// Disable user pictures on comments and nodes.
$this->container->get('config.factory')->get('system.theme.global')
@@ -123,7 +123,7 @@ class UserPictureTest extends WebTestBase {
->save();
$this->drupalGet('node/' . $node->nid);
- $this->assertNoRaw(file_uri_target($file->uri), 'User picture not found on node and comment.');
+ $this->assertNoRaw(file_uri_target($file->getFileUri()), 'User picture not found on node and comment.');
}
/**