Remove ids from blocks

Created on 18 June 2015, over 9 years ago
Updated 2 May 2024, 8 months ago

I just wrote a preprecessor to transform the ids on blocks to classes:

<?php
/*
 * Implements hook_preprocess_block().
 */
function template_preprocess_block(&$variables) {
  if (isset($variables['attributes']['id'])) {
    $variables['attributes']['class'] = $variables['attributes']['id'];
    unset($variables['attributes']['id']);
  }
}
?>

Having ids in the markup is against D8 standards, right?

📌 Task
Status

Closed: won't fix

Version

11.0 🔥

Component
Theme 

Last updated about 3 hours ago

Created by

🇨🇭Switzerland Lukas von Blarer

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇨🇦Canada Liam Morland Ontario, CA 🇨🇦

    You can probably do this in hook_preprocess_HOOK() for block.

  • Status changed to Closed: won't fix 8 months ago
  • 🇺🇸United States bnjmnm Ann Arbor, MI

    This may have been worthwhile when this issue was filed and Drupal 8 had not yet been released, but in the 9 years since this was filed, Drupal sites have grown quite accustomed to blocks having IDs and it would be very disruptive to existing sites to make this change now - potentially millions of CSS/JS selectors would cry out in terror and suddenly be silenced.

    There is also no current standard that would get mad about blocks having IDs, so lets send this one to a nice farm up north.

Production build 0.71.5 2024