X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Ffile%2Fsrc%2FElement%2FManagedFile.php;fp=web%2Fcore%2Fmodules%2Ffile%2Fsrc%2FElement%2FManagedFile.php;h=ca4e887a1b3fd193006cd2eb657a8fceacf18f8f;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=45c8aa7cec53c1814415d7cb134ce7d7030b13f6;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/web/core/modules/file/src/Element/ManagedFile.php b/web/core/modules/file/src/Element/ManagedFile.php index 45c8aa7ce..ca4e887a1 100644 --- a/web/core/modules/file/src/Element/ManagedFile.php +++ b/web/core/modules/file/src/Element/ManagedFile.php @@ -398,15 +398,23 @@ class ManagedFile extends FormElement { * Render API callback: Validates the managed_file element. */ public static function validateManagedFile(&$element, FormStateInterface $form_state, &$complete_form) { - // If referencing an existing file, only allow if there are existing - // references. This prevents unmanaged files from being deleted if this - // item were to be deleted. $clicked_button = end($form_state->getTriggeringElement()['#parents']); if ($clicked_button != 'remove_button' && !empty($element['fids']['#value'])) { $fids = $element['fids']['#value']; foreach ($fids as $fid) { if ($file = File::load($fid)) { - if ($file->isPermanent()) { + // If referencing an existing file, only allow if there are existing + // references. This prevents unmanaged files from being deleted if + // this item were to be deleted. When files that are no longer in use + // are automatically marked as temporary (now disabled by default), + // it is not safe to reference a permanent file without usage. Adding + // a usage and then later on removing it again would delete the file, + // but it is unknown if and where it is currently referenced. However, + // when files are not marked temporary (and then removed) + // automatically, it is safe to add and remove usages, as it would + // simply return to the current state. + // @see https://www.drupal.org/node/2891902 + if ($file->isPermanent() && \Drupal::config('file.settings')->get('make_unused_managed_files_temporary')) { $references = static::fileUsage()->listUsage($file); if (empty($references)) { // We expect the field name placeholder value to be wrapped in t()