Comments

Anonymous’s picture

Title: Class HTML attribute is present iven when no class is assigned to the list » Class HTML attribute is present even when no class is assigned to the list
dawehner’s picture

Issue tags: +Novice, +VDC

It would be great for people to fix the issue if you woul have provided a view configuration which results in such an output, but I guess people will be able to figure out.

kirby14’s picture

Status: Active » Needs review
StatusFileSize
new1.55 KB

This fixes it for me. I applied the same logic to the $wrapper_class as well. Views adds a default wrapper class but if you clear it out, it also adds an empty class tag.

kirby14’s picture

StatusFileSize
new417 bytes

Missed a new line for coding standards.

kirby14’s picture

StatusFileSize
new415 bytes

Last diff added the new line AND unwanted spaces. Time to find a better editor.

dawehner’s picture

Version: 8.0-alpha8 » 8.x-dev

Let's try to write a patch as well, so this never happens in the future.

kirby14’s picture

Let's try to write a patch as well, so this never happens in the future.

I assume you mean a test? If so, I'll see what I can do. I'm new to drupal's test framework.

dawehner’s picture

Ups, yeah indeed.

kirby14’s picture

So we would want a test that verifies we don't have an empty class on any field for all of Views, right? Not just for the HTML list?

lhangea’s picture

I cannot reproduce the bug.

Here are the steps I took:
1. Installed the latest version of D 8.x
2. Created an article and a basic page
3. Created a view listing published content.

Result: Cannot find any ul html tag on my page (inspected with firebug).

lhangea’s picture

Never mind. The issue applies if we select the format of the view to be HTML list.

lhangea’s picture

I reviwed the working patches from #3 and #5 and they work, everything's fine about them but I thought it would be nice to have them both in one .patch file and made a new patch combining those two patches.

amool’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new15.34 KB
new15.2 KB
amool’s picture

StatusFileSize
new21.4 KB

Previous comment submitted by mistake. It was incomplete.

So, This is how I tested the patch. It works!
1. Created sample content of content-type `article`
2. Created a view and selected display as "HTML List"
3. when browsed to the view the html generated is as show:

test 1

4. applied patch and then then the html generated is as shown:
test 2

5. Under "Format Settings for that view" added `custom-list-class` to "List Class". HTML generated is as shown.
test 3

Anonymous’s picture

Shouldn't Attribute class handle empty attributes?

tstoeckler’s picture

Re #15: For some attributes, i.e. data attributes (and others) empty attributes *should* be displayed, it's just that for class it doesn't make any sense.

Anonymous’s picture

#16 wouldnt be better to NOT display empty attributes and those attributes that needs to be displayed without value a boolean TRUE would be used as value? At least that makes sense to me.

tstoeckler’s picture

Again, that's not necessarily correct. <div data-foo> is totally correct and wanted markup whereas <div data-foo="whatever"> is not as correct/semantic.

webchick’s picture

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

Looks like this is still in need of an automated test, per #6/8. #14 looks like it has some good steps to reproduce.

Also, minor, but if we could clean this up in the next re-roll:

+++ b/core/modules/views/views.theme.inc
@@ -944,20 +944,27 @@ function template_preprocess_views_view_list(&$variables) {
+  if($handler->options['class']) {
...
+  if($handler->options['wrapper_class']) {
...
+  if(isset($class)) {

Should have a space separating "if" from "("

visabhishek’s picture

Status: Needs work » Needs review
StatusFileSize
new1.62 KB

As per #14, patch looks good and working fine , as per #19 i am uploading patch after cleanup.

kirby14’s picture

+++ b/core/modules/views/views.theme.inc
@@ -944,20 +944,26 @@ function template_preprocess_views_view_list(&$variables) {
+  if(isset($class)) {
+    $variables['list']['attributes'] = new Attribute(array('class' => $class));
+  }

I think the space should be added here as well?

lhangea’s picture

Patch with correct spacing for if statements.

shkodrava’s picture

Status: Needs review » Reviewed & tested by the community

Patch #22 worked for me.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

This still seems to lack a test. It seems like you could take one of the existing tests and check the output to make sure there's no extra class output?

jayeshanandani’s picture

Assigned: Unassigned » jayeshanandani

Working on tests!

ACF’s picture

Added a test to check for this and a patch to with the fix as well.

The last submitted patch, 26: empty-class-attr-html-list-views-removed-2197091-test.patch, failed testing.

dawehner’s picture

  1. +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleHtmlListTest.php
    @@ -0,0 +1,50 @@
    + * Definition of Drupal\views\Tests\Plugin\StyleHtmlListTest.
    

    Nitpick alarm, sorry. We do use now @file\nContains ... all over the place, but forget to convert some places. anyone wants to volunteer to convert all the other instances?

  2. +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleHtmlListTest.php
    @@ -0,0 +1,50 @@
    +class StyleHtmlListTest extends StyleTestBase {
    

    Just a quick note: you should be able to use ViewUnitTestBase which executes much faster

  3. +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleHtmlListTest.php
    @@ -0,0 +1,50 @@
    +    $view = Views::getView('test_view');
    +    $view->setDisplay();
    +    $style = $view->display_handler->getOption('style');
    +    $style['type'] = 'html_list';
    +    $style['options']['class'] = '';
    +    $view->display_handler->setOption('style', $style);
    

    I guess we want to provide some configured view instead.

  4. +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleHtmlListTest.php
    @@ -0,0 +1,50 @@
    +
    +    // Check that an empty class attribute is not added if no class has been set.
    +    $this->assertTrue(strpos($output, '<ul>') !== FALSE, 'Make sure no empty class is added to UL when no class is set');
    

    This approach of testing is a bit odd, but it certainly works.

smira’s picture

here is some initial improvements on the test patch
wanted to implement more of the changes that dawehner suggested but this seems to work as it is a copy of Drupal\views\Tests\Plugin\StyleUnformattedTest
maybe catch me on irc if you think it needs more work and maybe point me in the right direction?
THank you :)

Status: Needs review » Needs work
undertext’s picture

Status: Needs work » Needs review
StatusFileSize
new4.22 KB

Rewrote test. Please review.

undertext’s picture

Any feedback?

heiket’s picture

heiket’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Drupal8NZ
StatusFileSize
new54.47 KB

Tested and works as described:
1) no class was set (no empty class tag) with no class assigned
2) custom classes on row and list came through after they were assigned

I hope this is helpful. Sorry about the screenshots in 2 comments : (. Still getting my head around how to embed those...

(review and testing part of #Drupal8NZ)

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I think we can simply the preprocess function and have less if's by doing something like:

diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc
index 2a23621..4d9fee3 100644
--- a/core/modules/views/views.theme.inc
+++ b/core/modules/views/views.theme.inc
@@ -901,23 +901,17 @@ function template_preprocess_views_view_list(&$variables) {
   if ($handler->options['class']) {
     $class = explode(' ', $handler->options['class']);
     $class = array_map('drupal_clean_css_identifier', $class);
+    // Initialize a new attribute class for $class.
+    $variables['list']['attributes'] = new Attribute(array('class' => $class));
   }
 
   // Fetch wrapper classes from handler options.
   if ($handler->options['wrapper_class']) {
     $wrapper_class = explode(' ', $handler->options['wrapper_class']);
-    $wrapper_class = array_map('drupal_clean_css_identifier', $wrapper_class);
+    // Initialize a new attribute class for $wrapper_class.
+    $variables['attributes']['class'] = array_map('drupal_clean_css_identifier', $wrapper_class);
   }
 
-  // Initialize a new attribute class for $wrapper_class.
-  if (isset($wrapper_class)) {
-     $variables['attributes']['class'] = $wrapper_class;
-   }
-
-  // Initialize a new attribute class for $class.
-  if (isset($class)) {
-    $variables['list']['attributes'] = new Attribute(array('class' => $class));
-  }
   $variables['list']['type'] = $handler->options['type'];
 
   template_preprocess_views_view_unformatted($variables);

Also lets improve the test to check that adding a class and a wrapper class works as expected since we've changed that code.

undertext’s picture

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

Thanks for reviewing. Here is new patch.

m1r1k’s picture

Issue tags: +#ams2014contest
star-szr’s picture

Assigned: jayeshanandani » Unassigned
Status: Needs review » Needs work
Issue tags: -
+++ b/core/modules/views/src/Tests/Plugin/StyleHtmlListTest.php
@@ -0,0 +1,58 @@
+    //Check that an empty class attribute is not added if the wrapper class is
+    //not set.
...
+    //Check that an empty class attribute is not added if the list class is
+    //not set.
...
+    //Set wrapper class and list class in style options.
...
+    //Check that class attribute is present if the wrapper class is set.
...
+    //Check that class attribute is present if the list class is set.

These comments need spaces after the // added per https://www.drupal.org/node/1354#inline

hussainweb’s picture

Status: Needs work » Needs review
StatusFileSize
new3.31 KB
new5.02 KB

I fixed the comments as per #38. I also changed assertion comments to make them shorter and simpler and made a few other whitespace changes. There is an interdiff attached too.

heiket’s picture

Assigned: Unassigned » heiket
Status: Needs review » Needs work

Assigned to me for re-test > I am going to run another simplytest.me test before re-set to reviewed and tested by community

heiket’s picture

Assigned: heiket » Unassigned
Status: Needs work » Reviewed & tested by the community
StatusFileSize
new26.99 KB
new24.5 KB

retested as per #34
without class

with class

working as described! Ta.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 0d1b898 and pushed to 8.0.x. Thanks!

  • alexpott committed 0d1b898 on 8.0.x
    Issue #2197091 by kirby14, undertext, lhangea, hussainweb, ACF, smiro,...

Status: Fixed » Closed (fixed)

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