Commit 7d4962b5 authored by catch's avatar catch

Issue #1414510 by Spleshka, andypost, tim.plunkett: Fixed Remove...

Issue #1414510 by Spleshka, andypost, tim.plunkett: Fixed Remove drupal_reset_static() for drupal_html_id() when form validation fails.
parent ee2c99b0
......@@ -869,7 +869,10 @@ function drupal_process_form($form_id, &$form, &$form_state) {
// cache when a form is processed, so scenarios that result in
// the form being built behind the scenes and again for the
// browser don't increment all the element IDs needlessly.
drupal_static_reset('drupal_html_id');
if (!form_get_errors()) {
// In case of errors, do not break HTML IDs of other forms.
drupal_static_reset('drupal_html_id');
}
if ($form_state['submitted'] && !form_get_errors() && !$form_state['rebuild']) {
// Execute form submit handlers.
......
<?php
/**
* @file
* Definition of Drupal\system\Tests\Form\HTMLIdTest.
*/
namespace Drupal\system\Tests\Form;
use Drupal\simpletest\WebTestBase;
/**
* Tests uniqueness of generated HTML IDs.
*/
class HTMLIdTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('form_test');
public static function getInfo() {
return array(
'name' => 'Unique HTML IDs',
'description' => 'Tests functionality of drupal_html_id().',
'group' => 'Form API',
);
}
/**
* Tests that HTML IDs do not get duplicated when form validation fails.
*/
function testHTMLId() {
$this->drupalGet('form-test/double-form');
$this->assertNoDuplicateIds('There are no duplicate IDs');
// Submit second form with empty title.
$edit = array();
$this->drupalPost(NULL, $edit, 'Save', array(), array(), 'form-test-html-id--2');
$this->assertNoDuplicateIds('There are no duplicate IDs');
}
}
......@@ -261,6 +261,12 @@ function form_test_menu() {
'type' => MENU_CALLBACK,
);
}
$items['form-test/double-form'] = array(
'title' => 'Double form test',
'page callback' => 'form_test_double_form',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['form-test/load-include-menu'] = array(
'title' => 'FAPI test loading includes',
......@@ -2252,3 +2258,29 @@ function form_test_required_attribute($form, &$form_state) {
return $form;
}
/**
* Menu callback returns two instances of the same form.
*/
function form_test_double_form() {
return array(
'form1' => drupal_get_form('form_test_html_id'),
'form2' => drupal_get_form('form_test_html_id'),
);
}
/**
* Builds a simple form to test duplicate HTML IDs.
*/
function form_test_html_id($form, &$form_state) {
$form['name'] = array(
'#type' => 'textfield',
'#title' => 'name',
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Save',
);
return $form;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment