Problem

The empty text "No content available" appears twice in the content view:

Steps to replicate:

  1. Install the minimal profile.
  2. Enable Views
  3. Go to admin/content

Proposed resolution

Make sure it only appears once.

Remaining tasks

Repair. Test. Commit.

User interface changes

None.

API changes

None.

Data model changes

None.

CommentFileSizeAuthor
double-empty-text.png13.49 KBpfrenssen
#8 Screen Shot 2017-02-25 at 13.52.54.png88.08 KBmarthinal
#8 2578251-8.patch722 bytesmarthinal
#14 2578251-14.patch1011 bytesmarthinal
#16 empty-results-twice-2578251-16.patch586 bytesmarthinal
#19 2578251-19.patch648 bytesmarthinal
#24 2578251-24.patch9.52 KBjoe_carvajal
#27 no_results_text_appears-2578251-27.patch1.92 KBluismagr
#31 no_results_text_appears-2578251-30.patch1.99 KBShreya Shetty
#33 interdiff-31-33-2578251.txt3.88 KBmarthinal
#33 2578251-33-only-test-should-fail.patch1.41 KBmarthinal
#33 2578251-33.patch1.88 KBmarthinal
#37 2578251-37-only-test-should-fail.patch1.41 KBeporama
#37 2578251-37.patch2.39 KBeporama
#37 interdiff-33-37-2578251.txt962 byteseporama
#42 2578251-42.patch2.38 KBJohn Cook
#42 interdiff-37-42.txt1.46 KBJohn Cook
#43 Content Minimal site Before patch.png58.19 KBDinesh18
#43 Content Minimal site after patch.png55.49 KBDinesh18
#49 interdiff-42-49.txt541 bytesAda Hernandez
#49 2578251-49.patch2.37 KBAda Hernandez
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pfrenssen created an issue. See original summary.

alexpott’s picture

I think might be a duplicate of #2570895: FieldPluginBase can duplicate a suffix

pfrenssen’s picture

I checked if this was perhaps a duplicate of #2570895: FieldPluginBase can duplicate a suffix, but the patch in that issue doesn't solve this.

joyceg’s picture

Assigned: Unassigned » joyceg

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

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should 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.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should 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.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should 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.

marthinal’s picture

I had the same problem working on my current project.

From \Drupal\views\Plugin\views\display\DisplayPluginBase::elementPreRender() when a view is empty we add the #empty property but also we add the #empty property when building the form:

    if ($view->hasFormElements()) {
      // Only render row output if there are rows. Otherwise, render the empty
      // region.
      if (!empty($element['#rows'])) {
        $output = $element['#rows'];
      }
      else {
        $output = $element['#empty'];
      }

      $form_object = ViewsForm::create(\Drupal::getContainer(), $view->storage->id(), $view->current_display, $view->args);
      $form = \Drupal::formBuilder()->getForm($form_object, $view, $output);
      // The form is requesting that all non-essential views elements be hidden,
      // usually because the rendered step is not a view result.
      if ($form['show_view_elements']['#value'] == FALSE) {
        $element['#header'] = array();
        $element['#exposed'] = array();
        $element['#pager'] = array();
        $element['#footer'] = array();
        $element['#more'] = array();
        $element['#feed_icons'] = array();
      }

      $element['#rows'] = $form;
    }

If we have a form we don't need to add the value #empty again to the output but let's see the result of the tests.

marthinal’s picture

Status: Active » Needs review
marthinal’s picture

Assigned: joyceg » Unassigned
Issue tags: +Needs tests

Assigned to @joyceg 1 year ago... I'm going to work on it. Needs tests.

marthinal’s picture

Assigned: Unassigned » marthinal

Status: Needs review » Needs work

The last submitted patch, 8: 2578251-8.patch, failed testing.

marthinal’s picture

Version: 8.3.x-dev » 8.4.x-dev
marthinal’s picture

Status: Needs work » Needs review
Issue tags: +drupaldevdays
FileSize
1011 bytes

Let's try again.

Status: Needs review » Needs work

The last submitted patch, 14: 2578251-14.patch, failed testing.

marthinal’s picture

Status: Needs work » Needs review
FileSize
586 bytes
joe_carvajal’s picture

Status: Needs review » Reviewed & tested by the community

#16 works like a charm.

The text appears duplicated before the patch, and it deletes one of them.

I'll work in the test.

joe_carvajal’s picture

Status: Reviewed & tested by the community » Needs review

Sorry for the status change. I'll do the test.

marthinal’s picture

@joe_carvajal Great thanks!

Anyway I think we could verify that the empty behaviors are empty. Let's try this patch.

marthinal’s picture

Assigned: marthinal » Unassigned

Feel free to work on the test then. We need to parse and verify that the *Empty text* only appears once.

joe_carvajal’s picture

I tried it, but I don't know how to perform this test. I won't work in this issue from now on.

joe_carvajal’s picture

Assigned: Unassigned » joe_carvajal

I talked with marthinal and I'll try again :)

joe_carvajal’s picture

To reproduce the issue you only need to add at least an exposed filter.

joe_carvajal’s picture

I added a view that reproduces the error, but the test isn't created yet.

marthinal’s picture

Status: Needs review » Needs work
joe_carvajal’s picture

Assigned: joe_carvajal » Unassigned
luismagr’s picture

I've worked on this issue and when the patch is not applied, the test also receive the text message once. If you access to the view through the navigator, you can see the message twice but only once in the test.

I attach the patch without the testing view created by @joe_carvajal (also thanks for that view). I have created the test getting directly the path /admin/content.

Thanks to @marthinal for his support. I really appreciate it. You are awsome!

idebr’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
dawehner’s picture

+++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
@@ -2195,6 +2195,9 @@ public function elementPreRender(array $element) {
+      if (!empty($element['#view']->empty)) {
+        $element['#empty'] = [];
+      }

It'd be kinda nice to have some documentation about what is going on here :)

dawehner’s picture

Status: Needs review » Needs work
Shreya Shetty’s picture

Status: Needs work » Needs review
FileSize
1.99 KB

Hi @dawehner i have made the improvement as per your suggestion . Please find the patch for the same

amit.drupal’s picture

Step to test patch #31
1 - Install the minimal profile.
2 - Enable Views
3 - Go to admin/content and create content type and add new content.
4 - Go to admin/content page and filter "Published status" and found "No content available." text display in two times.
5 - Apply patch #31 and again display same page and found "No content available." text display in one time.

Issues is resolve and patch working fine

marthinal’s picture

As discussed with @dawehner, the test should fail and we cannot reproduce the problem from the default theme (classy). We change the theme from the setup and I added logic to the tpl to only render the empty results when rows are empty.

The last submitted patch, 33: 2578251-33-only-test-should-fail.patch, failed testing.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/views/templates/views-view.html.twig
@@ -51,8 +51,12 @@
-  {{ empty }}
+  {% if rows %}
+      {{ rows }}
+  {% elseif empty %}
+      {{ empty }}
+  {% endif %}
+

The only problem I have with that is that this doesn't fix the problem with custom templates. I assume this is fine.

star-szr’s picture

Status: Reviewed & tested by the community » Needs work

The template in Classy already has this logic so it doesn't need to be updated.

+++ b/core/modules/views/templates/views-view.html.twig
@@ -51,8 +51,12 @@
-  {{ rows }}
-  {{ empty }}
+  {% if rows %}
+      {{ rows }}
+  {% elseif empty %}
+      {{ empty }}
+  {% endif %}

This is a case where we should actually update Stable too since it's not changing markup but fixing a bug with the display logic.

Also, the {{ rows }} and {{ empty }} are indented by two spaces too many. Looks to be indented four spaces instead of two.

eporama’s picture

Added the same logic to Stable views-view.html.twig and fixed the indents.

Only question is whether there needs to be a specific test for Stable.

The last submitted patch, 37: 2578251-37-only-test-should-fail.patch, failed testing.

John Cook’s picture

Status: Needs review » Reviewed & tested by the community

I've tested the patch from #37.

This works as shown by marthinal's image in #8.

I removed the fix and ran the test and got this:

$ php core/scripts/run-tests.sh --verbose --class "Drupal\views\Tests\Plugin\ViewsNoResultsBehaviorTest"

Drupal test run
---------------

Tests to be run:
  - Drupal\views\Tests\Plugin\ViewsNoResultsBehaviorTest

Test run started:
  Saturday, May 13, 2017 - 14:27

Test summary
------------

Drupal\views\Tests\Plugin\ViewsNoResultsBehaviorTest          10 passes   1 fails                  3 messages
- Found database prefix 'test41674918' for test ID 4.

Test run duration: 33 sec

Detailed test results
---------------------


---- Drupal\views\Tests\Plugin\ViewsNoResultsBehaviorTest ----


Status    Group      Filename          Line Function                            
--------------------------------------------------------------------------------
⋮
Fail      Other      ViewsNoResultsBeh   42 Drupal\views\Tests\Plugin\ViewsNoRe
    Only one message should be present
    Value 1 is equal to value 2.

With the fix re-instated:

$ php core/scripts/run-tests.sh --verbose --class "Drupal\views\Tests\Plugin\ViewsNoResultsBehaviorTest"

Drupal test run
---------------

Tests to be run:
  - Drupal\views\Tests\Plugin\ViewsNoResultsBehaviorTest

Test run started:
  Saturday, May 13, 2017 - 14:28

Test summary
------------

Drupal\views\Tests\Plugin\ViewsNoResultsBehaviorTest          11 passes                            3 messages

Test run duration: 33 sec

Detailed test results
---------------------


---- Drupal\views\Tests\Plugin\ViewsNoResultsBehaviorTest ----


Status    Group      Filename          Line Function                            
--------------------------------------------------------------------------------
⋮
Pass      Other      ViewsNoResultsBeh   42 Drupal\views\Tests\Plugin\ViewsNoRe
    Only one message should be present

(NB: I've removed passes that aren't applicable.)

This has a fix in Stable as requested by Cottser in #36.

This all looks good and is RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/views/src/Tests/Plugin/ViewsNoResultsBehaviorTest.php
    @@ -0,0 +1,45 @@
    +class ViewsNoResultsBehaviorTest extends ViewTestBase {
    

    This should be \Drupal\Tests\views\Functional\ViewTestBase

  2. +++ b/core/modules/views/templates/views-view.html.twig
    @@ -51,8 +51,12 @@
    +  {% if rows %}
    +    {{ rows }}
    +  {% elseif empty %}
    +    {{ empty }}
    +  {% endif %}
    

    Also I'm concerned about introducing extra spaces with the new templates? Should we be doing something like

      {% if rows -%}
        {{ rows }}
      {%- elseif empty -%}
        {{ empty }}
      {%- endif %}
    

    ?

  3. +++ b/core/modules/views/templates/views-view.html.twig
    @@ -51,8 +51,12 @@
    +
    

    How come the new line here?

star-szr’s picture

+++ b/core/modules/views/templates/views-view.html.twig
@@ -51,8 +51,12 @@
-  {{ rows }}
-  {{ empty }}
+  {% if rows %}
+    {{ rows }}
+  {% elseif empty %}
+    {{ empty }}
+  {% endif %}

+++ b/core/themes/stable/templates/views/views-view.html.twig
@@ -49,8 +49,11 @@
-  {{ rows }}
-  {{ empty }}
+  {% if rows %}
+    {{ rows }}
+  {% elseif empty %}
+    {{ empty }}
+  {% endif %}

Per @alexpott's point, to get this to output the same amount of whitespace the following should work:

{% if rows %}
  {{- rows }}
{% elseif empty %}
  {{- empty }}
{% endif %}

or

{% if rows -%}
{{ rows }}
{% elseif empty -%}
{{ empty }}
{% endif %}

I think the if's themselves don't need to be "trimmed", just the part before the variable is printed.

John Cook’s picture

Status: Needs work » Needs review
FileSize
2.38 KB
1.46 KB

From alexpott's comment in #40 I've:

  1. changed the test to inherit from Drupal\Tests\views\Functional\ViewTestBase
  2. added the triming using Cottser's option 2 in #41
  3. removed the extra empty line
Dinesh18’s picture

I have applied the patch mentioned in comment #42 and it works as expected.
PFA before and after patch screengrab.
Looks like RTBC.

Dinesh18’s picture

Status: Needs review » Reviewed & tested by the community

Changing the status to RTBC

cilefen’s picture

Status: Reviewed & tested by the community » Needs work

Thank you, everyone.

+++ b/core/modules/views/src/Tests/Plugin/ViewsNoResultsBehaviorTest.php
@@ -0,0 +1,45 @@
+class ViewsNoResultsBehaviorTest extends ViewTestBase {

This test seems out of place in the test hierarchy. Should it be somewhere in Drupal\Tests\views\Functional?

+++ b/core/modules/views/src/Tests/Plugin/ViewsNoResultsBehaviorTest.php
@@ -0,0 +1,45 @@
+  /**
+   * Setup test.
+   */

In other test classes, if setUp() has a Docblock at all, it's an {@inheritdoc}.

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.

webadpro’s picture

Patch #42 worked for me also.

Ada Hernandez’s picture

Status: Needs work » Needs review
FileSize
2.37 KB
541 bytes

#45 I added the docblock and it changed the test view to /functional namespace

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.

johnsicili’s picture

Patch #49 works for me. Thank you!

Vj’s picture

Status: Needs review » Reviewed & tested by the community

Issue can be reproduced by setting "Stark" as admin theme in standard profile install.

Patch works #49 and resolves issue.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 4284388 and pushed to 8.7.x. Thanks!

  • catch committed 4284388 on 8.7.x
    Issue #2578251 by marthinal, eporama, John Cook, Adita, joe_carvajal,...
DamienMcKenna’s picture

Is this something that could be backported to 8.6.x?

Status: Fixed » Closed (fixed)

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