From 3400bc2cb5cdcb7cf0a4923fa6f4ee632649d10e Mon Sep 17 00:00:00 2001 From: catch Date: Wed, 29 Aug 2012 11:17:27 +0100 Subject: [PATCH] Issue #1734716 by larowlan: Fixed File field form label has incorrect id in @for attribute. --- core/modules/file/file.module | 3 +++ .../modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/core/modules/file/file.module b/core/modules/file/file.module index d2f6f76f294a..32bbce99e38e 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -370,6 +370,9 @@ function file_file_predelete(File $file) { * This function is assigned as a #process callback in file_element_info(). */ function file_managed_file_process($element, &$form_state, $form) { + // Append the '-upload' to the #id so the field label's 'for' attribute + // corresponds with the file element. + $element['#id'] .= '-upload'; $fid = isset($element['#value']['fid']) ? $element['#value']['fid'] : 0; // Set some default element properties. diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php index 4f93ce01036f..0bb8866eaf83 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php @@ -68,6 +68,9 @@ class FileFieldWidgetTest extends FileFieldTestBase { // Ensure the page now has an upload button instead of a remove button. $this->assertNoFieldByXPath('//input[@type="submit"]', t('Remove'), t('After clicking the "Remove" button, it is no longer displayed.')); $this->assertFieldByXpath('//input[@type="submit"]', t('Upload'), t('After clicking the "Remove" button, the "Upload" button is displayed.')); + // Test label has correct 'for' attribute. + $label = $this->xpath("//label[@for='edit-" . drupal_clean_css_identifier($field_name) . "-" . LANGUAGE_NOT_SPECIFIED . "-0-upload']"); + $this->assertTrue(isset($label[0]), 'Label for upload found.'); // Save the node and ensure it does not have the file. $this->drupalPost(NULL, array(), t('Save'));