Problem/Motivation

Once #2907413: Consider supporting Layout Builder Overrides for other view modes is addressed, sections will be stored per-view mode.

LayoutEntityHelperTrait::getEntitySections() assumes the view mode is default.

Proposed resolution

Provide additional functionality for displays, and do not assume the default display.

Remaining tasks

Per #3008924-27: Callers of LayoutEntityHelperTrait::getEntitySections() do not account for the view mode:

Thank you all! Sadly still needs tests and steps to reproduce to be committed. I don't have the time currently, sorry.

Steps to reproduce should follow, per #3008924-13: Callers of LayoutEntityHelperTrait::getEntitySections() do not account for the view mode:

Could you explain how to reproduce the bug, using only core modules?
Step by step, starting with "Install standard profile"
That is an important step for writing test coverage, which must be done before the fix can be committed.

User interface changes

N/A

API changes

TBD

Data model changes

N/A

Issue fork drupal-3008924

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

tim.plunkett created an issue. See original summary.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tim.plunkett’s picture

matt_paz’s picture

Thanks for the work on this.

After a bit of debugging, I think this issue (#3008924) might be why I'm getting an error from quickedit.

I'm using display_mode_extras and on the surface, LB seems to be presenting different layouts correctly (so far).

I only saw one side-effect:

/quickedit/metadata

InvalidArgumentException: Invalid UUID "f7d1c76a-e989-4c98-af42-c40596469bff" in Drupal\layout_builder\Section->getComponent() (line 180 of /app/web/core/modules/layout_builder/src/Section.php).

---

It looked like ...
web/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php
$sections = $this->getEntitySections($entity);
... was indeed only returning the `default` display mode.

That got me worried, tho. Is this the only side-effect, or might be other, ugly side-effects that I haven't seen yet.

Do you think I'm good to continue using LB with other display modes in the interim, or would you advise against it (until #3008924 gets fixed) for reasons that haven't jumped out at me yet? It seems like comments in #2907413 were advising that different view modes shouldn't be supported at all. If that's looking like the direction this will be heading, please advise.

While it _mostly_ seems to be working for me, I'd just assume drop use of display_mode_extras, step back and think through other ways to facilitate what I was looking at doing if this isn't likely to get addressed.

romixua’s picture

StatusFileSize
new3.09 KB

I revived error during of reproducing of this issue https://www.drupal.org/project/field_formatter_class/issues/3053629
So after debuging and investigation I find that we always use view mode 'full'

  protected function getSectionStorageForEntity(EntityInterface $entity) {
    $view_mode = 'full';
    if ($entity instanceof LayoutEntityDisplayInterface) {
      $contexts['display'] = EntityContext::fromEntity($entity);
    }
    else {
      $contexts['entity'] = EntityContext::fromEntity($entity);
      if ($entity instanceof FieldableEntityInterface) {
        $display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode);
        if ($display instanceof LayoutEntityDisplayInterface) {
          $contexts['display'] = EntityContext::fromEntity($display);
        }
        $contexts['view_mode'] = new Context(new ContextDefinition('string'), $view_mode);
      }
    }
    return $this->sectionStorageManager()->findByContext($contexts, new CacheableMetadata());
  }

In my case I need to get section storage for teaser, and than get component by UUID, but we get the exception that UUID is invalid.

Here is the patch that resolve this problem. Using of additional argument with default value fix the problem, and prevent errors after code changes.

matt_paz’s picture

The patch from #5 seemed to resolve the issues reported in #4 as well. Thanks @Romixua!

pifagor’s picture

Status: Postponed » Needs review
anybody’s picture

Same problem as in #4, fixed by #5! We're using it in Drupal 8.7.x
Wonderful! RTBC +1.

I guess @tim.plunkett should do the final RTBC?

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

yepa’s picture

Status: Needs review » Reviewed & tested by the community

Same fatal error on a project based on drupal 8.7.5.
InvalidArgumentException: Invalid UUID "3b59df4b-cf9a-4347-af9d-36036d93c9a7" in Drupal\layout_builder\Section->getComponent() (line 177 of web/core/modules/layout_builder/src/Section.php).

The patch #5 works fine! Thanks @Romixua

tim.plunkett’s picture

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

Thanks for the patch! That looks like a good fix.

Before it is committed, we need test coverage of the existing bug that fails, and then passes when combined with this change.

maskedjellybean’s picture

#5 works in Drupal 8.8.1.

I was seeing this error after moving a block in Layout Builder from one section to a new section and then trying to delete the old section. This patch allows me to do this without errors.

tim.plunkett’s picture

@matt_paz, @Romixua, @Anybody, @yepa, @maskedjellybean:
Could you explain how to reproduce the bug, using only core modules?
Step by step, starting with "Install standard profile"
That is an important step for writing test coverage, which must be done before the fix can be committed.
Thanks!

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

abhisekmazumdar’s picture

So the #5 works for me.
I came across this issue when I was trying to alter the view mode of a content type which uses layout builder for display.

phjou’s picture

The patch in #5 seems to work for me as well. But the issue was not with quick_edit but with a computed field.

Vidushi Mehta’s picture

Status: Needs work » Needs review
StatusFileSize
new3.18 KB

I've pulled the latest code and the patch #5 was failed to apply. Added a rerolled patch against 9.1.x.

Webbeh’s picture

Reiterating comment #13:

@matt_paz, @Romixua, @Anybody, @yepa, @maskedjellybean:
Could you explain how to reproduce the bug, using only core modules?
Step by step, starting with "Install standard profile"
That is an important step for writing test coverage, which must be done before the fix can be committed.

I was unable to reproduce this issue from a fresh 9.1.x install, without and with field_formatter_class.

I attached a View block of entities' teaser displays into a (separate entity type) Layout, which worked as expected and without the reported issue.

+1 to getting a repeatable process to recreate and resolve this bug.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

simgui8’s picture

#17 fixes it for me on drupal 8.9.7

The site that had this error uses the field_formatter_class module.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

murz’s picture

I catch this problem on my website even without field_formatter_class module, or any other similar module for formatting fields, the error on Drupal 9.2.4 is:
Uncaught PHP Exception InvalidArgumentException: "Invalid UUID "xxx"" at web/core/modules/layout_builder/src/Section.php line 184

And the patch form #17 resolves the fatal error for me, thanks!

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

geoffreyr’s picture

StatusFileSize
new3.17 KB

Rerolled against 9.3.x.

hswong3i made their first commit to this issue’s fork.

anybody’s picture

Status: Needs review » Needs work

Thank you all! Sadly still needs tests and steps to reproduce to be committed. I don't have the time currently, sorry.

But I can confirm it works great, we're using it in several projects for a long period of time.

anybody’s picture

Important:
#3044993: Allow synced Layout default Translations: translating labels and inline blocks uses $this->getSectionStorageForEntity($this->entity); in

/**
   * {@inheritdoc}
   */
  public function hasTranslatable() {
    $section_storage = $this->getSectionStorageForEntity($this->entity);
    $sections = $section_storage->getSections();
    if (!empty($sections)) {
      foreach ($sections as $section) {
        $components = $section->getComponents();
        if ($components) {
          foreach ($components as $component) {
            // @todo Determine if component has translatable schema.
            return TRUE;
          }
        }
      }
    }

    return FALSE;
  }

So I guess it's relevant for that issue to fix the hard coded view mode as translations may differ per view mode!

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

anybody’s picture

Patch fails to apply against 9.4.2. Both the MR and the rerolled patch from #24.

anybody’s picture

The reason is that function getQuickEditSectionComponent() has been removed in 9.4.x.

anybody’s picture

@hswong3i could you please change the MR to point against 9.5.x? It seems I can't do that.

BTW I still couldn't figure out how to reproduce this on a clean install, but ran into it again and again in several existing installations.

diegodalr3’s picture

Status: Needs work » Needs review
StatusFileSize
new3.19 KB

Patch updated to apply on Layout Builder and QuickEdit modules.
Related change https://www.drupal.org/node/3265518

anybody’s picture

Created a new MR against 9.5.x as I couldn't change the target branch in the existing and there was no reaction from @hswong3i. And rebasing issue forks is still kind of pain or perhaps I'm just too dumb ;)

Grevil made their first commit to this issue’s fork.

andrea.cividini’s picture

+1 for patch #33 on Drupal 9.4.3 / PHP 7.4

Webbeh’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

This needs an issue summary update for our progress and next steps, as I think some comments may be missing what work is left.

From #27:

Thank you all! Sadly still needs tests and steps to reproduce to be committed. I don't have the time currently, sorry.

Have we made progress on either/both? If so, I'll move back to For Review.

Webbeh’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

Updated IS where we're at.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

a.milkovsky’s picture

The changes in the merge request 2499 work great for me against 9.5.x.

Unfortunately the patch does not apply against 10.1.x.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new1.95 KB

Patch for 10.1.x, queckedit moved to contrib

hfernandes’s picture

#42 worked here. Even though I'm using Drupal 9.5.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

Did not test

But for the tests and steps to reproduce.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

joelpittet’s picture

Version: 11.x-dev » 10.1.x-dev

We've been using #33 for a while. Thanks for rerolling @andypost.

Sorry I don't have any steps on this one, but my guess it has to do with our entity references to field_bundle/storage entities in LB.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

carolpettirossi’s picture

I have faced an issue that I needed to add patch #42 + patch from https://www.drupal.org/project/layout_builder_st/issues/3069964 when using the modules "Moderation Dashboard" and accessing the /user/{uid}/moderation-dashboard page.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

anybody’s picture

Edit: Sorry comment was wrong.