Entity wrapper prevents site building to properly work with components

Created on 6 November 2023, 8 months ago
Updated 4 January 2024, 6 months ago

Problem/Motivation

For example with accordion and accordion item.

When having a content type or a block content type (or any other entity type) which uses a paragraph field (but it could be an entity reference field to another content entity type).

Having the wrapper div of the referenced entity between accordion and accordion-item prevents proper theming.

Expected result:

Proposed resolution

At first I didn't want to remove the wrapper div due to at least the feature to indicate publication status of an entity.

Following @pdureau suggestion:
- with declaration of a preRender callback in the pattern render element and checking publication status here allows to do it generically.
- with an override of the paragraph default twig template to remove the wrapper div, then it is ok.

I think it is ok to override the paragraph Twig template because I guess it will be the main content entity type to be used as accordion_item, carousel_item, etc. (sub-componants). I am still not ok into removing wrapper in node or taxonomy.

Edit: I am also even more ok to remove the paragraph div wrapper because currently it does not work when using components. On the screenshots, the 2nd paragraph item is unpublished.

Remaining tasks

Remaining point is the preRender callback, should it go into ui_patterns directly or into a ui_patterns_entity_status or another name?

Then implements the solution properly.

🐛 Bug report
Status

Fixed

Version

5.0

Component

Code

Created by

🇫🇷France Grimreaper France 🇫🇷

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @Grimreaper
  • 🇫🇷France Grimreaper France 🇫🇷
  • 🇫🇷France pdureau Paris

    - with an override of the paragraph default twig template to remove the wrapper div, then it is ok.

    Instead of just removing the wrapper, I would do something like that for paragraph.html.twig:

    {% if attributes %}
    <div{{ attributes.addClass(classes) }}>
    {% endif %}
        {{ content }}
    {% if attributes %}
    </div>
    {% endif %}
    or into a ui_patterns_entity_status or another name?

    In order to keep the not paragraph.isPublished() ? 'paragraph--unpublished' feature, we can dream about a ui_styles ecosystem module allowing the addition of a style for each Drupal\workflows\State of a Drupal\workflows\WorkflowInterface:

    id: editorial
    label: Editorial
    type: content_moderation
    type_settings:
      states:
        archived:
          label: Archived
          weight: 5
          published: false
          default_revision: true
          ui_styles:
            - bg-color-secondary
        draft:
          label: Draft
          published: false
          default_revision: false
          weight: -5
          ui_styles:
            - border-warning
  • 🇫🇷France Grimreaper France 🇫🇷

    Thanks for the reply.

    Point 1: wrapper div

    The if statement is always true so not possible. Or we need to think about a configuration to be able to tell, in this view mode (of this bundle of the content entity) remove the wrapper, so we can have a Twig variable to base the if statement on.

    Point 2: adding CSS class

    Nice idea that this will be more in UI Styles side than UI Patterns!

    Regarding our quick call.

    1: let's do workflow integration in a second time
    2: Using hook_entity_view is ok. quick poc:

      /** @var \Drupal\ui_styles\StylePluginManagerInterface $styles_manager */
      $styles_manager = \Drupal::service('plugin.manager.ui_styles');
      if (isset($build['_layout_builder'][0])) {
        $build['_layout_builder'][0] = $styles_manager->addClasses($build['_layout_builder'][0], ['bg-danger-subtle']);
      }
    

    Need to be cleaned up to loop and to handle non layout builder handled view mode. Like ui_styles_layout_builder does.

    About the workflow integration, we need to chack if third_party_settings are handled, ok. But for the default boolean status on entities, where should we store the ui styles plugin classes we want to use?
    - a global configuration form?
    - in theme settings?
    - somewhere else?

    Maybe let's create an issue in UI Styles to continue this conversation, or use this one?
    And in UI Suite Bootstrap we can have an issue about removing paragraphs wrapper and an issue about updating how the unpublished class is working regarding the new ui_styles module.

  • Assigned to Grimreaper
  • 🇫🇷France Grimreaper France 🇫🇷
  • 🇫🇷France Grimreaper France 🇫🇷
  • Status changed to Needs work 6 months ago
  • 🇫🇷France Grimreaper France 🇫🇷

    I don't know if we should add a dependency on ui_styles_entity_status and provide a default configuration in the theme settings.

  • 🇫🇷France Grimreaper France 🇫🇷

    The removing of the div wrapper in paragraph.html.twig will prevent ui_styles_paragraphs to work with ui_suite_bootstrap.

    • Grimreaper committed b00c318f on 5.0.x
      Issue #3399450 by Grimreaper, pdureau: Entity wrapper prevents site...
  • Issue was unassigned.
  • Status changed to Fixed 6 months ago
  • 🇫🇷France Grimreaper France 🇫🇷

    UI Patterns best practice documentation page updated too.

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

Production build 0.69.0 2024