(First, verify that the preprocess changes have been made. #2322163: [meta] Consensus Banana Phase 1, move CSS classes from preprocess to twig templates.)

Preprocess changes are done.

The templates will be copied in another issue. #2424533: Copy views templates to Classy

  1. Remove all classes from the core module's template. Remove all classes added with addClass and ones that are hard-coded in the template.
  • If there are classes that are required for basic functionality, discuss whether they should be kept.
  • If there is CSS from the module, or anywhere else, referring to the class, discuss removing it or moving it to Bartik&Seven. Do not move the CSS to Classy.

Twig Templates to modify

core/modules/views/templates/views-exposed-form.html.twig
core/modules/views/templates/views-mini-pager.html.twig
core/modules/views/templates/views-more.html.twig
core/modules/views/templates/views-view-field.html.twig
core/modules/views/templates/views-view-fields.html.twig
core/modules/views/templates/views-view-grid.html.twig
core/modules/views/templates/views-view-grouping.html.twig
core/modules/views/templates/views-view-list.html.twig
core/modules/views/templates/views-view-mapping-test.html.twig
core/modules/views/templates/views-view-opml.html.twig
core/modules/views/templates/views-view-row-opml.html.twig
core/modules/views/templates/views-view-row-rss.html.twig
core/modules/views/templates/views-view-rss.html.twig
core/modules/views/templates/views-view-summary-unformatted.html.twig
core/modules/views/templates/views-view-summary.html.twig
core/modules/views/templates/views-view-table.html.twig
core/modules/views/templates/views-view-unformatted.html.twig
core/modules/views/templates/views-view.html.twig

CommentFileSizeAuthor
#58 interdiff.txt1.35 KBManuel Garcia
#58 remove_classes_from-2349775-58.patch19.41 KBManuel Garcia
#54 Content_d8.local_-_2015-05-15_11.08.38.png27.94 KBtombo
#54 Content_d8.local_-_2015-05-15_11.01.47.png30.41 KBtombo
#54 Content_d8.local_-_2015-05-15_11.00.54.png22.28 KBtombo
#53 Content_d8.local_-_2015-05-15_10.58.20.png29.08 KBtombo
#52 Content_d8.local_-_2015-05-15_10.54.04.png25.79 KBtombo
#52 Content_d8.local_-_2015-05-15_10.53.41.png25.37 KBtombo
#50 remove_classes_from-2349775-50.patch19.78 KBManuel Garcia
#50 interdiff.txt442 bytesManuel Garcia
#49 interdiff-2349775-39_2349775-49.txt755 bytessaki007ster
#49 remove_classes_from-2349775-49.patch20.21 KBsaki007ster
#45 remove_classes_from-2349775-45.patch19.06 KBsaki007ster
#45 interdiff-2349775-39_2349775-45.txt1.89 KBsaki007ster
#44 Screen Shot 2015-05-12 at 5.44.21 pm.png170.93 KBsaki007ster
#44 Screen Shot 2015-05-12 at 5.54.44 pm.png159.54 KBsaki007ster
#39 interdiff-2349775-34-39.txt1.94 KBManjit.Singh
#39 remove_classes_from-2349775-39.patch20.52 KBManjit.Singh
#35 remove_classes_from-2349775-35.patch11.68 KBbrahmjeet789
#34 interdiff.txt2.06 KBManuel Garcia
#34 remove_classes_from-2349775-34.patch18.58 KBManuel Garcia
#32 interdiff.txt7.71 KBManuel Garcia
#32 remove_classes_from-2349775-32.patch16.52 KBManuel Garcia
#31 remove_classes_from-2349775-31.patch22.04 KBManuel Garcia
#27 interdiff.txt16.16 KBManuel Garcia
#27 remove_classes_from-2349775-27.patch21.93 KBManuel Garcia
#25 interdiff.txt2.92 KBManuel Garcia
#25 remove_classes_from-2349775-25.patch9.42 KBManuel Garcia
#21 interdiff.txt4.31 KBManuel Garcia
#21 remove_classes_from-2349775-21.patch9.42 KBManuel Garcia
#16 interdiff.txt675 bytesManuel Garcia
#16 remove_classes_from-2349775-15.patch5.1 KBManuel Garcia
#12 interdiff.txt1.31 KBManuel Garcia
#12 remove_classes_from-2349775-12.patch5.11 KBManuel Garcia
#10 remove_classes_from-2349775-10.patch5.21 KBManuel Garcia
#4 copy_views_ui_templates-2349777-2.patch18.77 KBmortendk
#1 copy_views_templates_to-2349775-1.patch19.04 KBmortendk
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mortendk’s picture

Status: Active » Needs review
FileSize
19.04 KB

moved templates & cleaned out classes

Status: Needs review » Needs work

The last submitted patch, 1: copy_views_templates_to-2349775-1.patch, failed testing.

mortendk’s picture

Issue tags: +cssbanana
mortendk’s picture

Status: Needs work » Needs review
FileSize
18.77 KB

re roll

Status: Needs review » Needs work

The last submitted patch, 4: copy_views_ui_templates-2349777-2.patch, failed testing.

davidhernandez’s picture

Status: Needs work » Postponed

This should be postponed until #2329917: Move views classes from preprocess to templates is in.

davidhernandez’s picture

Title: Copy views templates to Classy » Remove classes from Views templates
Status: Postponed » Needs work

Unpostponing. I created another issue to just copy the templates, like we did with System. We can continue to use this one to remove the classes from core.

#2424533: Copy views templates to Classy

davidhernandez’s picture

Issue summary: View changes
davidhernandez’s picture

The templates have been copied to Classy, so we can try to remove the classes.

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
5.21 KB

Here's a brave new patch -=)

davidhernandez’s picture

Issue summary: View changes
+++ b/core/modules/views/templates/views-mini-pager.html.twig
@@ -12,28 +12,28 @@
-            <span class="visually-hidden">{{ 'Next page'|t }}</span>

"visually-hidden" classes are functional, so they need to stay.

Manuel Garcia’s picture

You're right, I got carried away...

dawehner’s picture

Status: Needs review » Needs work
+++ b/core/modules/views/templates/views-mini-pager.html.twig
@@ -12,28 +12,28 @@
-    <ul class="pager__items">
...
+    <ul>

pager__items are used by the javascript, please test those bits to ensure things still works. Ajax view ... with a mini pager

The last submitted patch, 10: remove_classes_from-2349775-10.patch, failed testing.

davidhernandez’s picture

We'll probably want to prefix the ones using javascript. (js-) a la #2431671: [meta] Add in js- prefixed classes for separation of JS & CSS functionality

I'm honestly surprised there are only 11 fails (from two tests.)

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
5.1 KB
675 bytes

Good catch dawehner. I've tested the attached (with stark enabled) using a minipager with ajax, its now working.

I also tested an exposed filter using ajax, it also works.

The last submitted patch, 12: remove_classes_from-2349775-12.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 16: remove_classes_from-2349775-15.patch, failed testing.

dawehner’s picture

Status: Needs work » Reviewed & tested by the community

I also tested an exposed filter using ajax, it also works.

Thank you for manually testing it. It looks fine for me now.

davidhernandez’s picture

Status: Reviewed & tested by the community » Needs work

RTBCing a red patch?

I think we should still do the js- prefixing, unless there is an argument against it.

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
9.42 KB
4.31 KB

This should fix the failing tests.

@davidhernandez do you think we should include a change to the views classes for js- prefixing in this patch, or tackle that on a different issue?

dawehner’s picture

+++ b/core/modules/views/src/Tests/Handler/AreaEntityTest.php
@@ -158,8 +161,8 @@ public function doTestRender($entities) {
+    $view_class = 'view-dom-id-' . $view->dom_id;
+    $result = $this->xpath('//div[@class = "' . $view_class .'"]/div[1]');

@@ -167,7 +170,8 @@ public function doTestRender($entities) {
+    $view_class = 'view-dom-id-' . $view->dom_id;
+    $result = $this->xpath('//div[@class = "' . $view_class .'"]/div[3]');

Mh, the test now is much less readable ... too bad, anyway, can we open up a follow up to use and for those bits? This would improve a lot the semantics of the code.

star-szr’s picture

Interesting, I thought most tests used Classy. So far we haven't had to do much of this type of thing.

+++ b/core/modules/views/src/Tests/Handler/AreaEntityTest.php
@@ -125,23 +125,26 @@ public function doTestRender($entities) {
+    $header_xpath = '//div[@class = "' . $view_class .'"]/div[1]';
+    $footer_xpath = '//div[@class = "' . $view_class .'"]/div[3]';

@@ -158,8 +161,8 @@ public function doTestRender($entities) {
+    $result = $this->xpath('//div[@class = "' . $view_class .'"]/div[1]');

@@ -167,7 +170,8 @@ public function doTestRender($entities) {
+    $result = $this->xpath('//div[@class = "' . $view_class .'"]/div[3]');

+++ b/core/modules/views/src/Tests/Handler/AreaViewTest.php
@@ -44,7 +44,7 @@ public function testViewArea() {
+    $this->assertTrue(strpos($output, 'view-dom-id-'. $view->dom_id) !== FALSE, 'The test view is correctly embedded.');

Minor: concatenating should always have spaces around the dot per https://www.drupal.org/coding-standards#concat.

davidhernandez’s picture

It's not a webtest, it is extending ViewUnitTestBase. So it is not setting a theme? Even though it is checking markup. We could probably get it to use Classy, but I think that is the wrong direction. We want to remove the reliance on Classy in tests, not add more. What would be better is to not have these tests verify output by looking for a CSS class.

Regarding the js- prefix. It is the only way to get the class out of the core template. If we split them here, we can remove the use for styling in the core template. The one downside, since we'd have the change the javascript, is we'd have to make changes to Pager. It doesn't look that bad though. One line changes to a js file, two templates, and a test or two.

Manuel Garcia’s picture

@dawehner Yeah i couldn't think of a way to make the test easier to read :S

@Cottser thanks! Fixing that on this patch now.

@davidhernandez I agree about the tests. Not sure I follow, but in my opinion we should tackle switching to js- css classes on a separate issue.

mortendk’s picture

@manuel go with the js-prefix so we get it fixed right away :)
is what our documentation is also saying

Manuel Garcia’s picture

Alright, the attached patch includes the following:
Replaced all instances of:

  • view-dom-id- with js-view-dom-id-
  • pager__items with js-pager__items

I did not tackle the classes on views-view-table.html.twig (responsive-enabled and sticky-enabled) because these are not views specific, but used throughout core, so perhaps we should change those on a separate issue.

dawehner’s picture

+++ b/core/modules/system/templates/pager.html.twig
@@ -34,7 +34,7 @@
-    <ul class="pager__items">
+    <ul class="js-pager__items">

So this is super confusing, honestly. For me we basically loose quite some of the semanticness of those css classes? Maybe this is simply something we don't care about?

davidhernandez’s picture

I should have explained this better. Apologies. See here for some background on the js- prefixing. #2431671: [meta] Add in js- prefixed classes for separation of JS & CSS functionality

Instead of changing the CSS class to have a prefix, add another class with the prefix. So we end up with:

<ul class="js-pager__items pager__items">

The CSS should remain unchanged, and use .pager__items. The JS is changed to use js-pager__items. This way we can leave the js- class in the core template, but remove the class that adds styles. This allows us to remove all the styling from the core template, but maintain the JS functionality.

Also, I'm thinking it isn't necessary to add the js- prefix to the dom-id classes, since they aren't being used for styles.

star-szr’s picture

I think we should especially add the js- prefix to the dom-id classes, because frankly I'm sick of explaining to people what they are for ;P

Manuel Garcia’s picture

Rerolling because #2187113: Incorrect usage of attributes in twig templates resulting in possible duplicate attributes. got in.

@davidhernandez thanks for the explanation, I will tackle that next (.pager__items)

I agree with Cottser that we should add the js- prefix to the dom-id classes... it makes a lot of sense to me to add the prefix because they are only used for javascript.

Manuel Garcia’s picture

Here it is without removing pager__items from the system pager nor classy, and adding js- prefix to all.

I manually tested that ajax enabled views minipager, normal pager and exposed filters work.

I am now getting failures on AggregatorRenderingTest and PagerTest, but I don't understand why. The class being tested for is still in the core template, we're just adding a new one... let's see if the bot finds the same, if it does I could use some help figuring this out.

Status: Needs review » Needs work

The last submitted patch, 32: remove_classes_from-2349775-32.patch, failed testing.

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
18.58 KB
2.06 KB

OK, learning a bit of xpath madness along the way. Hopefully this one will come back green.

brahmjeet789’s picture

Status: Needs review » Needs work

The last submitted patch, 35: remove_classes_from-2349775-35.patch, failed testing.

davidhernandez’s picture

@brahmjeet789, what were you trying to improve with your patch? Please leave a comment and an interdiff so we know what you were trying to do.

davidhernandez’s picture

Looking at #34 it looks like a few templates were missed.

views-view-grid.html.twig
views-view-summary.html.twig
views-view-summary-unformatted.html.twig

Probably somethings can be removed from views-view-table.html.twig. I'm not sure if we want to remove the row and column classes, but there are views-field- type classes that can probably go. There are a few other templates to fix. I didn't list them all.

Manjit.Singh’s picture

removing classes from :
views-view-grid.html.twig
views-view-summary.html.twig
views-view-summary-unformatted.html.twig

@davidhernandez have we need to remove classes from classy's view templates also ? For now i have removed only from /core/modules/views/templates/. Please verify.

Manjit.Singh’s picture

Status: Needs work » Needs review

forget to trigger test bot :)

davidhernandez’s picture

@Manjit, no, do not remove classes from Classy templates.

Manjit.Singh’s picture

ok !! then patch would be fine i guess :)

Manuel Garcia’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/views/templates/views-view-grid.html.twig
    @@ -28,16 +28,12 @@
    -    'views-view-grid',
    ...
    -      'views-row',
    
    @@ -45,7 +41,6 @@
    -      'views-col',
    

    We should manually verify (using stark theme) that the grid actually works as a grid without these classes. To me it would make no sense to remove these if the grid style stops working without them.

  2. +++ b/core/modules/views/templates/views-view-grid.html.twig
    @@ -28,16 +28,12 @@
         options.alignment,
    -    'cols-' ~ options.columns,
    -    'clearfix',
       ]
    

    This would break the alignment options functionality, again, we should manually test this using stark.

  3. +++ b/core/modules/views/templates/views-view-summary-unformatted.html.twig
    @@ -21,7 +21,7 @@
    -  {{ options.inline ? '<span' : '<div' }} class="views-summary views-summary-unformatted">
    +  {{ options.inline ? '<span' : '<div' }} >
    
    +++ b/core/themes/classy/templates/views/views-view-summary.html.twig
    @@ -18,8 +18,8 @@
    -<div class="item-list">
    -  <ul class="views-summary">
    +<div>
    +  <ul>
    

    Yes, totally missed those earlier.. thanks!

saki007ster’s picture

Manually tested this and alignment does break in the stark theme. See the screenshot of stark theme - admin people view in grid view with and without classes.

saki007ster’s picture

Updated the patch

saki007ster’s picture

Status: Needs work » Needs review
saki007ster’s picture

Assigned: saki007ster » Unassigned
Manuel Garcia’s picture

Status: Needs review » Needs work

Thanks @saki007ster for the testing and the updated patch.

On the interdiff:

+++ b/core/modules/views/templates/views-view-summary-unformatted.html.twig
@@ -21,7 +21,7 @@
-  {{ options.inline ? '<span' : '<div' }} >
+  {{ options.inline ? '<span' : '<div' }} class="views-summary views-summary-unformatted">

+++ b/core/modules/views/templates/views-view-summary.html.twig
@@ -20,8 +20,8 @@
-<div>
-  <ul>
+<div class="item-list">
+  <ul class="views-summary">

These should be ok to be removed in my opinion.

saki007ster’s picture

Status: Needs work » Needs review
FileSize
20.21 KB
755 bytes

@Manuel Garcia updated the patch and interdiff.

Manuel Garcia’s picture

Thank you @saki007ster - I have fixed just a tiny missing space for coding standards, and reviewed all other templates on core/modules/views/templates/ directory, nothing else to do that I can see. I'd say this patch is good to go!

tombo’s picture

I'm reviewing this patch

tombo’s picture

Added screenshots for grid, pager item

tombo’s picture

formatted list screenshot

tombo’s picture

screenshots for more link, unformatted, table display. these seem fine. I'm done adding screenshots.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/system/templates/pager.html.twig
@@ -34,7 +34,7 @@
-    <ul class="pager__items">
+    <ul class="pager__items js-pager__items">

It seems alright now even it is a bit sad to have both classes available.

Manuel Garcia’s picture

thanks @tombo for the screenshots!
@dawehner thnx for rtbcing! - the reason to have both classes is to make it simpler to remove all styling form the core template, keeping the js functionality (see comment #29).

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/views/tests/modules/views_test_data/templates/views-view--frontpage.html.twig
    @@ -11,7 +11,7 @@
      *     - view-[css_name]
      *     - view-id-[view_name]
      *     - view-display-id-[display_name]
    - *     - view-dom-id-[dom_id]
    + *     - js-view-dom-id-[dom_id]
    

    Are we sure that this documentation is correct? Afaics this will now have no classes at all. I know this is not introduced by this patch but we are changing a line here.

  2. +++ b/core/themes/classy/templates/views/views-view-summary.html.twig
    @@ -18,8 +18,8 @@
    -<div class="item-list">
    -  <ul class="views-summary">
    +<div>
    +  <ul>
    
    +++ b/core/themes/classy/templates/views/views-view.html.twig
    @@ -36,7 +36,7 @@
    -    dom_id ? 'view-dom-id-' ~ dom_id,
    

    Why are we removing classes from classy?

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
19.41 KB
1.35 KB

Thanks @alexpott for the input,

About 1. - Good point, I've updated the documentation on that to be a little more generic, since not all classes are for styling purposes now. If anyone has a better idea on what to say here let me know.

About 2. -

+++ b/core/themes/classy/templates/views/views-view-summary.html.twig
@@ -18,8 +18,8 @@
-<div class="item-list">
-  <ul class="views-summary">
+<div>
+  <ul>

Good catch, that change got introduced on #39 and only @davidhernandez noticed... oops! I've moved that out of this patch now.

+++ b/core/themes/classy/templates/views/views-view.html.twig
@@ -36,7 +36,7 @@
-    dom_id ? 'view-dom-id-' ~ dom_id,

We're actually changing that for the new js- prefixed one, so not a removal ;)

Manjit.Singh’s picture

Status: Needs review » Reviewed & tested by the community

Changes in #58 looks fine.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 1827c1e and pushed to 8.0.x. Thanks!

+++ b/core/modules/views/tests/modules/views_test_data/templates/views-view--frontpage.html.twig
@@ -5,13 +5,12 @@
  * - attributes: Remaining HTML attributes for the element including:
- *   - class: HTML classes that can be used to style contextually
- *     through CSS, including:
+ *   - class: HTML classes including:
  *     - view
  *     - view-[css_name]
  *     - view-id-[view_name]
  *     - view-display-id-[display_name]
- *     - view-dom-id-[dom_id]
+ *     - js-view-dom-id-[dom_id]

I think we should just copy the text from views-view.html.twig. ie attributes: Remaining HTML attributes for the element. And considering this is test code I think we should fix it here. Fixed on commit.

  • alexpott committed 1827c1e on 8.0.x
    Issue #2349775 by Manuel Garcia, saki007ster, mortendk, Manjit.Singh,...
nod_’s picture

Issue tags: +JavaScript
Manuel Garcia’s picture

Cheers @alexpott!

Status: Fixed » Closed (fixed)

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

brahmjeet789’s picture