Follow-up to #1995272: [Meta] Refactor module CSS files inline with our CSS standards

Problem/Motivation

This drupal.org documentation page describes many common pitfalls of Drupal module's CSS: http://drupal.org/node/1887918#pitfalls

Proposed resolution

To remove these problems, we should follow the best practices guidelines outlined on this drupal.org documentation page: http://drupal.org/node/1887918#best-practices

Remaining tasks

  • Look at Forum's CSS and template files within the Forum module and refactor them based on the CSS standards here.
  • Try to make the templates as clean as possible, ditch IDs, use correct naming conventions for CSS selectors etc.
  • Look at Bartik's CSS styles for Forum and adjust accordingly to match the work carried out in the Module files.

User interface changes

None. The design objects that style the Drupal module's functionality should be look roughly the same after as they do now.

API changes

All of core's modules will have new CSS selectors that better match the design objects being used for their content.

Beta phase evaluation

-->

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because coding standards
Issue priority Not critical because no user facing defect
Unfrozen changes Unfrozen because it only changes CSS/markup

Before:


After:


Comments

lewisnyman’s picture

Component: CSS » forum.module
StatusFileSize
new1.24 KB
Aleksandar_P’s picture

Assigned: Unassigned » Aleksandar_P
Aleksandar_P’s picture

Assigned: Aleksandar_P » Unassigned
mgifford’s picture

@LewisNyman - why didn't you upload a patch? What is forum.module.css_.txt other than the current forum.module.css?

emma.maria’s picture

@mgifford it's a starting point. Others can see the whole file as it is now and you can use dreditor to add suggestions to it if you do not want to write a patch yourself.

lewisnyman’s picture

@mgifford It's easy to review it in Dreditor to find problems to fix

mgifford’s picture

Ok, no problem. So this would be to just replace core/modules/forum/css/forum.theme.css if everyone's happy with the CSS.

lewisnyman’s picture

There is loads to do :P

  1. #forum .description {
    

    This should be .forum__description

  2. #forum td.created,
    #forum td.posts,
    #forum td.topics,
    #forum td.last-reply,
    #forum td.replies,
    #forum td.pager {
    

    forum__created
    forum__posts
    forum__topics
    forum__last-reply
    forum__replies
    forum__pager

  3. #forum .icon{
    

    forum__icon

  4. #forum .title {
    

    forum__title

  5. #forum div.indent {
    

    hmm don't we already have an indent class that we use in menus?

  6. #forum .topic-status-new {
    

    forum__topic-status--new

  7. #forum .topic-status-hot {
    

    forum__topic-staus--hot

  8. #forum .topic-status-hot-new {
    

    forum__topic-staus--hot-new

  9. #forum .topic-status-sticky {
    

    forum__topic-staus--sticky

  10. #forum .topic-status-closed {
    

    forum__topic-staus--closed

  11. [dir="rtl"] .forum-topic-navigation {
    

    forum-topic-navigation is a good class name imo, but why only rtl styling? Where is the ltr styling?

  12. [dir="rtl"] .forum-topic-navigation .topic-previous {
    

    forum-topic-navigation__previous

  13. [dir="rtl"] .forum-topic-navigation .topic-next {
    

    forum-topic-navigation__next

  14. .action--forum {
    

    I'm not sure what this is but I don't think we have an action class in D8, so we can't add a forum modifier to it

Vidushi Mehta’s picture

StatusFileSize
new1.86 KB

@LewisNyman replaced classes in patch.. Please verify

other, what should we do with #forum div.indent, I guess ID's would be no longer in D8.

Vidushi Mehta’s picture

lewisnyman’s picture

Status: Active » Needs review
lewisnyman’s picture

Status: Needs review » Needs work

This is looking good, but we also need to change the twig files as well as the CSS. Setting back to needs work.

MathieuSpil’s picture

Assigned: Unassigned » MathieuSpil
MathieuSpil’s picture

Assigned: MathieuSpil » Unassigned
Status: Needs work » Needs review
StatusFileSize
new7.94 KB

CSS changes::
1. Following the last patch of Vidushi Mehta, I noticed there are other css-files inside Customtheme and Bartik that use the #forum-selector.
2. I saw that the #forum td.created and the #forum td.pager selector was no longer being used, so I deleted it from the CSS.
3. Replaced #forum div.indent with .forum .indented following the comment-module.
4. Removed all css using the .forum-topic-navigation selector because I can't find where this is being used? (That's probably why only the rtl was still inside the CSS?)

Twig changes:
1. I updated the template files in the classy theme.

Other changes:
1. There is still a need for a refactoring inside the forum frontend. (but maybe this should be for a other ticket?)
2. .action--forumis now replaced with .forum__action Because this makes more sense to me, or am I missing something here?

Status: Needs review » Needs work

The last submitted patch, 14: refactor-forum-module-css-2408513-14.patch, failed testing.

lewisnyman’s picture

+++ b/core/modules/forum/css/forum.theme.css
@@ -23,48 +23,35 @@
+}
\ No newline at end of file

+++ b/core/themes/bartik/css/components/forum.css
@@ -1,6 +1,6 @@
+}
\ No newline at end of file

We are missing blank lines at the end of these files

+++ b/core/modules/forum/css/forum.theme.css
@@ -23,48 +23,35 @@
-.action--forum {
+.forum__action {
   list-style: none;
-}

+++ b/core/modules/forum/src/Controller/ForumController.php
@@ -260,7 +260,7 @@ protected function buildActionLinks($vid, TermInterface $forum_term = NULL) {
-          '#attributes' => ['class' => ['action--forum']],
+          '#attributes' => ['class' => ['forum__action']],

@@ -286,7 +286,7 @@ protected function buildActionLinks($vid, TermInterface $forum_term = NULL) {
-          '#attributes' => ['class' => ['action--forum']],
+          '#attributes' => ['class' => ['forum__action']],

Instead of using custom classes and CSS, I think we can just reuse the .action-links class

There is still a need for a refactoring inside the forum frontend. (but maybe this should be for a other ticket?)

What is left to do?

manjit.singh’s picture

StatusFileSize
new7.88 KB

@LewisNyman adding blank line at the end of file. Please verify.

what should we do, Can we replace .forum__action with.action-links in css and ForumController.php ?

tadityar’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 17: refactor-forum-module-css-2408513-17.patch, failed testing.

MathieuSpil’s picture

Assigned: Unassigned » MathieuSpil
MathieuSpil’s picture

Assigned: MathieuSpil » Unassigned
StatusFileSize
new7.88 KB

Changes from patch #17:
We now use the .action-links class.

@lewis: Not sure if this has been noticed before, but the comment.theme.css file defines the following:

.indented {
  margin-left: 25px; /* LTR */
}
[dir="rtl"] .indented {
  margin-left: 0;
  margin-right: 25px;
}

This causes the elements with class .indented to have margins defined from the moment the comment-module is being used. I don't think that is a desired behaviour, because we use the .indented also in the forum-module... (Follow-up ticket for this?)

About the frontend refactoring:
We didn't do any semantic reordering in this ticket, so why do we change

#forum td.created,
#forum td.posts,
#forum td.topics,
#forum td.last-reply,
#forum td.replies,
#forum td.pager {
  white-space: nowrap;
}

into

.forum__created,
.forum__posts,
.forum__topics,
.forum__last-reply,
.forum__replies,
.forum__pager {
  white-space: nowrap;
}

and not into

.forum td {
  white-space: nowrap;
}

Something else I noticed is that we can now have a .forum into .forum
Because in forums.html.twig we have:

{% if forums_defined %}
  <div class="forum">
    {{ forums }}
    {{ topics }}
    {{ topics_pager }}
  </div>
{% endif %}

and in forum-list.html.twig we have

<td {% if forum.is_container == true -%}
        colspan="4" class="container"
      {%- else -%}
        class="forum"
      {%- endif -%}>

And last but not least, the testing is failing because "I think" we deleted the id="forum" and now the bot can't create testnodes.

lewisnyman’s picture

This causes the elements with class .indented to have margins defined from the moment the comment-module is being used. I don't think that is a desired behaviour, because we use the .indented also in the forum-module... (Follow-up ticket for this?)

Yeah that sounds like we should reduce the scope of that selector, can you create a new issue for it? For this issue, can we change the class to .forum__indented?

.forum td {
  white-space: nowrap;
}

Yeah this is a good improvement, what do you think we should do with .forum__pager? Does it make sense to give it nowrap?

Something else I noticed is that we can now have a .forum into .forum

Can we rename the old .forum class to be .forum-list__forum? I think that is more clear what it's purpose is.

MathieuSpil’s picture

Status: Needs work » Needs review
StatusFileSize
new8.06 KB

1. Created a follow-up issue for the indented class, for now I suggest to keep .forum .indented (the same as how the comment module does this) This way the follow-up ticket will be more clear.

2. I think .forum__pager or the old #forum td.pager is no longer relevant, and it should have been removed from the first patch of mine, can you confirm?

3. Changed the old .forum to .forum-list__forum as suggested.

Also changed ticket to needs review so it is more clear what changes need to happen in the tests.

Status: Needs review » Needs work

The last submitted patch, 23: refactor-forum-module-css-2408513-23.patch, failed testing.

pakmanlh’s picture

Assigned: Unassigned » pakmanlh

Working on it.

pakmanlh’s picture

Assigned: pakmanlh » Unassigned
svendecabooter’s picture

Status: Needs work » Needs review
StatusFileSize
new10.01 KB
MathieuSpil’s picture

Issue tags: +drupaldevdays
lewisnyman’s picture

StatusFileSize
new2.86 KB

Here is the interdiff between 23 and 26

lewisnyman’s picture

Here are the screenshots to compare before and after

Before:


After:


+++ b/core/modules/forum/src/Tests/ForumTest.php
--- a/core/modules/forum/templates/forums.html.twig
+++ b/core/modules/forum/templates/forums.html.twig

+++ b/core/modules/forum/templates/forums.html.twig
@@ -17,7 +17,7 @@
-  <div>
+  <div class="forum">

I don't think we should be adding this class in the module. Only in Classy

MathieuSpil’s picture

StatusFileSize
new9.64 KB

Resetted

+++ b/core/modules/forum/src/Tests/ForumTest.php
--- a/core/modules/forum/templates/forums.html.twig
+++ b/core/modules/forum/templates/forums.html.twig
+++ b/core/modules/forum/templates/forums.html.twig
@@ -17,7 +17,7 @@
-  <div>
+  <div class="forum">

in latest patch based upon #27

lewisnyman’s picture

Status: Needs work » Needs review
lewisnyman’s picture

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

Thanks, almost done:

+++ b/core/modules/forum/css/forum.theme.css
@@ -23,48 +18,32 @@
-.action--forum {
-  list-style: none;
-}
+}
\ No newline at end of file

We are missing a blank link here

manjit.singh’s picture

StatusFileSize
new9.61 KB

@lewisnyman Adding blank line :)

manjit.singh’s picture

Status: Needs work » Needs review
lewisnyman’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Excellent, thank you!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 34: refactor-forum-module-css-2408513-34.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 34: refactor-forum-module-css-2408513-34.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 34: refactor-forum-module-css-2408513-34.patch, failed testing.

emma.maria’s picture

The patch applies, I found nothing weird in the patch. Due to the high number of errors and seeing a patch in another issue fail like this and it is now passing, I'm hitting re-test again and keeping my fingers crossed.

Status: Needs work » Needs review
emma.maria’s picture

Status: Needs review » Reviewed & tested by the community

Setting back to RTBC as the patch passes and @LewisNyman already gave it the status in #36.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 34: refactor-forum-module-css-2408513-34.patch, failed testing.

Status: Needs work » Needs review
lewisnyman’s picture

Status: Needs review » Reviewed & tested by the community

Seems legit...

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 1cdef09 and pushed to 8.0.x. Thanks!

Thanks for adding the beta eval to the issue summary.

  • alexpott committed 1cdef09 on 8.0.x
    Issue #2408513 by MathieuSpil, Manjit.Singh, Vidushi Mehta,...

Status: Fixed » Closed (fixed)

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

Vidushi Mehta’s picture