Problem/Motivation

\Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay has methods supporting the two checkboxes on "Manage display":
"Use Layout Builder": isLayoutBuilderEnabled()/enableLayoutBuilder()/disableLayoutBuilder()
"Allow each @entity_type to have its layout customized.": isOverridable()/setOverridable($overridable = TRUE)

(Ignore the strangeness of one checkbox having 3 methods and the other having 2 with one taking a bool)

In the UI, the "customized" (overridable) checkbox cannot be checked unless Layout Builder is enabled.
However, that is not enforced on the API level.

Proposed resolution

There are multiple options:

  1. Throw an exception if isLayoutBuilderEnabled() is FALSE when setOverridable() is called with TRUE or if disableLayoutBuilder() is called when isOverridable() is TRUE
  2. Rewrite setOverridable() so that when it is called with TRUE enableLayoutBuilder() is called

#1 is more explicit but may be considered an API break

Remaining tasks

Write tests
Decide on an solution

User interface changes

N/A, this already is enforced in the UI and has test coverage

API changes

Maybe?

Data model changes

N/A

Release notes snippet

N/A

Support from Acquia helps fund testing for Drupal Acquia logo

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

tim.plunkett’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update +sprint
nord102’s picture

Assigned: Unassigned » nord102
Issue tags: +Seattle2019
nord102’s picture

I have created a patch that implements Proposed Solution - #2 which does the following:

  • When setOverridable is called with TRUE and Layout Builder is not already enabled, enableLayoutBuilder() is called



Noting here: the second piece of Proposed Solution - #2 was previously completed.


I have added a test as well

nord102’s picture

Assigned: nord102 » Unassigned
Status: Active » Needs review
tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Looks great, thanks!

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

The issue summary says...

Rewrite setOverridable() so that when it is called with TRUE enableLayoutBuilder() is called, and rewrite disableLayoutBuilder() so that when it is called setOverridable(FALSE) is called

Is the second half of that incorrect?

If so feel free to update the issue summary and set back to "reviewed and tested by the community"

tim.plunkett’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

That second part was already done in HEAD

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 7ca5921520 to 8.8.x and d950a4dbda to 8.7.x. Thanks!

As a bugfix backported to 8.7.x - thanks for making layout builder have less bugs before its stable release.

FILE: ..._builder/tests/src/Kernel/LayoutBuilderEntityViewDisplayTest.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 64 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found
    |       |     1
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
diff --git a/core/modules/layout_builder/tests/src/Kernel/LayoutBuilderEntityViewDisplayTest.php b/core/modules/layout_builder/tests/src/Kernel/LayoutBuilderEntityViewDisplayTest.php
index 04d718b9c1..9a12b74b36 100644
--- a/core/modules/layout_builder/tests/src/Kernel/LayoutBuilderEntityViewDisplayTest.php
+++ b/core/modules/layout_builder/tests/src/Kernel/LayoutBuilderEntityViewDisplayTest.php
@@ -61,7 +61,7 @@ public function testGetRuntimeSections() {
     $this->assertEquals($this->sectionStorage->getSections(), $result);
   }
 
- /**
+  /**
    * Tests that setting overridable enables Layout Builder only when set to TRUE.
    */
   public function testSetOverridable() {

Fix coding standards on commit.

  • alexpott committed 7ca5921 on 8.8.x
    Issue #3019824 by nord102, tim.plunkett: Layout Builder's isOverridable...

  • alexpott committed d950a4d on 8.7.x
    Issue #3019824 by nord102, tim.plunkett: Layout Builder's isOverridable...

Status: Fixed » Closed (fixed)

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