Problem/Motivation

After enabling the node type example module and creating a new content item using the node edit form, the body field does not appear on the default display of the newly created node. Visiting the content type page and attempting to enable the body field results in the body field always reverting to disabled.

To reproduce:

  • Use Drupal 8.1.x. Examples works with the current stable release of Drupal.
  • Enable node_type_example module.
  • Add a node: node/add/basic_content_type
  • View the node you just added.
  • Note that the body is missing.
  • Edit the display of the content type: admin/structure/types/manage/basic_content_type/display
  • Note that the body field is disabled.
  • Edit the body field to be visible.
  • Clear the cache: admin/config/development/performance
  • View the node again.
  • The body is visible.

Proposed resolution

  • Rebuild the content type YAML files as per the instructions in node_type_example module. Perform this for both example content types.
  • Adjust code to make tests pass.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

toddtomlinson created an issue. See original summary.

toddtomlinson’s picture

Note: I'm running Drupal 8.3 when testing this. I started with a fresh install on 8.1.x and had the same problem though.

mile23’s picture

Issue summary: View changes

Thanks for filing the issue!

I think rebuilding the YAML files according to the instructions will be good enough. If it's not it will be interesting to find out what is.

jeevanbhushetty’s picture

Assigned: Unassigned » jeevanbhushetty

Working on it..

jeevanbhushetty’s picture

Assigned: jeevanbhushetty » Unassigned
Status: Active » Needs review
StatusFileSize
new1.72 KB

configuration file for default view mode was missing, added for both the content types.

While fixing this issue found another issue which will be fixed as a part of #2841250: On Uninstallling node_type_example configurations are not deleted, which leads to an error while re-enabling the module.

ajits’s picture

Status: Needs review » Needs work

As a standard, we use 2 space indentation in the yml files. Otherwise, looks okay :)

jeevanbhushetty’s picture

Assigned: Unassigned » jeevanbhushetty

Thanks @Ajit updating indents.

jeevanbhushetty’s picture

Assigned: jeevanbhushetty » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.62 KB

Updated the patch, as it will affect whole patch so not adding interdiff :)

ajits’s picture

Status: Needs review » Reviewed & tested by the community

Thank you!

mile23’s picture

Status: Reviewed & tested by the community » Needs work

Thanks.

We need a test that goes through the repo steps listed above.

Also, it looks like the patch adds new yaml but doesn't remove any old files. So are all the files necessary, or just the new ones?

jeevanbhushetty’s picture

Assigned: Unassigned » jeevanbhushetty

Hi @Mile, We need all YAML files, entity view mode YAML was missing added it.

Will add test for the steps in repo.

jeevanbhushetty’s picture

Assigned: jeevanbhushetty » Unassigned
Status: Needs work » Needs review
StatusFileSize
new3.02 KB

Added test as well.

gg24’s picture

Status: Needs review » Reviewed & tested by the community

Patch works as intended.

gg24’s picture

Status: Reviewed & tested by the community » Needs work

This is my observation, correct me if i am wrong that if the module is already enabled and we apply the patch. This doesn't update the existing configurations.

jeevanbhushetty’s picture

Status: Needs work » Needs review

Hi @gg24, As per my understanding whenever you update config or create new config you have to re-install the module to apply the new config. Simply applying patch won't work.

Steps to Test:

1. Disable the module
2. Apply the Path
3. Delete the config of module from config file (this is the issue of module which will be fixed in #2841250: On Uninstallling node_type_example configurations are not deleted, which leads to an error while re-enabling the module)
4. Enable the module
5. Test as per repo and added test case.

gg24’s picture

@jeevanbhushetty we can go for a better way for doing this, like adding a hook_update_N, you can refer here for more ideas: https://www.drupal.org/docs/8/api/update-api/updating-configuration-in-d...

gg24’s picture

Status: Needs review » Reviewed & tested by the community

As this module is Dev Release. It won't require any update hook. Changing Status to RTBC.

jeevanbhushetty’s picture

StatusFileSize
new3.12 KB
new1.26 KB

Add support to delete configuration from config table on uninstalling the module.

Issue of module uninstallation for older YAML files are solved in #2733739: Node Type Example fails to reinstall

  • Mile23 committed bd4b0bd on 8.x-1.x authored by jeevanbhushetty
    Issue #2795283 by jeevanbhushetty, gg24, toddtomlinson, AjitS: Node type...
mile23’s picture

Status: Reviewed & tested by the community » Fixed

Yah, we *don't* want hook_update_n() because we're only demonstrating that you can set up a content type as a yaml file.

Also, even though the test doesn't have all the steps of the repro instructions, it does demonstrate that the body field shows on the node default view, so we're OK as far as regressing this issue.

  • +++ b/node_type_example/src/Tests/NodeTypeExampleTest.php
    @@ -117,4 +117,34 @@ class NodeTypeExampleTest extends WebTestBase {
    +    $admin_user = $this->drupalCreateUser(array('administer content types'));
    

    We should only give the permissions we expect to need, which in this case would be 'create [type] content'. Changed on commit.

  • +++ b/node_type_example/src/Tests/NodeTypeExampleTest.php
    @@ -117,4 +117,34 @@ class NodeTypeExampleTest extends WebTestBase {
    +    // Create random strings to insert data into fields.
    +    $title = $this->randomMachineName(8);
    +    $body = $this->randomMachineName(16);
    

    Random names are somewhat harmful and can lead to intermittent failures, unless we're specifically testing for edge cases in field content. Let's just use a static string. Changed on commit.

Thanks folks!

Status: Fixed » Closed (fixed)

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