diff --git a/core/includes/file.inc b/core/includes/file.inc index 067aaee1aa..b4949a9107 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -13,7 +13,6 @@ use Drupal\Core\Site\Settings; use Drupal\Core\StreamWrapper\PublicStream; use Drupal\Core\StreamWrapper\PrivateStream; -use Drupal\file\FileInterface; /** * Default mode for new directories. See drupal_chmod(). @@ -77,7 +76,7 @@ * @deprecated in Drupal 8.7.0, will be removed before Drupal 9.0.0. * Use \Drupal\file\FileInterface::STATUS_PERMANENT instead. * - * @see https://www.drupal.org/project/drupal/issues/3021833 + * @see https://www.drupal.org/node/3022147 */ const FILE_STATUS_PERMANENT = 1; diff --git a/core/modules/editor/editor.module b/core/modules/editor/editor.module index f1c18a1fab..754d4774ba 100644 --- a/core/modules/editor/editor.module +++ b/core/modules/editor/editor.module @@ -430,8 +430,7 @@ function editor_entity_revision_delete(EntityInterface $entity) { /** * Records file usage of files referenced by formatted text fields. * - * Every referenced file that does not yet have the - * \Drupal\file\FileInterface::STATUS_PERMANENT state, will be given that state. + * Every referenced file that is temporally saved will be resaved as permanent. * * @param array $uuids * An array of file entity UUIDs. @@ -441,8 +440,9 @@ function editor_entity_revision_delete(EntityInterface $entity) { function _editor_record_file_usage(array $uuids, EntityInterface $entity) { foreach ($uuids as $uuid) { if ($file = \Drupal::entityManager()->loadEntityByUuid('file', $uuid)) { - if ($file->status !== FileInterface::STATUS_PERMANENT) { - $file->status = FileInterface::STATUS_PERMANENT; + /** @var \Drupal\file\FileInterface $file */ + if ($file->isTemporary()) { + $file->setPermanent(); $file->save(); } \Drupal::service('file.usage')->add($file, 'editor', $entity->getEntityTypeId(), $entity->id()); diff --git a/core/modules/file/tests/src/Functional/Rest/FileResourceTestBase.php b/core/modules/file/tests/src/Functional/Rest/FileResourceTestBase.php index 78055988d8..17ba59b986 100644 --- a/core/modules/file/tests/src/Functional/Rest/FileResourceTestBase.php +++ b/core/modules/file/tests/src/Functional/Rest/FileResourceTestBase.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\file\Functional\Rest; use Drupal\file\Entity\File; -use Drupal\file\FileInterface; use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait; use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase; use Drupal\user\Entity\User; @@ -96,7 +95,7 @@ protected function createEntity() { $file->setFilename('drupal.txt'); $file->setMimeType('text/plain'); $file->setFileUri('public://drupal.txt'); - $file->set('status', FileInterface::STATUS_PERMANENT); + $file->setPermanent(); $file->save(); file_put_contents($file->getFileUri(), 'Drupal'); diff --git a/core/modules/image/image.module b/core/modules/image/image.module index e790445bcc..e877b1dcd5 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -420,7 +420,7 @@ function image_field_storage_config_update(FieldStorageConfigInterface $field_st // Is there a new file? if ($file_new) { - $file_new->status = FileInterface::STATUS_PERMANENT; + $file_new->setPermanent(); $file_new->save(); \Drupal::service('file.usage')->add($file_new, 'image', 'default_image', $field_storage->uuid()); } @@ -459,7 +459,7 @@ function image_field_config_update(FieldConfigInterface $field) { if ($uuid_new != $uuid_old) { // Save the new file, if present. if ($file_new) { - $file_new->status = FileInterface::STATUS_PERMANENT; + $file_new->setPermanent(); $file_new->save(); \Drupal::service('file.usage')->add($file_new, 'image', 'default_image', $field->uuid()); }