Problem/Motivation

If no content types are available, the list displays the possibly wrong text: There is no Content type yet., while it should be at least No content types available.

Proposed resolution

Looks like there's a correct logic in NodeTypeListBuilder class, but it doesn't get picked up (see the render() function).

  public function render() {
    $build = parent::render();
    $build['#empty'] = t('No content types available. <a href="@link">Add content type</a>.', array(
      '@link' => $this->urlGenerator->generateFromPath('admin/structure/types/add'),
    ));
    return $build;
  }
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

meramo’s picture

Issue summary: View changes
drubb’s picture

Status: Active » Needs review
FileSize
720 bytes

It was just the wrong render element used in the build function. Here's the patch!

drubb’s picture

FileSize
16.48 KB
larowlan’s picture

This is a duplicate

drubb’s picture

Duplicate of which issue? It's similar to https://www.drupal.org/node/2454309, but that deals with content, not content types.

darol100’s picture

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

@larowlan, if you believe this is a duplicated please provide the link for the duplicated issue.

@drubb, great work it seem to be working fine.

I have tested this patch and seem to be working fine. I have attached an image of the results of this patch.

alexpott’s picture

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

Let's add an assertion to a test for this.

darol100’s picture

@alexpott,

Its unclear to me what is the next step. If you can provide me a link for what type of testing it needs I might be able to help testing this patch.

m4olivei’s picture

Status: Needs work » Needs review
FileSize
1.96 KB

How about something like this for a test? I created a new test class for node module, b/c I didn't want to inherit the setup from NodeTestBase. If I did I would have had to delete the Page and Article types which are defined there. Let me know if I'm off base. Otherwise, this seems like a good enough test.

adriancotter’s picture

Status: Needs review » Reviewed & tested by the community

epophoto and I tested this at DrupalConLA.

image415’s picture

I tested this at DrupalConLA

willzyx’s picture

webchick’s picture

Status: Reviewed & tested by the community » Needs work

This is exactly the kind of thing that we're looking for, except that by making it its own test extending from WebTestBase it's going to incur a Drupal installation/teardown, which is quite expensive. Is it possible to look for an existing test that's already hitting the admin/structure/types page where we could simply add the assertion there?

smccabe’s picture

Slim picking for tests to piggyback off of, nearly all of them create content types as part of setup.

Few not-so-great candidates I found

NodeBodyFieldStorageTest
NodeCacheTagsTest
NodeFieldAccessTest
NodeFieldOverrridesTest
NodeListBuilderTest

None of these really have anything to do with content types though and none of them seem suitable generic.

willzyx’s picture

@all as suggested by @tim.plunkett can we please combine this issue with #2490290: Subclasses of EntityListBuilder incorrectly override the #empty message and fix all of the subclasses of EntityListBuilder at once?

@smccabe could NodeTypeTest or NodeAdminTest be candidate? we simply need to delete the Page and Article node types before test the empty message

smccabe’s picture

@willzyx I agree one of those makes a lot more sense logically, I just wasn't sure about undoing the setup, possibly screwing up additional tests that get added. What would be the best option, to remove the content types, run the test and then re-add them so additional tests still have the correct setup?

sumitmadan’s picture

Status: Needs work » Needs review

Changed #9 patch according to @webchick said. I have added the test in NodeTypeTest and also changed NodeTypeListBuilder as per #2490290: Subclasses of EntityListBuilder incorrectly override the #empty message.

sumitmadan’s picture

Oops!!! Forgot to upload the patch.

joshi.rohit100’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/node/src/Tests/NodeTypeTest.php
    @@ -22,7 +23,7 @@ class NodeTypeTest extends NodeTestBase {
    -  public static $modules = array('field_ui');
    +  public static $modules = array('node', 'field_ui');
    

    Should be short array syntax here.

  2. +++ b/core/modules/node/src/Tests/NodeTypeTest.php
    @@ -202,6 +203,20 @@ public function testNodeTypeFieldUiPermissions() {
    +    $this->assertRaw(t('No content types available. <a href="@link">Add content type</a>.', array(
    +        '@link' => Url::fromRoute('node.type_add')->toString()
    +      )), 'Empty text when there are no content types in the system is correct.');
    

    same here (short array syntax)

The last submitted patch, 18: wrong_text_if_no-2473215-17.patch, failed testing.

joshi.rohit100’s picture

As NodeTypeTest class extends the NodeTestBase, and you can see that in setup, Article and Page content types are created. So in your test case, You should first delete those two bundles.

Also I think that the new test case method name be testNoNodeContentType (just thought).

smccabe’s picture

Status: Needs work » Needs review
FileSize
4.45 KB

updated test to remove the content types and then re-add after the tests are done.

smccabe’s picture

@joshi.rohit100 im not sure why you suggest short array syntax for those sections, when I looked at any other tests they don't use short array syntax either. Is this something new that is being changed for D8?

cilefen’s picture

@smccabe

I think the working policy is to use short array syntax if the array in question is in the issue scope.

smccabe’s picture

Ah I see, try to update if you're doing new stuff but not doing the mass convert of everything. I will update the patch when I get a chance.

https://www.drupal.org/node/2135291

googletorp’s picture

Issue summary: View changes
googletorp’s picture

Fixed the short array syntax.

jmolivas’s picture

Issue summary: View changes
FileSize
114.74 KB
87.65 KB

I have tested this patch and seem to be working fine, I have attached an image of the results of this patch:

2473215_admin-structure-types

And the result of running phpunit:

./vendor/bin/phpunit --group node

2473215_test.png

jmolivas’s picture

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

Remove embedding images and status update

joshi.rohit100’s picture

I am just curious why we re-added the node module in NodeTypeTest class as it is already added in parent class ?

@smccabe : I just suggested the short array syntax as it is new patch policy.

smccabe’s picture

FileSize
4.41 KB

removed unneeded node module included

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/node/src/Tests/NodeTypeTest.php
@@ -202,6 +203,34 @@ public function testNodeTypeFieldUiPermissions() {
+    //Add content types back in so other tests have the expected environment
+    $this->drupalCreateContentType([
+      'type' => 'page',
+      'name' => 'Basic page',
+      'display_submitted' => FALSE,
+    ]);
+    $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);

Not needed.

@jmolivas running PHPUnit doesn't run the test added by this patch - unfortunately. It's a web test.

joshi.rohit100’s picture

Status: Needs work » Needs review
FileSize
3.99 KB
1020 bytes
googletorp’s picture

Thanks @joshi.rohit100 RTBC when turns green.

googletorp’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs tests

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 34d3c8c and pushed to 8.0.x. Thanks!

  • alexpott committed 34d3c8c on 8.0.x
    Issue #2473215 by smccabe, joshi.rohit100, googletorp, drubb, sumitmadan...

Status: Fixed » Closed (fixed)

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