Commit fdec77fc authored by alexpott's avatar alexpott
Browse files

Issue #2382543 by rpayanm, ianthomas_uk: Remove usage of drupal_html_class()...

Issue #2382543 by rpayanm, ianthomas_uk: Remove usage of drupal_html_class() and drupal_clean_css_identifier()
parent ee0b5439
......@@ -9,6 +9,7 @@
*/
use Drupal\Component\Serialization\Json;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Unicode;
......@@ -1352,7 +1353,7 @@ function template_preprocess_html(&$variables) {
}
else {
$segment = explode('/', $path);
$variables['attributes']['class'][] = 'path-' . drupal_html_class($segment[1]);
$variables['attributes']['class'][] = 'path-' . Html::getClass($segment[1]);
}
$site_config = \Drupal::config('system.site');
......@@ -1638,7 +1639,7 @@ function template_preprocess_field(&$variables, $hook) {
// Add default CSS classes. Since there can be many fields rendered on a page,
// save some overhead by calling strtr() directly instead of
// drupal_html_class().
// \Drupal\Component\Utility\Html::getClass().
$variables['entity_type_css'] = strtr($element['#entity_type'], '_', '-');
$variables['field_name_css'] = strtr($element['#field_name'], '_', '-');
$variables['field_type_css'] = strtr($element['#field_type'], '_', '-');
......
......@@ -7,6 +7,7 @@
namespace Drupal\Core\Field;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\NestedArray;
use Drupal\Component\Utility\SortArray;
use Drupal\Component\Utility\String;
......@@ -126,9 +127,9 @@ public function form(FieldItemListInterface $items, array &$form, FormStateInter
'#parents' => array_merge($parents, array($field_name . '_wrapper')),
'#attributes' => array(
'class' => array(
'field-type-' . drupal_html_class($this->fieldDefinition->getType()),
'field-name-' . drupal_html_class($field_name),
'field-widget-' . drupal_html_class($this->getPluginId()),
'field-type-' . Html::getClass($this->fieldDefinition->getType()),
'field-name-' . Html::getClass($field_name),
'field-widget-' . Html::getClass($this->getPluginId()),
),
),
'widget' => $elements,
......
......@@ -107,7 +107,7 @@ public function getFilters() {
new \Twig_SimpleFilter('without', 'twig_without'),
// CSS class and ID filters.
new \Twig_SimpleFilter('clean_class', 'drupal_html_class'),
new \Twig_SimpleFilter('clean_class', '\Drupal\Component\Utility\Html::getClass'),
new \Twig_SimpleFilter('clean_id', 'drupal_clean_id_identifier'),
);
}
......
......@@ -9,6 +9,7 @@
use Drupal\block\Event\BlockContextEvent;
use Drupal\block\Event\BlockEvents;
use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Executable\ExecutableManagerInterface;
......@@ -337,7 +338,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
array(
'theme' => $form_state->getValue('theme'),
),
array('query' => array('block-placement' => drupal_html_class($this->entity->id())))
array('query' => array('block-placement' => Html::getClass($this->entity->id())))
);
}
......
......@@ -7,6 +7,7 @@
namespace Drupal\block;
use Drupal\Component\Utility\Html;
use Drupal\Core\Block\BlockManagerInterface;
use Drupal\Component\Serialization\Json;
use Drupal\Component\Utility\String;
......@@ -245,7 +246,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'class' => array('draggable'),
),
);
if ($placement && $placement == drupal_html_class($entity_id)) {
if ($placement && $placement == Html::getClass($entity_id)) {
$form['blocks'][$entity_id]['#attributes']['id'] = 'block-placed';
}
......
......@@ -7,6 +7,7 @@
namespace Drupal\block\Tests;
use Drupal\Component\Utility\Html;
use Drupal\simpletest\WebTestBase;
/**
......@@ -74,7 +75,7 @@ function testBlockRenderOrder() {
$id = $return_block->get('id');
if ($return_block_weight = $return_block->get('weight')) {
$this->assertTrue($test_blocks[$id]['weight'] == $return_block_weight, 'Block weight is set as "' . $return_block_weight . '" for ' . $id . ' block.');
$position[$id] = strpos($test_content, drupal_html_class('block-' . $test_blocks[$id]['id']));
$position[$id] = strpos($test_content, Html::getClass('block-' . $test_blocks[$id]['id']));
}
}
$this->assertTrue($position['stark_powered'] < $position['stark_by'], 'Blocks with different weight are rendered in the correct order.');
......
......@@ -7,6 +7,7 @@
namespace Drupal\block\Tests;
use Drupal\Component\Utility\Html;
use Drupal\Core\Cache\Cache;
use Drupal\simpletest\WebTestBase;
use Drupal\Component\Utility\String;
......@@ -200,7 +201,7 @@ public function testBlockThemeSelector() {
$block['region'] = 'content';
$this->drupalPostForm('admin/structure/block/add/system_powered_by_block', $block, t('Save block'));
$this->assertText(t('The block configuration has been saved.'));
$this->assertUrl('admin/structure/block/list/' . $theme . '?block-placement=' . drupal_html_class($block['id']));
$this->assertUrl('admin/structure/block/list/' . $theme . '?block-placement=' . Html::getClass($block['id']));
// Set the default theme and ensure the block is placed.
$theme_settings->set('default', $theme)->save();
......@@ -288,10 +289,10 @@ function moveBlockToRegion(array $block, $region) {
// Confirm that the custom block was found at the proper region.
$xpath = $this->buildXPathQuery('//div[@class=:region-class]//div[@id=:block-id]/*', array(
':region-class' => 'region region-' . drupal_html_class($region),
':region-class' => 'region region-' . Html::getClass($region),
':block-id' => 'block-' . str_replace('_', '-', strtolower($block['id'])),
));
$this->assertFieldByXPath($xpath, NULL, t('Block found in %region_name region.', array('%region_name' => drupal_html_class($region))));
$this->assertFieldByXPath($xpath, NULL, t('Block found in %region_name region.', array('%region_name' => Html::getClass($region))));
}
/**
......
......@@ -7,6 +7,7 @@
namespace Drupal\block\Tests;
use Drupal\Component\Utility\Html;
use Drupal\simpletest\WebTestBase;
/**
......@@ -200,7 +201,7 @@ public function testBlockPlacementIndicator() {
// After adding a block, it will indicate which block was just added.
$this->drupalPostForm('admin/structure/block/add/system_powered_by_block', $block, t('Save block'));
$this->assertUrl('admin/structure/block/list/classy?block-placement=' . drupal_html_class($block['id']));
$this->assertUrl('admin/structure/block/list/classy?block-placement=' . Html::getClass($block['id']));
// Resaving the block page will remove the block indicator.
$this->drupalPostForm(NULL, array(), t('Save blocks'));
......
......@@ -8,6 +8,7 @@
namespace Drupal\block\Tests\Views;
use Drupal\Component\Serialization\Json;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\String;
use Drupal\views\Views;
use Drupal\views\Tests\ViewTestBase;
......@@ -63,7 +64,7 @@ public function testBlockCategory() {
// base table.
$arguments = array(
':id' => 'edit-category-lists-views',
':li_class' => 'views-block' . drupal_html_class($edit['id']) . '-block-1',
':li_class' => 'views-block' . Html::getClass($edit['id']) . '-block-1',
':href' => \Drupal::Url('block.admin_add', array(
'plugin_id' => 'views_block:' . $edit['id'] . '-block_1',
'theme' => 'classy',
......@@ -102,7 +103,7 @@ public function testBlockCategory() {
$arguments = array(
':id' => 'edit-category-lists-views',
':li_class' => 'views-block' . drupal_html_class($edit['id']) . '-block-2',
':li_class' => 'views-block' . Html::getClass($edit['id']) . '-block-2',
':href' => \Drupal::Url('block.admin_add', array(
'plugin_id' => 'views_block:' . $edit['id'] . '-block_2',
'theme' => 'classy',
......@@ -114,7 +115,7 @@ public function testBlockCategory() {
$arguments = array(
':id' => $category_id,
':li_class' => 'views-block' . drupal_html_class($edit['id']) . '-block-3',
':li_class' => 'views-block' . Html::getClass($edit['id']) . '-block-3',
':href' => \Drupal::Url('block.admin_add', array(
'plugin_id' => 'views_block:' . $edit['id'] . '-block_3',
'theme' => 'classy',
......
......@@ -7,6 +7,7 @@
namespace Drupal\block_content;
use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
......@@ -102,7 +103,7 @@ public function form(array $form, FormStateInterface $form_state) {
// Override the default CSS class name, since the user-defined custom block
// type name in 'TYPE-block-form' potentially clashes with third-party class
// names.
$form['#attributes']['class'][0] = drupal_html_class('block-' . $block->bundle() . '-form');
$form['#attributes']['class'][0] = 'block-' . Html::getClass($block->bundle()) . '-form';
$form['langcode'] = array(
'#title' => $this->t('Language'),
......
......@@ -6,6 +6,7 @@
*/
namespace Drupal\block_content\Tests;
use Drupal\Component\Utility\Html;
/**
* Ensures that custom block type functions work correctly.
......@@ -179,7 +180,7 @@ public function testsBlockContentAddTypes() {
$block = reset($blocks);
$this->assertUrl(\Drupal::url('block.admin_add', array('plugin_id' => 'block_content:' . $block->uuid(), 'theme' => $theme), array('absolute' => TRUE)));
$this->drupalPostForm(NULL, array(), t('Save block'));
$this->assertUrl(\Drupal::url('block.admin_display_theme', array('theme' => $theme), array('absolute' => TRUE, 'query' => array('block-placement' => drupal_html_class($edit['info[0][value]'])))));
$this->assertUrl(\Drupal::url('block.admin_display_theme', array('theme' => $theme), array('absolute' => TRUE, 'query' => array('block-placement' => Html::getClass($edit['info[0][value]'])))));
}
else {
$this->fail('Could not load created block.');
......
......@@ -5,6 +5,7 @@
* Callbacks and theming for the CKEditor toolbar configuration UI.
*/
use Drupal\Component\Utility\Html;
use Drupal\Core\Template\Attribute;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Language\LanguageInterface;
......@@ -115,7 +116,7 @@ function template_preprocess_ckeditor_settings_toolbar(&$variables) {
foreach ($active_buttons as $row_number => $button_row) {
foreach ($button_groups[$row_number] as $group_name) {
$variables['active_buttons'][$row_number][$group_name] = array(
'group_name_class' => drupal_html_class($group_name),
'group_name_class' => Html::getClass($group_name),
'buttons' => array(),
);
$buttons = array_filter($button_row, function ($button) use ($group_name) {
......
......@@ -8,6 +8,7 @@
namespace Drupal\comment\Plugin\Field\FieldWidget;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Component\Utility\Html;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
......@@ -76,7 +77,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
'#open' => ($items->status != $field_default_values[0]['status']),
'#group' => 'advanced',
'#attributes' => array(
'class' => array('comment-' . drupal_html_class($entity->getEntityTypeId()) . '-settings-form'),
'class' => array('comment-' . Html::getClass($entity->getEntityTypeId()) . '-settings-form'),
),
'#attached' => array(
'library' => array('comment/drupal.comment'),
......
......@@ -7,6 +7,7 @@
namespace Drupal\contextual\Element;
use Drupal\Component\Utility\Html;
use Drupal\Core\Render\Element\RenderElement;
use Drupal\Core\Url;
......@@ -79,7 +80,7 @@ public static function preRenderLinks(array $element) {
// Transform contextual links into parameters suitable for links.html.twig.
$links = array();
foreach ($items as $class => $item) {
$class = drupal_html_class($class);
$class = Html::getClass($class);
$links[$class] = array(
'title' => $item['title'],
'url' => Url::fromRoute(isset($item['route_name']) ? $item['route_name'] : '', isset($item['route_parameters']) ? $item['route_parameters'] : []),
......
......@@ -7,6 +7,7 @@
namespace Drupal\dblog\Controller;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode;
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Xss;
......@@ -199,7 +200,7 @@ public function overview() {
Xss::filter($dblog->link),
),
// Attributes for table row.
'class' => array(drupal_html_class('dblog-' . $dblog->type), $classes[$dblog->severity]),
'class' => array(Html::getClass('dblog-' . $dblog->type), $classes[$dblog->severity]),
);
}
......
......@@ -5,6 +5,7 @@
* Allows administrators to attach custom fields to fieldable types.
*/
use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
......@@ -228,7 +229,7 @@ function theme_field_ui_table($variables) {
// Render rows, region by region.
foreach ($elements['#regions'] as $region_name => $region) {
$region_name_class = drupal_html_class($region_name);
$region_name_class = Html::getClass($region_name);
// Add region rows.
if (isset($region['title']) && empty($region['invisible'])) {
......
......@@ -7,6 +7,7 @@
namespace Drupal\field_ui;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\EntityListBuilderInterface;
......@@ -127,7 +128,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t
);
$table[$name] = array(
'#attributes' => array(
'id' => drupal_html_class($name),
'id' => Html::getClass($name),
),
'label' => array(
'#markup' => String::checkPlain($field->getLabel()),
......
......@@ -7,6 +7,7 @@
namespace Drupal\field_ui;
use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
......@@ -192,7 +193,7 @@ public function tablePreRender($elements) {
}
// Add row id and associate JS settings.
$id = drupal_html_class($name);
$id = Html::getClass($name);
$row['#attributes']['id'] = $id;
if (isset($row['#js_settings'])) {
$row['#js_settings'] += array(
......
......@@ -8,6 +8,7 @@
namespace Drupal\file\Tests;
use Drupal\comment\Entity\Comment;
use Drupal\Component\Utility\Html;
use Drupal\field\Entity\FieldConfig;
use Drupal\field_ui\Tests\FieldUiTestTrait;
......@@ -74,7 +75,7 @@ function testSingleValuedWidget() {
$this->assertNoFieldByXPath('//input[@type="submit"]', t('Remove'), 'After clicking the "Remove" button, it is no longer displayed.');
$this->assertFieldByXpath('//input[@type="submit"]', t('Upload'), '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) . "-0-upload']");
$label = $this->xpath("//label[@for='edit-" . Html::cleanCssIdentifier($field_name) . "-0-upload']");
$this->assertTrue(isset($label[0]), 'Label for upload found.');
// Save the node and ensure it does not have the file.
......
......@@ -8,6 +8,7 @@
* API pattern.
*/
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Form\FormStateInterface;
......@@ -520,7 +521,7 @@ function node_is_page(NodeInterface $node) {
function node_preprocess_html(&$variables) {
// If on an individual node page, add the node type to body classes.
if (($node = \Drupal::routeMatch()->getParameter('node')) && $node instanceof NodeInterface) {
$variables['attributes']['class'][] = drupal_html_class('node--type-' . $node->getType());
$variables['attributes']['class'][] = Html::getClass('node--type-' . $node->getType());
}
}
......
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