Problem/Motivation

Layout Builder currently has a hard dependency on the layout_onecol layout defined in the Layout Discovery module.

If somebody removes this Layout (plugin) via hook_layout_alter() all hell breaks loose.

This is the case if you only want to support only your own Layouts, and not the Layouts provided by Core.
There is a workaround by using hook_plugin_filter_TYPE__CONSUMER_alter(), but this is a cosmetic workaround.

Proposed resolution

Remove the dependency by removing the hard coded value and allow changing the default value somehow.

Remaining tasks

  1. Agree on solution
  2. Write patch
  3. Write documentation
  4. Write change record

User interface changes

None

API changes

Data model changes

None

Comments

dmsmidt created an issue. See original summary.

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett

Working on this

tim.plunkett’s picture

Status: Active » Needs review
StatusFileSize
new11.21 KB

With update path tests.

tim.plunkett’s picture

Idk that this needs a UI in core, but one could be written from contrib.

dmsmidt’s picture

Status: Needs review » Needs work

Wow this was so quick! Awesome, thanks!

Manual tested:

  1. Install Drupal, enable LB, setup Layout for Page, apply patch, run update hook, Remove all sections on Page, save, Manage Layout again:
    Ok, automatically a section with layout_onecol is set. (Offtopic: This is by design, although strange one can't have a page without sections
  2. Install Drupal, apply patch, remove Core layouts, enable LB, setup Layout for Page:
    Not ok, I expect at least a warning that no Layouts are available. When turning LB on for Page: PluginNotFoundException.
  3. Install Drupal, enable LB, remove Core layouts, apply patch, run update hook (Drush):
    Ok, update fails gracefully with error messages ("No layout plugins available").
  4. Install Drupal, enable LB, remove Core layouts, add custom Layouts, apply patch, run update hook, Layout a Page:
    Ok, first defined custom Layout is used by default, jay!
  5. Install Drupal, remove Core layouts, add custom Layouts, apply patch, enable LB, Layout Page:
    Not ok, see 2
  1. +++ b/core/modules/layout_builder/layout_builder.install
    @@ -62,3 +63,24 @@ function layout_builder_update_8601(&$sandbox) {
    +function layout_builder_update_8602() {
    

    ++ updates for experimental

  2. +++ b/core/modules/layout_builder/layout_builder.install
    @@ -62,3 +63,24 @@ function layout_builder_update_8601(&$sandbox) {
    +      throw new UpdateException('No layout plugins available');
    

    Nit: I like my exceptions with a "." at the end of a sentence.

  3. +++ b/core/modules/layout_builder/tests/src/Functional/Update/DefaultLayoutIDUpdatePathTest.php
    @@ -0,0 +1,77 @@
    +    \Drupal::state()->set('layout_builder_test.plugin_alter.function', 'array_intersect_key');
    

    I'm learning new things here, cool. But can't we return an empty value without calling array_intersect_key?

  4. +++ b/core/modules/layout_builder/tests/src/Functional/Update/DefaultLayoutIDUpdatePathTest.php
    @@ -0,0 +1,77 @@
    +    // There are expected to be failed updates.
    ...
    +    $this->assertSession()->responseContains('<strong>' . t('Failed:') . '</strong>');
    

    This search can be a bit stricter. Failed can be anything that crept up.

  5. We are missing coverage for module install.

I agree that we don't need a UI for this in core. It can easily be set via settings.php, an update hook or changing config ymls. This is only relevant for more advanced scenarios. It should be documented somewhere though.

tim.plunkett’s picture

Aha, yeah this does need accounting for during install. Thanks for the thorough review!

1) :)
2) I am quite the opposite, since by default exception messages get concatenated into a larger sentence!
3) Hah, I wrestled with this a bunch. Feel like I'm being too tricky here. Probably should change this
4) Yeah I wasn't sure the best way to check this, I c/p'd this from another test.
5) Yep, NW for that

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned
Issue tags: +Blocks-Layouts, +sprint

Not personally working on this right now, hopefully I'll have time next week.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new8.66 KB

#3030647: Do not add a section when editing an empty layout, or differentiate between new layouts and existing empty layouts removes one of the main usages of the onecol layout.

Here's a straight reroll of the old patch.

Status: Needs review » Needs work

The last submitted patch, 8: 2990187-hardcoded-8.patch, failed testing. View results

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

Status: Needs work » Needs review
StatusFileSize
new8.63 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, 11: 2990187-hardcoded-11.patch, failed testing. View results

johnwebdev’s picture

Status: Needs work » Needs review
StatusFileSize
new8.57 KB
new1.13 KB

The layout is now called layout_twocol_section. Also updated the update hook name.

tim.plunkett’s picture

Looks good still, need someone to review!

sam152’s picture

+++ b/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php
@@ -453,7 +453,8 @@ public function setComponent($name, array $options = []) {
-      $this->appendSection(new Section('layout_onecol'));
+      $default_layout_id = \Drupal::config('layout_builder.settings')->get('default_layout_id');
+      $this->appendSection(new Section($default_layout_id));

+++ b/core/modules/layout_builder/src/Plugin/Field/FieldType/LayoutSectionItem.php
@@ -80,7 +80,8 @@ public static function schema(FieldStorageDefinitionInterface $field_definition)
-    $values['section'] = new Section('layout_onecol');
+    $default_layout_id = \Drupal::config('layout_builder.settings')->get('default_layout_id');
+    $values['section'] = new Section($default_layout_id);

I wonder if here we should add 'layout_onecol' as the default when the setting doesn't exist. It would maintain the existing functionality where sites somehow failed to install the settings, deleted it or were between updates somehow.

Other than that, LGTM.

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.

tim.plunkett’s picture

Status: Needs review » Needs work
Issue tags: -sprint

NW for #15

dhirendra.mishra’s picture

Assigned: Unassigned » dhirendra.mishra
Issue tags: +vb13febContribution
dhirendra.mishra’s picture

Assigned: dhirendra.mishra » Unassigned
Status: Needs work » Needs review
StatusFileSize
new8.6 KB

Not uploading Interdiff..Not sure why it was showing wrong changes. However done the fix mentioned in #15 and re-rolled against 8.9.x

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Thanks!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/layout_builder/layout_builder.install
    @@ -136,3 +137,24 @@ function layout_builder_update_8602() {
    +/**
    + * Set a default layout ID.
    + */
    +function layout_builder_update_8801() {
    
    +++ b/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php
    --- a/core/modules/layout_builder/src/Plugin/Field/FieldType/LayoutSectionItem.php
    +++ b/core/modules/layout_builder/src/Plugin/Field/FieldType/LayoutSectionItem.php
    
    +++ b/core/modules/layout_builder/tests/src/Functional/Update/DefaultLayoutIDUpdatePathTest.php
    @@ -0,0 +1,77 @@
    +      __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.4.0.bare.standard.php.gz',
    

    This needs to use an 8.8.x update file and I think given we're adding an update function this should target 8.9.x

  2. +++ b/core/modules/layout_builder/layout_builder.install
    @@ -136,3 +137,24 @@ function layout_builder_update_8602() {
    +    if (empty($layout_ids)) {
    +      throw new UpdateException('No layout plugins available');
    +    }
    

    This makes me realise that we've introduced a dependency on config entities from the simple config. If you delete the default layout then the config is invalid.

    I ponder if we should do this in a different way. Can we have a default flag on the config entity instead?

rithesh bk’s picture

Assigned: Unassigned » rithesh bk
Issue tags: +VbContribution2020

currently working on it .......

rithesh bk’s picture

Assigned: rithesh bk » Unassigned
Status: Needs work » Needs review
StatusFileSize
new8.96 KB
new1.29 KB

Please find the updated patch .......

Status: Needs review » Needs work

The last submitted patch, 23: 2990187-23.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

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.

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.

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.

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.

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.

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.

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.

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.