Problem/Motivation

If you visit the /admin page, the tag contains a path-admin class, but if you visit the page in another language, like /fa/admin, the tag will contain a path-fa class and miss the path-admin class, because it uses the first segment after the / symbol (in core/includes/theme.inc -> function template_preprocess_html).
The .path-admin class is now used in a few CSS rules, which means those styles won't be applied if the path has a language prefix.

Proposed resolution

Construct that CSS class based on a non-aliased, non-processed path.

Remaining tasks

Commit.

User interface changes

CSS classes applied to path-admin will work again. Bartik has these styles:

$ git grep path-admin
core/themes/bartik/css/components/admin.css:.path-admin #content img {
core/themes/bartik/css/components/admin.css:.path-admin #content .simpletest-image img {
core/themes/bartik/css/components/admin.css:.path-admin #admin-dblog img {

API changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dileepmaurya’s picture

Status: Active » Needs review
FileSize
547 bytes

Status: Needs review » Needs work
dileepmaurya’s picture

Status: Needs work » Needs review
FileSize
716 bytes
Gábor Hojtsy’s picture

Status: Needs review » Needs work
Issue tags: +D8MI, +CSS, +language-base, +Novice

I don't think that is a good idea, there may be any number of other things done to the path, eg. path aliases. Does this prefix work with a path alias a /headquarters for /admin for example?

dileepmaurya’s picture

dileepmaurya’s picture

Status: Needs work » Needs review
gvso’s picture

I think we shouldn't use drupal_is_front_page() in order to avoid make this patch again https://www.drupal.org/node/2388627

dileepmaurya’s picture

drupal_is_front_page() is replaced with \Drupal::service('path.matcher')->isFrontPage()

Gábor Hojtsy’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

I cannot tell if this is technically correct or not, but it looks promising.

Please watch your code style, you should indent with 2 spaces, not 3 or 4. Also add space after if, else and before {.

Also not sure how best we can test this but it sure would be great to have test for this, since it was broken unnoticed.

dileepmaurya’s picture

dileepmaurya’s picture

Status: Needs work » Needs review
Gábor Hojtsy’s picture

Code format looks good :) Given the change is in the theme system this can get tests AFAIS.

Gábor Hojtsy’s picture

Issue tags: +SprintWeekend2015Queue
Kristen Pol’s picture

I tested the patch and it does indeed work as expected so then time for tests. :)

Kristen Pol’s picture

Status: Needs review » Needs work

Moving back to needs work.

dileepmaurya’s picture

If any one on admin page what classes sholud be added ?
I think if we visit on admin page then one of the class should be path-admin and its not depend on url language prefix or any type of prefix and url alias.

dileepmaurya’s picture

Adding language specific class in body such as lang-[language-id].

dileepmaurya’s picture

Status: Needs work » Needs review
dileepmaurya’s picture

Gábor Hojtsy’s picture

Issue summary: View changes
Status: Needs review » Needs work

The root HTML tag already has a lang="XY" attribute. That can already perfectly used in CSS. No need for that body class. Also not in scope for this issue anyway.

@dileepmaurya: please also post interdiffs (https://www.drupal.org/documentation/git/interdiff) so we can review what did you change and explain changes. Updated patches like 19 without comments and interdiffs is very hard to review.

segi’s picture

Assigned: Unassigned » segi
Gábor Hojtsy’s picture

Issue tags: +SprintWeekend2015
prajaankit’s picture

prajaankit’s picture

Status: Needs work » Needs review
Gábor Hojtsy’s picture

Status: Needs review » Needs work

@prajaankit:

1. Please respect if an issue was assigned to someone recently.
2. You did not post an explanation or an interdiff of what you changed.
3. You did not actually address anything in #20, despite referring to that only in your comment.

segi’s picture

Assigned: prajaankit » segi
Status: Needs work » Needs review
FileSize
2.97 KB
3.12 KB

I modified the last #23 patch based on @Gábor Hojtsy feedbacks, I created a new test and I add it to LanguageSwitchingTest test class.

Gábor Hojtsy’s picture

Status: Needs review » Needs work

Looking good now, only two notes:

  1. +++ b/core/includes/theme.inc
    @@ -1343,8 +1343,17 @@ function template_preprocess_html(&$variables) {
    +  //Add a variable for language. This can be used to create a language specific class.
    +  $variables['language'] = $language_interface->getId();
    

    You don't use this anymore.

  2. +++ b/core/modules/language/src/Tests/LanguageSwitchingTest.php
    @@ -242,6 +241,26 @@ function testLanguageLinkActiveClass() {
    +    // Go to admin/config page
    +    $this->drupalGet('fr/admin/config');
    +    $class = $this->xpath('//body[contains(@class, :class)]', array(':class' => 'path-admin'));
    +    $this->assertTrue(isset($class[0]), t('The path-admin class same as on default language'));
    

    I would also test this without the French language, to compare it also works the same on the non-foreign page.

segi’s picture

Ok, I fixed the patch based on feedbacks.

segi’s picture

Status: Needs work » Needs review
Gábor Hojtsy’s picture

Title: Wrong/missing class on <body> in paths with language prefix » Path class on <body> may be language specific, results in CSS bugs
Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Retitled to be more specific. Also updated issue summary. Thanks!

DevElCuy’s picture

Issue tags: -SprintWeekend2015Queue
DevElCuy’s picture

Issue tags: +SprintWeekend2015Queue

Removed SprintWeekend2015Queue by mistake.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

Needs a reroll

alexpott’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll

Actually I didn't commit the patch that causes the conflict.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed f8aa6c2 and pushed to 8.0.x. Thanks!

diff --git a/core/includes/theme.inc b/core/includes/theme.inc
old mode 100644
new mode 100755

We need to be careful not to change filemodes. Fixed on commit.

  • alexpott committed f8aa6c2 on 8.0.x
    Issue #2404929 by dileepmaurya, segi, Kristen Pol, prajaankit: Path...
Gábor Hojtsy’s picture

Yay superb, thanks all!

davidhernandez’s picture

Not sure what happened with the patches, but there was back and forth with root_path being set TRUE or FALSE and html.html.twig being modified or not modified. In the end that seems to have gotten confused because path-frontpage doesn't work now with that logic.

The template uses not root_path so the preprocess functions should set it FALSE.

Gábor Hojtsy’s picture

How does the test work then?

davidhernandez’s picture

The test in this issue? It looks to only be visiting admin pages, and looking for 'path-admin'. The switch in logic only affected the class for the frontpage.

idebr’s picture

I opened a followup for the missing body class: #2411597: Class 'path-frontpage' missing from <body>

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.