Module does nothing on content types with Layout Builder?

Created on 17 April 2024, 8 months ago
Updated 18 April 2024, 8 months ago

Problem/Motivation

I've installed this module and added the switch field on the 'page' content type. I have Layout Builder enabled on the default/full content view mode, and created a separate "Standard" view mode that I'd like to not be Layout Builder-enabled. Instead this layout will have a standard template using fields as it typically is without Layout Builder enabled.

Enabling this module, and in the switch field changing it to Standard does nothing to the layout. It still utilizes the LB-enabled view mode for the node. I would think that changing the view mode in the field would change what the template looks like to not include the LB-enabled look with blocks, etc. that are defined in the LB override?

For the record, this works as I expect it to if I instead use Display Suite's "view mode switcher" instead, but I'd love to not install Display Suite for this one thing.

πŸ’¬ Support request
Status

Closed: works as designed

Version

2.0

Component

User interface

Created by

πŸ‡ΊπŸ‡ΈUnited States dalemoore

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

Comments & Activities

  • Issue created by @dalemoore
  • πŸ‡ΊπŸ‡ΈUnited States dalemoore

    So I just did a little testing with Twig debugging enabled.

    If I only use this module, and I inspect the source code, the Twig suggestions for the node.html.twig never change on the Layout Builder-enabled content type. No matter what I select in this module's field dropdown, I always get this:

    <!-- FILE NAME SUGGESTIONS:
       * node--281905--full.html.twig
       * node--281905.html.twig
       * node--page--full.html.twig
       * node--page.html.twig
       * node--full.html.twig
       x node.html.twig
    -->

    If I instead enable Display Suite's view mode switcher and change it to a different view mode, the Twig suggestions are updated to the new view mode's name.

    <!-- FILE NAME SUGGESTIONS:
       * node--281905--standard.html.twig
       * node--281905.html.twig
       * node--page--standard.html.twig
       * node--page.html.twig
       * node--standard.html.twig
       x node.html.twig
    -->
  • πŸ‡©πŸ‡ͺGermany hctom

    Thanks for the report. In order to track down this issue, I need some more information from you:

    • How is your VMS field configured? Especially: What are the View modes to switch in Field storage? Is it enabled for Full and/or Default

    It would be nice, if you could provide this information, so I can try to reproduce this potential issue.

    Thanks!

  • πŸ‡ΊπŸ‡ΈUnited States dalemoore

    Thanks!

    Here is a detailed description. This is on the standard profile 'page' content type.

    Manage fields

    1. I've added a view mode switch field labeled "View mode" with machine name "field_view_mode".
    2. Under field storage, "view modes to switch", the only view mode selected is "Default". Full content is not checked because if I check it it removes it from "View modes allowed to switch to".
    3. The field is set to "required"
    4. Under "View modes allowed to switch to", I have selected:
      • Full content
      • Standard
      • Teaser
    5. Under default value, I have it set to "Full content".

    That's it for the field setup.

    Manage form display

    The field is just setup with the defaults here.

    Manage display

    1. In custom display settings, I have enabled "Full content", "Standard", and "Teaser" view modes (Standard is a view mode I manually created).
    2. I have "Use Layout Builder" and "Allow each content item to have its layout customized" enabled on the Default view mode.
    3. On the Standard view mode, I don't have anything Layout Builder enabled, just the normal field/label/format view.
  • πŸ‡©πŸ‡ͺGermany hctom

    Thanks for the details - I think, I know what the problem is: You are only switching the default view mode, but you are accessing the entity in full view mode.

    So you have to check full view mode (because you want to switch away from that one) under "View modes to switch" in field storage config instead of enabling it under "View modes allowed to switch to".
    Additionally your field should be optional - if no switch is selected later, the full view mode (with layout builder and potential overrides enabled) is displayed, if standard is selected, that view mode will be used instead. I have some of these setups running without problems.

    Please let me know, if that fixes the issue for you.

  • πŸ‡ΊπŸ‡ΈUnited States dalemoore

    Thanks! Yes, that fixes it!

    I guess I didn't think of that because I want the user to be able to select from options that are labeled meaningfully, so I wanted "Full content" or "Layout Builder" (really the full view mode, which is the only one Layout Builder overrides work with currently ✨ Consider supporting Layout Builder Overrides for other view modes Needs work ) to be an option they can select. Hence the making it required and wanting the "Full content" option to be selectable under "View modes allowed to switch to", so there would be no option "- No change -" which I felt was confusing. Could I perhaps configure what that "no change" option says on a per-field basis, even if in code? Maybe it could be added in the form display widget?

  • Status changed to Closed: works as designed 8 months ago
  • πŸ‡©πŸ‡ͺGermany hctom

    You are welcome... and this is actually really something I was already thinking about, to allow setting custom labels for the field options. I'll give this a try soon, when I have some spare time again.

    In the meantime you may alter the displayed label of the field's empty value by implementing a corresponding field widget form alter hook.

    For now, I will close this issue as "works as designed" and I will start on a follow up for the custom labels soon.

Production build 0.71.5 2024