From 55d9324fa26942fc093e35b1f1295f40852f7a14 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 3 Jan 2025 13:26:35 +1000
Subject: [PATCH] Issue #3495733 by deepali sardana, idebr, knyshuk.vova:
 ManagedFile #accept overwrites existing attributes

---
 core/modules/file/src/Element/ManagedFile.php                  | 2 +-
 .../image/tests/src/Functional/ImageFieldWidgetTest.php        | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/core/modules/file/src/Element/ManagedFile.php b/core/modules/file/src/Element/ManagedFile.php
index 7b80af79ebfb..8abd25101478 100644
--- a/core/modules/file/src/Element/ManagedFile.php
+++ b/core/modules/file/src/Element/ManagedFile.php
@@ -326,7 +326,7 @@ public static function processManagedFile(&$element, FormStateInterface $form_st
     }
 
     if (!empty($element['#accept'])) {
-      $element['upload']['#attributes'] = ['accept' => $element['#accept']];
+      $element['upload']['#attributes']['accept'] = $element['#accept'];
     }
 
     // Indicate that $element['#title'] should be used as the HTML label for the
diff --git a/core/modules/image/tests/src/Functional/ImageFieldWidgetTest.php b/core/modules/image/tests/src/Functional/ImageFieldWidgetTest.php
index 2bf7c652ea49..dd2e6929a97b 100644
--- a/core/modules/image/tests/src/Functional/ImageFieldWidgetTest.php
+++ b/core/modules/image/tests/src/Functional/ImageFieldWidgetTest.php
@@ -27,6 +27,7 @@ public function testWidgetElement(): void {
     $min_resolution = 50;
     $max_resolution = 100;
     $field_settings = [
+      'description' => 'test description',
       'max_resolution' => $max_resolution . 'x' . $max_resolution,
       'min_resolution' => $min_resolution . 'x' . $min_resolution,
       'alt_field' => 0,
@@ -36,7 +37,7 @@ public function testWidgetElement(): void {
     // Verify that the image field widget is found on add/node page.
     $this->assertSession()->elementExists('xpath', '//div[contains(@class, "field--widget-image-image")]');
     // Verify that the image field widget limits accepted files.
-    $this->assertSession()->elementExists('xpath', '//input[contains(@accept, "image/*")]');
+    $this->assertSession()->elementExists('xpath', '//input[@aria-describedby][contains(@accept, "image/*")]');
     $this->assertSession()->pageTextNotContains('Image test on [site:name]');
 
     // Check for allowed image file extensions - default.
-- 
GitLab