Commit a2defc66 authored by jhodgdon's avatar jhodgdon

Revert "Issue #2407361 by JeroenT, cilefen, hussainweb: Move usages of...

Revert "Issue #2407361 by JeroenT, cilefen, hussainweb: Move usages of drupal_html_id() to Html::getUniqueId()"

This reverts commit 85b8c837.
parent 85b8c837
......@@ -1653,7 +1653,7 @@ function template_preprocess_field_multiple_value_form(&$variables) {
$variables['multiple'] = $element['#cardinality_multiple'];
if ($variables['multiple']) {
$table_id = Html::getUniqueId($element['#field_name'] . '_values');
$table_id = drupal_html_id($element['#field_name'] . '_values');
$order_class = $element['#field_name'] . '-delta-order';
$header_attributes = new Attribute(array('class' => array('label')));
if (!empty($element['#required'])) {
......
......@@ -217,7 +217,7 @@ protected function formMultipleElements(FieldItemListInterface $items, array &$f
// Add 'add more' button, if not working with a programmed form.
if ($cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED && !$form_state->isProgrammed()) {
$id_prefix = implode('-', array_merge($parents, array($field_name)));
$wrapper_id = Html::getUniqueId($id_prefix . '-add-more-wrapper');
$wrapper_id = drupal_html_id($id_prefix . '-add-more-wrapper');
$elements['#prefix'] = '<div id="' . $wrapper_id . '">';
$elements['#suffix'] = '</div>';
......
......@@ -467,11 +467,11 @@ public function processForm($form_id, &$form, FormStateInterface &$form_state) {
}
$this->formValidator->validateForm($form_id, $form, $form_state);
// \Drupal\Component\Utility\Html::getUniqueId() maintains a cache of
// element IDs it has seen, so it can prevent duplicates. We want to be
// sure we reset that 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_html_id() maintains a cache of element IDs it has seen, so it
// can prevent duplicates. We want to be sure we reset that 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.
if (!FormState::hasAnyErrors()) {
// In case of errors, do not break HTML IDs of other forms.
Html::resetSeenIds();
......
......@@ -7,7 +7,6 @@
namespace Drupal\Core\Render\Element;
use Drupal\Component\Utility\Html;
use Drupal\Core\Form\FormStateInterface;
/**
......@@ -54,7 +53,7 @@ public function getInfo() {
public static function processContainer(&$element, FormStateInterface $form_state, &$complete_form) {
// Generate the ID of the element if it's not explicitly given.
if (!isset($element['#id'])) {
$element['#id'] = Html::getUniqueId(implode('-', $element['#parents']) . '-wrapper');
$element['#id'] = drupal_html_id(implode('-', $element['#parents']) . '-wrapper');
}
return $element;
}
......
......@@ -8,7 +8,6 @@
namespace Drupal\Core\Render\Element;
use Drupal\Component\Utility\NestedArray;
use Drupal\Component\Utility\Html;
/**
* Provides a link render element.
......@@ -70,7 +69,7 @@ public static function preRenderLink($element) {
if (isset($element['#ajax']) && !isset($element['#ajax_processed'])) {
// If no HTML ID was found above, automatically create one.
if (!isset($element['#id'])) {
$element['#id'] = $element['#options']['attributes']['id'] = Html::getUniqueId('ajax-link');
$element['#id'] = $element['#options']['attributes']['id'] = drupal_html_id('ajax-link');
}
$element = static::preRenderAjaxForm($element);
}
......
......@@ -8,7 +8,6 @@
namespace Drupal\Core\Render\Element;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Utility\Html;
/**
* Provides a form element for a set of radio buttons.
......@@ -66,7 +65,7 @@ public static function processRadios(&$element, FormStateInterface $form_state,
'#default_value' => isset($element['#default_value']) ? $element['#default_value'] : FALSE,
'#attributes' => $element['#attributes'],
'#parents' => $element['#parents'],
'#id' => Html::getUniqueId('edit-' . implode('-', $parents_for_id)),
'#id' => drupal_html_id('edit-' . implode('-', $parents_for_id)),
'#ajax' => isset($element['#ajax']) ? $element['#ajax'] : NULL,
'#weight' => $weight,
);
......
......@@ -9,7 +9,6 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Component\Utility\Html;
/**
* Provides a render element for a table.
......@@ -132,10 +131,9 @@ public static function processTable(&$element, FormStateInterface $form_state, &
// Since the #parents of the tableselect form element will equal the
// #parents of the row element, prevent FormBuilder from auto-generating
// an #id for the row element, since
// \Drupal\Component\Utility\Html::getUniqueId() would automatically
// an #id for the row element, since drupal_html_id() would automatically
// append a suffix to the tableselect form element's #id otherwise.
$row['#id'] = Html::getUniqueId('edit-' . implode('-', $element_parents) . '-row');
$row['#id'] = drupal_html_id('edit-' . implode('-', $element_parents) . '-row');
// Do not overwrite manually created children.
if (!isset($row['select'])) {
......@@ -173,7 +171,7 @@ public static function processTable(&$element, FormStateInterface $form_state, &
$row = array('select' => array()) + $row;
$row['select'] += array(
'#type' => $element['#multiple'] ? 'checkbox' : 'radio',
'#id' => Html::getUniqueId('edit-' . implode('-', $element_parents)),
'#id' => drupal_html_id('edit-' . implode('-', $element_parents)),
// @todo If rows happen to use numeric indexes instead of string keys,
// this results in a first row with $key === 0, which is always FALSE.
'#return_value' => $key,
......
......@@ -9,7 +9,6 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Component\Utility\Html;
/**
* Provides a form element for a table with radios or checkboxes in left column.
......@@ -237,7 +236,7 @@ public static function processTableselect(&$element, FormStateInterface $form_st
'#default_value' => ($element['#default_value'] == $key) ? $key : NULL,
'#attributes' => $element['#attributes'],
'#parents' => $element['#parents'],
'#id' => Html::getUniqueId('edit-' . implode('-', $parents_for_id)),
'#id' => drupal_html_id('edit-' . implode('-', $parents_for_id)),
'#ajax' => isset($element['#ajax']) ? $element['#ajax'] : NULL,
);
}
......
......@@ -7,7 +7,6 @@
namespace Drupal\Core\Render\MainContent;
use Drupal\Component\Utility\Html;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\OpenDialogCommand;
use Drupal\Core\Controller\TitleResolverInterface;
......@@ -89,7 +88,7 @@ protected function determineTargetSelector(array &$options, RouteMatchInterface
else {
// Generate a target based on the route id.
$route_name = $route_match->getRouteName();
$target = '#' . Html::getUniqueId("drupal-dialog-$route_name");
$target = '#' . drupal_html_id("drupal-dialog-$route_name");
}
return $target;
}
......
......@@ -372,7 +372,7 @@
}
// Prevent duplicate HTML ids in the returned markup.
// @see \Drupal\Component\Utility\Html::getUniqueId()
// @see drupal_html_id()
var ids = document.querySelectorAll('[id]');
var ajaxHtmlIds = [];
for (var i = 0, il = ids.length; i < il; i++) {
......
......@@ -6,7 +6,6 @@
*/
use Drupal\block\BlockInterface;
use Drupal\Component\Utility\Html;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\language\ConfigurableLanguageInterface;
......@@ -247,12 +246,12 @@ function template_preprocess_block(&$variables) {
// Create a valid HTML ID and make sure it is unique.
if (!empty($variables['elements']['#id'])) {
$variables['attributes']['id'] = Html::getUniqueId('block-' . $variables['elements']['#id']);
$variables['attributes']['id'] = drupal_html_id('block-' . $variables['elements']['#id']);
}
// Proactively add aria-describedby if possible to improve accessibility.
if ($variables['label'] && isset($variables['attributes']['role'])) {
$variables['title_attributes']['id'] = Html::getUniqueId($variables['label']);
$variables['title_attributes']['id'] = drupal_html_id($variables['label']);
$variables['attributes']['aria-describedby'] = $variables['title_attributes']['id'];
}
......
......@@ -206,7 +206,7 @@ public function testBlockThemeSelector() {
// Set the default theme and ensure the block is placed.
$theme_settings->set('default', $theme)->save();
$this->drupalGet('');
$elements = $this->xpath('//div[@id = :id]', array(':id' => Html::getUniqueId('block-' . $block['id'])));
$elements = $this->xpath('//div[@id = :id]', array(':id' => drupal_html_id('block-' . $block['id'])));
$this->assertTrue(!empty($elements), 'The block was found.');
}
}
......
......@@ -95,7 +95,7 @@ public function testBlockCategory() {
$this->drupalPostForm(NULL, array(), t('Save'));
// Test that the blocks are listed under the correct categories.
$category_id = Html::getUniqueId('edit-category-' . String::checkPlain($category));
$category_id = drupal_html_id('edit-category-' . String::checkPlain($category));
$arguments[':id'] = $category_id;
$this->drupalGet('admin/structure/block');
$elements = $this->xpath('//details[@id=:id]//li[contains(@class, :li_class)]/a[contains(@href, :href) and text()=:text]', $arguments);
......
......@@ -8,7 +8,6 @@
namespace Drupal\comment;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Cache\Cache;
......@@ -83,7 +82,7 @@ public function form(array $form, FormStateInterface $form_state) {
$config = $this->config('user.settings');
// Use #comment-form as unique jump target, regardless of entity type.
$form['#id'] = Html::getUniqueId('comment_form');
$form['#id'] = drupal_html_id('comment_form');
$form['#theme'] = array('comment_form__' . $entity->getEntityTypeId() . '__' . $entity->bundle() . '__' . $field_name, 'comment_form');
$anonymous_contact = $field_definition->getSetting('anonymous');
......
......@@ -112,7 +112,7 @@ public function testTwigWithoutFilter() {
'message' => 'All attributes printed again.',
),
array(
'expected' => '<div id="quotes-here"><span class="gray-like-a-bunny bem__ized--top-feature" id="quotes-here">ID and class. Having the same ID twice is not valid markup but we want to make sure the filter doesn\'t use \Drupal\Component\Utility\Html::getUniqueId().</span></div>',
'expected' => '<div id="quotes-here"><span class="gray-like-a-bunny bem__ized--top-feature" id="quotes-here">ID and class. Having the same ID twice is not valid markup but we want to make sure the filter doesn\'t use drupal_html_id().</span></div>',
'message' => 'Class and ID filtered.',
),
);
......
......@@ -20,4 +20,4 @@
<div><span data-id="{{ attributes.id }}"{{ attributes|without('id') }}>Without string attribute.</span></div>
<div><span{{ attributes|without('id', 'class') }}>Without id and class attributes.</span></div>
<div><span{{ attributes }}>All attributes again.</span></div>
<div id="{{ 'quotes Here!'|clean_id }}"><span class="{{ 'Gray like a bunny!'|clean_class }} {{ 'BEM__ized--Top Feature'|clean_class }}" id="{{ 'quotes Here!'|clean_id }}">ID and class. Having the same ID twice is not valid markup but we want to make sure the filter doesn't use \Drupal\Component\Utility\Html::getUniqueId().</span></div>
<div id="{{ 'quotes Here!'|clean_id }}"><span class="{{ 'Gray like a bunny!'|clean_class }} {{ 'BEM__ized--Top Feature'|clean_class }}" id="{{ 'quotes Here!'|clean_id }}">ID and class. Having the same ID twice is not valid markup but we want to make sure the filter doesn't use drupal_html_id().</span></div>
......@@ -7,7 +7,6 @@
namespace Drupal\tour\Plugin\tour\tip;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
......@@ -79,7 +78,7 @@ public static function create(ContainerInterface $container, array $configuratio
public function getAriaId() {
static $id;
if (!isset($id)) {
$id = Html::getUniqueId($this->get('id'));
$id = drupal_html_id($this->get('id'));
}
return $id;
}
......
......@@ -113,7 +113,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#name' => '',
'#type' => 'submit',
'#value' => $this->t('Apply'),
'#id' => Html::getUniqueId('edit-submit-' . $view->storage->id()),
'#id' => drupal_html_id('edit-submit-' . $view->storage->id()),
);
$form['#action'] = $view->hasUrl() ? $view->getUrl()->toString() : Url::fromRoute('<current>')->toString();
......
......@@ -8,7 +8,6 @@
namespace Drupal\views\Plugin\views\argument;
use Drupal\Component\Plugin\DependentPluginInterface;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\NestedArray;
use Drupal\Component\Utility\String as UtilityString;
use Drupal\Core\Form\FormStateInterface;
......@@ -1096,7 +1095,7 @@ public static function processContainerRadios($element) {
'#default_value' => isset($element['#default_value']) ? $element['#default_value'] : NULL,
'#attributes' => $element['#attributes'],
'#parents' => $element['#parents'],
'#id' => Html::getUniqueId('edit-' . implode('-', $parents_for_id)),
'#id' => drupal_html_id('edit-' . implode('-', $parents_for_id)),
'#ajax' => isset($element['#ajax']) ? $element['#ajax'] : NULL,
);
$element[$key . '_options'] = array(
......
......@@ -8,7 +8,6 @@
namespace Drupal\views\Plugin\views\display;
use Drupal\Component\Plugin\DependentPluginInterface;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Cache\Cache;
......@@ -1019,7 +1018,7 @@ public function optionLink($text, $section, $class = '', $title = '') {
$title = $text;
}
return \Drupal::l($text, new Url('views_ui.form_display', ['js' => 'nojs', 'view' => $this->view->storage->id(), 'display_id' => $this->display['id'], 'type' => $section], array('attributes' => array('class' => array('views-ajax-link', $class), 'title' => $title, 'id' => Html::getUniqueId('views-' . $this->display['id'] . '-' . $section)), 'html' => TRUE)));
return \Drupal::l($text, new Url('views_ui.form_display', ['js' => 'nojs', 'view' => $this->view->storage->id(), 'display_id' => $this->display['id'], 'type' => $section], array('attributes' => array('class' => array('views-ajax-link', $class), 'title' => $title, 'id' => drupal_html_id('views-' . $this->display['id'] . '-' . $section)), 'html' => TRUE)));
}
/**
......
......@@ -8,7 +8,6 @@
namespace Drupal\views\Plugin\views\style;
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
use Drupal\Component\Utility\Html;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\wizard\WizardInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -316,7 +315,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
),
);
// Provide an ID so we can have such things.
$radio_id = Html::getUniqueId('edit-default-' . $field);
$radio_id = drupal_html_id('edit-default-' . $field);
$form['default'][$field] = array(
'#title' => $this->t('Default sort for @field', array('@field' => $field)),
'#title_display' => 'invisible',
......
......@@ -154,11 +154,11 @@ public function testExposedBlock() {
$this->drupalGet('test_exposed_block');
// Test there is an exposed form in a block.
$xpath = $this->buildXPathQuery('//div[@id=:id]/form/@id', array(':id' => Html::getUniqueId('block-' . $block->id())));
$xpath = $this->buildXPathQuery('//div[@id=:id]/form/@id', array(':id' => drupal_html_id('block-' . $block->id())));
$this->assertFieldByXpath($xpath, $this->getExpectedExposedFormId($view), 'Expected form found in views block.');
// Test there is not an exposed form in the view page content area.
$xpath = $this->buildXPathQuery('//div[@class="view-content"]/form/@id', array(':id' => Html::getUniqueId('block-' . $block->id())));
$xpath = $this->buildXPathQuery('//div[@class="view-content"]/form/@id', array(':id' => drupal_html_id('block-' . $block->id())));
$this->assertNoFieldByXpath($xpath, $this->getExpectedExposedFormId($view), 'No exposed form found in views content region.');
// Test there is only one views exposed form on the page.
......
......@@ -517,7 +517,7 @@ function template_preprocess_views_view_table(&$variables) {
$variables['header'][$field]['content'] = '<' . $element_label_type . '>' . $variables['header'][$field]['content'] . '</' . $element_label_type . '>';
}
// Improves accessibility of complex tables.
$variables['header'][$field]['attributes']['id'] = Html::getUniqueId('view-' . $field . '-table-column');
$variables['header'][$field]['attributes']['id'] = drupal_html_id('view-' . $field . '-table-column');
}
// Check if header label is not empty.
if (!empty($variables['header'][$field]['content'])) {
......
......@@ -51,12 +51,12 @@ function views_ui_add_ajax_trigger(&$wrapping_element, $trigger_key, $refresh_pa
// Add the AJAX behavior to the triggering element.
$triggering_element = &$wrapping_element[$trigger_key];
$triggering_element['#ajax']['callback'] = 'views_ui_ajax_update_form';
// We do not use \Drupal\Component\Utility\Html::getUniqueId() to get an ID
// for the AJAX wrapper, because it remembers IDs across AJAX requests (and
// won't reuse them), but in our case we need to use the same ID from request
// to request so that the wrapper can be recognized by the AJAX system and
// its content can be dynamically updated. So instead, we will keep track of
// duplicate IDs (within a single request) on our own, later in this function.
// We do not use drupal_html_id() to get an ID for the AJAX wrapper, because
// it remembers IDs across AJAX requests (and won't reuse them), but in our
// case we need to use the same ID from request to request so that the
// wrapper can be recognized by the AJAX system and its content can be
// dynamically updated. So instead, we will keep track of duplicate IDs
// (within a single request) on our own, later in this function.
$triggering_element['#ajax']['wrapper'] = 'edit-view-' . implode('-', $refresh_parents) . '-wrapper';
// Add a submit button for users who do not have JavaScript enabled. It
......
......@@ -337,7 +337,7 @@ public function getStandardButtons(&$form, FormStateInterface $form_state, $form
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => $name,
'#id' => 'edit-submit-' . Html::getUniqueId($form_id),
'#id' => 'edit-submit-' . drupal_html_id($form_id),
// The regular submit handler ($form_id . '_submit') does not apply if
// we're updating the default display. It does apply if we're updating
// the current display. Since we have no way of knowing at this point
......
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