Since #422824: Add more specific body classes so page elements can be themed based on page type, we are using template suggestions to figure out body classes. Running theme_get_suggestions(array('node', '1'), 'page', '-') just as template_preprocess_html() does returns the following suggestions:

 Array(
    [0] => page-node
    [1] => page-node-%
    [2] => page-node-1
    [3] => page-front
) 

Now drupal_html_class() will turn page-node-% into 'page-node-', which is a meaningless class. Let's either strip the wildcard solutions before running drupal_html_class() or turn % into something meaningful.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Issue tags: -html5

Nothing to do with HTML5. Also, I'm not sure *why* we even support a suggestion like page__node__% to begin with? I think we should remove the wildcard functionality.

Dave Reid’s picture

This change seems to have originated with #167112: PHPTemplate Suggestion wildcard. We should remove them when processed by CSS classes.

Dave Reid’s picture

Status: Active » Needs review
FileSize
707 bytes

Let's skip any suggestions with wildcards in them.

barraponto’s picture

Wonderful.
I have added a comment to make it clear why we are filtering % out.

marcingy’s picture

Status: Needs review » Needs work
Issue tags: +Needs backport to D7

Sorry for the nitpick

// Ignore front page and wildcard suggestions

needs a period at the end otherwise looks good.

barraponto’s picture

Done.

@marcingy You will like the patch I posted at #1054848: Fixing common typos through codespell.py, although it needs updating.

barraponto’s picture

Status: Needs work » Needs review
Hanpersand’s picture

Subscribing.

marcingy’s picture

Status: Needs review » Reviewed & tested by the community

looks good

andypost’s picture

+1, this also fixes taxonomy page body classes

before patch:
html not-front logged-in no-sidebars page-taxonomy page-taxonomy-term page-taxonomy-term- page-taxonomy-term-45 toolbar toolbar-drawer footer-columns

after patch:
html not-front logged-in no-sidebars page-taxonomy page-taxonomy-term page-taxonomy-term-45 toolbar toolbar-drawer footer-columns

pvasili’s picture

Subscribing

Damien Tournoud’s picture

Status: Reviewed & tested by the community » Needs work

I was ready to write "This check needs to go into theme_get_suggestions()", until I saw comment #2.

So either:

  • We need to extend the comment to explain *why* those wildcard-based classes have no use. Comments explaining *what* have zero value. I can read the code below, thank you :)
  • We need to support wildcard classes in CSS. "%" is not actually valid in CSS class names, so we could replace it with the explicit text "wildcard"
barraponto’s picture

The reason we have the wildcard suggestion there, in the first place, is to have different templates for /user and /user/1. It makes sense for templates and it makes sense for CSS classes as well.

According to http://www.w3.org/TR/CSS2/syndata.html#characters, the closest we can get to a wildcard class would be ending it with a hyphen. I agree we should use a explicit string (-wildcard or -ALL). I wonder if it ever conflicts with the template name (let's hope not).

BarisW’s picture

Status: Needs work » Needs review
FileSize
1.1 KB

Replaced % with 'wildcard' in list_themes().

Body classes before: "html not-front logged-in one-sidebar sidebar-first page-node page-node- page-node-1 node-type-article toolbar toolbar-drawer"
Body classes after: "html not-front logged-in one-sidebar sidebar-first page-node page-node-wildcard page-node-1 node-type-article toolbar toolbar-drawer"

Status: Needs review » Needs work

The last submitted patch, wildcards-in-body-classes-1242908-14.patch, failed testing.

barraponto’s picture

Status: Needs work » Needs review
FileSize
3.56 KB

Updating the tests.

BarisW’s picture

alansaviolobo’s picture

Reroll.

BarisW’s picture

The comments have been removed, so let's remove it for the wildcard too.

Status: Needs review » Needs work

The last submitted patch, 19: wildcards_in_body_classes-1242908-19.patch, failed testing.

BarisW’s picture

Status: Needs work » Needs review
FileSize
3.25 KB

Here's a re-roll.

mgifford’s picture

Status: Needs review » Needs work

Needs re-roll.

BarisW’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Needs work » Needs review
FileSize
3.25 KB
BarisW’s picture

Issue tags: +Needs themer review

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

ranjith_kumar_k_u’s picture

Re-rolled for 9.2

Status: Needs review » Needs work

The last submitted patch, 36: 1242908-36.patch, failed testing. View results

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

smustgrave’s picture

This is the same as #41 but with a tests-only patch.

The last submitted patch, 42: 1242908-42-tests-only.patch, failed testing. View results

smustgrave’s picture

Issue tags: +Bug Smash Initiative

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

catch’s picture

Status: Needs review » Needs work
+++ b/core/includes/theme.inc
@@ -1473,9 +1473,9 @@ function theme_get_suggestions($args, $base, $delimiter = '__') {
   //
   // page__node
-  // page__node__%
   // page__node__1
   // page__node__edit
+  // page__node__wildcard
 

Isn't page__node identical to page__node__wildcard?

smustgrave’s picture

Guess it’s the same so should we remove page_node_%

Should we be worried about BC

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.