diff --git a/core/lib/Drupal/Component/Utility/Html.php b/core/lib/Drupal/Component/Utility/Html.php index b10f203..659cb27 100644 --- a/core/lib/Drupal/Component/Utility/Html.php +++ b/core/lib/Drupal/Component/Utility/Html.php @@ -144,7 +144,7 @@ public static function getUniqueId($id) { // will be merged with content already on the base page. The HTML IDs must // be unique for the fully merged content. Therefore use unique IDs. if (static::$isAjax) { - return static::getId($id) . '--' . uniqid(); + return static::getId($id) . '--' . Crypt::randomBytesBase64(8); } // seenIdsInit is only useful for tests anymore. diff --git a/core/misc/ajax.js b/core/misc/ajax.js index 8f2b8cd..76ee918 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -379,7 +379,7 @@ /** * Request parameter to indicate that a request is a drupal ajax request. */ - DRupal.ajax.AJAX_REQUEST_PARAMETER = '_drupal_ajax'; + Drupal.ajax.AJAX_REQUEST_PARAMETER = '_drupal_ajax'; /** * Execute the ajax request. diff --git a/core/modules/file/src/Element/ManagedFile.php b/core/modules/file/src/Element/ManagedFile.php index 40d0c31..740791c 100644 --- a/core/modules/file/src/Element/ManagedFile.php +++ b/core/modules/file/src/Element/ManagedFile.php @@ -7,6 +7,7 @@ namespace Drupal\file\Element; +use Drupal\Component\Utility\Html; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element\FormElement; use Drupal\Core\Url; @@ -130,9 +131,6 @@ public static function valueCallback(&$element, $input, FormStateInterface $form * support for a default value. */ public static function processManagedFile(&$element, FormStateInterface $form_state, &$complete_form) { - // Append the '-upload' to the #id so the field label's 'for' attribute - // corresponds with the file element. - $element['#id'] .= '-upload'; // This is used sometimes so let's implode it just once. $parents_prefix = implode('_', $element['#parents']); @@ -144,6 +142,9 @@ public static function processManagedFile(&$element, FormStateInterface $form_st $element['#files'] = !empty($fids) ? File::loadMultiple($fids) : FALSE; $element['#tree'] = TRUE; + // Generate a wrapper html ID. All we need is that its unique. + $ajax_wrapper_id = Html::getUniqueId('ajax-wrapper'); + $ajax_settings = [ 'url' => Url::fromRoute('file.ajax_upload'), 'options' => [ @@ -152,7 +153,7 @@ public static function processManagedFile(&$element, FormStateInterface $form_st 'form_build_id' => $complete_form['form_build_id']['#value'], ], ], - 'wrapper' => $element['#id'] . '-ajax-wrapper', + 'wrapper' => $ajax_wrapper_id, 'effect' => 'fade', 'progress' => [ 'type' => $element['#progress_indicator'], @@ -259,8 +260,12 @@ public static function processManagedFile(&$element, FormStateInterface $form_st $element['upload']['#attached']['drupalSettings']['file']['elements']['#' . $element['#id']] = $extension_list; } + // Let #id point of the file element, so the field label's 'for' corresponds + // with it. + $element['#id'] = &$element['upload']['#id']; + // Prefix and suffix used for Ajax replacement. - $element['#prefix'] = '