Problem/Motivation

When rendering entity reference field items (node, taxonomy_term, ...) it is impossible to override the view mode templates (node--teaser.html.twig, ...), meaning, although field wrappers can be controlled from the module, it does not provide sufficient markup control when rendering entities from entity reference field to fully remove HTML wrappers when rendering referenced field item content.

Steps to reproduce

Add an entity reference field to Manage Display and set the field Format to the Rendered entity. If rendered entity uses the twig template for the selected display mode (e.g., node--teaser.html.twig, ...) the template can add undesired wrapping markup.

Proposed resolution

Provide an option to remove item content wrappers when rendering entity reference filed item content, i.e., loop through field items, check for and override content #theme with no-wrappers template provided by fences module.

Remaining tasks

Review and community test the merge request.

User interface changes

Add Override Referenced Field Item Content Template Theme checkbox to Entity Reference type fields.
Field Item Content Only checkbox

Data model changes

Update configuration schema.

Issue fork fences-3321665

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

martins.bruvelis created an issue. See original summary.

martins.bruvelis’s picture

Issue summary: View changes

martins.bruvelis’s picture

Title: Provide an option to remove item content wrappers for Rendered entity field formatter. Display » Provide an option to remove item content wrappers for Rendered entity field formatter.
Status: Active » Needs review
anybody’s picture

Assigned: martins.bruvelis » Unassigned
Status: Needs review » Needs work

Thanks @martins.bruvelis, we'll have a look at this, as soon as the failing tests are fixed (NW for that).

@thomas.frobieter what do you think about this request? Does it make sense to you with your experience?

thomas.frobieter’s picture

I think this is a pretty good idea! But for sure, it should be disabled by default.

anybody’s picture

Thanks! :)

@martins.bruvelis some points for refinement then, as I think we will accept the additions as soon as everything is fine.

Please

  • check why existing tests fail. This should NOT be a breaking change (BC). Existing installations output may not change!
  • add test coverage for the new functionality to proof this works as expected
  • see the review comments

Thanks a lot in advance, nice work!

martins.bruvelis’s picture

martins.bruvelis’s picture

Status: Needs work » Needs review
martins.bruvelis’s picture

@Anybody, regarding

check why existing tests fail. This should NOT be a breaking change (BC).

Drupal 10 no longer has "stable" theme, replaced it with "stark" theme, resolved the tests failure.

add test coverage for the new functionality to proof this works as expected

OK, added a test to check if the default "stark" theme content wrapper element (article) is removed, when enabling the new setting.

Improve description to understand what this does.

Please, check the revised description.

martins.bruvelis’s picture

Also, when enabling the setting "No wrapping HTML for entity content", it is necessary to use the module Manage display to resolve the bug reported in the issue
Unable to remove "Author" and "Created" data from Entity Reference fields. The module Manage display allows to correctly hide/display all of the fiends, including, "Author" and "Created" fields.

anybody’s picture

Status: Needs review » Needs work

@martins.bruvelis I'm back here, sorry. Would you mind having a look at my comment in the MR and fix the conflicts? Then we should fix the broken test and review and test this once again!

martins.bruvelis’s picture

Title: Provide an option to remove item content wrappers for Rendered entity field formatter. » Provide an option to remove entity reference field item content wrappers for Rendered entity field formatter.
Version: 3.0.0 » 3.0.7
Issue summary: View changes
Status: Needs work » Needs review

Review needed (all patch related tests in OverrideEntityReferenceTest pass).

martins.bruvelis’s picture