Problem/Motivation

I am currently working on a new contrib module to create/manage and reuse layouts for DS/Panels/D8.5 Layout Builder in a UI using the LayoutDiscovery plugin derivatives.
https://www.drupal.org/project/dynamic_layouts

When I deleted a layout, I got the following error in my D8.5 Core layout builder:
(/admin/structure/types/manage/article/display-layout/default)

The "dynamic_layout:my_awesome_layout2" plugin does not exist.
Drupal\layout_builder\Section->getDefaultRegion() (Line: 121)
Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->getDefaultRegion() (Line: 157)
Drupal\Core\Entity\EntityDisplayBase->init() (Line: 143)
Drupal\Core\Entity\EntityDisplayBase->__construct(Array, 'entity_view_display') (Line: 175)
Drupal\Core\Entity\Entity\EntityViewDisplay->__construct(Array, 'entity_view_display') (Line: 322)

Proposed resolution

The layout discovery module makes it possible to implement layouts via:
- *.layout.yml files
- Layout Plugin derivatives

Both of the above cases, can get deleted/renamed. Which will cause errors on the Layout Builder.
I will provide a patch which adds some extra guards, if the layout does not exist anymore and displays a message if a Layout plugin is not found. Also adding red highlighting of the sections where the layout plugin does not exist anymore.

A preview of the patch will be added as a file attachment.

Remaining tasks

- Create a patch for this issue
- Testing
- Code reviewing

CommentFileSizeAuthor
#41 2943627-layout_dependencies-backport-41-interdiff.txt2.34 KBtim.plunkett
#41 2943627-layout_dependencies-backport-41.patch12.71 KBtim.plunkett
#31 2943627-layout_dependencies-31.patch10.72 KBtim.plunkett
#29 2943627-layout_dependencies-29-FAIL.patch9.68 KBtim.plunkett
#27 2943627-layout_dependencies-27-interdiff.txt637 bytestim.plunkett
#27 2943627-layout_dependencies-27-PASS.patch10.72 KBtim.plunkett
#27 2943627-layout_dependencies-27-FAIL.patch9.65 KBtim.plunkett
#25 2943627-layout_dependencies-25-interdiff.txt4.65 KBtim.plunkett
#25 2943627-layout_dependencies-25-PASS.patch10.69 KBtim.plunkett
#25 2943627-layout_dependencies-25-FAIL.patch9.65 KBtim.plunkett
#22 2943627-layout_dependencies-22-interdiff.txt1.66 KBtim.plunkett
#22 2943627-layout_dependencies-22.patch6.04 KBtim.plunkett
#9 2943627-layout_dependencies-9.patch4.9 KBtim.plunkett
#7 2943627-layout_dependencies-7.patch6.88 KBtim.plunkett
#4 2943627-layout_dependencies-4.patch734 bytestim.plunkett
#2 layout-builder-error-layout-deleted-2943627-2.patch11.28 KBFalco010
layouts-got-renamed-deleted.png186.69 KBFalco010
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Falco010 created an issue. See original summary.

Falco010’s picture

Created the following patch for the issue described above.

EvaSoek’s picture

+1

tim.plunkett’s picture

Title: New core layout builder causes error when chosen section layout is deleted. » Layout Builder does not consult layout plugin for dependencies
Version: 8.5.x-dev » 8.6.x-dev
Issue tags: +Blocks-Layouts, +Needs tests
FileSize
734 bytes

https://cgit.drupalcode.org/dynamic_layouts/tree has no code in it so I can't see how you are computing/storing the derivatives.

This should be fixed via the dependencies system within your plugin/deriver.

Then the only change needed in LB would be this (which we should do anyway).

Falco010’s picture

Hi @tim.plunkett

Thanks for your quick reaction! Was hoping for a reply from you. Just did a dev release of the dynamic_layouts module so you can have look at how I am using the plugin/deriver in my module. I just followed the standard documentation on:
https://www.drupal.org/docs/8/api/layout-api/how-to-register-layouts#usi...

FYI: the module is still under development :)

Falco010’s picture

@tim.plunkett When a layout gets renamed/deleted:
Do you agree with me that we also should visually show to the LB that a section layout is not available anymore?

LB

tim.plunkett’s picture

Status: Active » Needs review
Issue tags: -Needs tests
FileSize
6.88 KB

No, I do not necessarily agree.
We should use the config dependency system correctly, and the UI where you change the layout derivatives should explain what you are about to affect.

This will add any layout's dependencies to the config. Your module should correctly declare its dependencies on the config entities that define it.

tim.plunkett’s picture

Note that this has to expand the method that is still slated to be removed in #2939925: Add a getPluginDependencies() method to \Drupal\Core\Plugin\PluginDependencyTrait

tim.plunkett’s picture

Rerolled now that the getPluginDependencies() is fixed.

Falco010’s picture

Thank you for the patch.

If I understand correctly:
- I need to add config depencies to my layout plugin derivative
- This patch will check if dependencies got removed and it will delete the section (which used the deleted layout plugin) if a dependency got deleted.

I am not really familliar with the config dependencies.
Was reading through the documentation:
https://www.drupal.org/docs/8/api/configuration-api/configuration-entity...

Only the example given there does not really apply for my use case.

How would I get information on which config entities are using my layout plugin? Because Display Suite, Panels & Core LB are able to use my layout plugins.

samuel.mortenson’s picture

Hi @Falco010 - I was looking through the Dynamic Layouts module and I think you would just need to add a dependency to the related Dynamic Layout config entity (https://cgit.drupalcode.org/dynamic_layouts/tree/src/Entity/DynamicLayou...).

You will not need to add dependencies for systems which use your layout like Panels and Display Suite. Your Layout Plugins are derived from Config Entities, so you need to make sure they're dependent on them so that the logic in this patch works.

tim.plunkett’s picture

Falco010’s picture

@tim.plunkett Thank you very much! Will do some functional testing ASAP.

tim.plunkett’s picture

Keep in mind that you will need both that patch AND this patch

tim.plunkett’s picture

Component: layout.module » layout_builder.module
Falco010’s picture

Just tested both of the patches and these solve the issue described above. Thanks for your work @tim.plunket

I will commit & release your Dynamic Layouts patch.

xjm’s picture

Priority: Normal » Major

Ouchy, this is at least major and might be critical. Thanks @Falco010 for reporting this!

samuel.mortenson’s picture

Status: Needs review » Reviewed & tested by the community

Marking as RTBC per my earlier review and #16.

Falco010’s picture

Issue summary: View changes
alexpott’s picture

+++ b/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php
@@ -215,6 +216,15 @@ public function onDependencyRemoval(array $dependencies) {
+      $layout_dependencies = $this->getPluginDependencies($section->getLayout());
+      $layout_removed_dependencies = $this->getPluginRemovedDependencies($layout_dependencies, $dependencies);
+      if ($layout_removed_dependencies) {
+        // @todo Allow the plugins to react to their dependency removal in
+        //   https://www.drupal.org/project/drupal/issues/2579743.
+        $this->removeSection($delta);
+        $changed = TRUE;
+      }
+
       foreach ($section->getComponents() as $uuid => $component) {

If we remove the entire section should we process it's components? Or should we process the section after the components. Not sure leaving at RTBC and pinging @tim.plunkett in slack.

tim.plunkett’s picture

There's no need to process the components after we remove their section.
Interdiff is generated with -w

tim.plunkett’s picture

Issue tags: +sprint

Tagging as this is currently on our shortlist.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Since this missed the 8.5.0 ship we need an update path, unfortunately. Something like views_post_update_table_display_cache_max_age() to just update all the LayoutBuilderEntityViewDisplay entities. Sorry we didn't get this in earlier.

tim.plunkett’s picture

tim.plunkett’s picture

tim.plunkett’s picture

Slowly losing my mind. The PASS patch was correct, the FAIL was not.

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
10.72 KB

This is identical to 27-PASS but reuploading so the bot is happy.

alexpott’s picture

Update looks good. The issue of experimental commits during RC was discussed more by @catch & @xjm. At some point in the past we agreed that since experimental module are at a state less than RC we can continue to commit during a RC phase. So once this is RTBC I'll commit to both 8.5.x and 8.6.x.

samuel.mortenson’s picture

Status: Needs review » Reviewed & tested by the community

The interdiffs since my last review look good, marking as RTBC.

alexpott’s picture

Adding credit for patch reviews.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 2678eabf6e to 8.6.x and bc6f172f55 to 8.5.x. Thanks!

Discussed with @catch and he was +1 to this going in to 8.5.x.

  • alexpott committed 2678eab on 8.6.x
    Issue #2943627 by tim.plunkett, Falco010, alexpott, samuel.mortenson:...

  • alexpott committed bc6f172 on 8.5.x
    Issue #2943627 by tim.plunkett, Falco010, alexpott, samuel.mortenson:...
xjm’s picture

Version: 8.6.x-dev » 8.5.x-dev
Status: Fixed » Needs work

It looks like this broke HEAD on 8.5.x (but not 8.6.x) Reverting there. Also setting the branch correctly; please set it to the minimum branch that includes an issue.

  • xjm committed bc21962 on 8.5.x
    Revert "Issue #2943627 by tim.plunkett, Falco010, alexpott, samuel....
xjm’s picture

Probably something else was not backported to 8.5.x and this depends on it.

tim.plunkett’s picture

The lack of a backport on #2939925: Add a getPluginDependencies() method to \Drupal\Core\Plugin\PluginDependencyTrait is what caused the fail.
However, that changes non-experimental code, so I'm not sure it's eligible for backport.
Here's a patch with the fix from there copied into the method that is still @todo'd for removal.

EclipseGc’s picture

Status: Needs review » Reviewed & tested by the community

Interdiff looks good to me. RTBC assuming tests pass.

Eclipse

alexpott’s picture

Let's leave #2939925: Add a getPluginDependencies() method to \Drupal\Core\Plugin\PluginDependencyTrait for 8.6.x it adds a method to a trait so it potentially disruptive.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Second time lucky. @tim.plunkett thanks for the quick turn-around. Committed ae5ffa9 and pushed to 8.5.x.

  • alexpott committed ae5ffa9 on 8.5.x
    Issue #2943627 by tim.plunkett, Falco010, alexpott, samuel.mortenson,...

Status: Fixed » Closed (fixed)

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