Call to undefined method isLayoutBuilderEnabled()

Created on 28 April 2022, over 2 years ago
Updated 24 July 2023, over 1 year ago

Steps to reproduce

Drupal 9.3.2, with Layout Builder and Display Suite 8.x-3.13 enabled.
I've choose a DisplaySuite layout in a content form display.
Then, I cant' display content.

Problem/Motivation

Error: Call to undefined method Drupal\Core\Entity\Entity\EntityViewDisplay::isLayoutBuilderEnabled() in Drupal\layout_builder\Plugin\SectionStorage\DefaultsSectionStorage->isLayoutBuilderEnabled() (line 330 of core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php).
Drupal\layout_builder\Plugin\SectionStorage\DefaultsSectionStorage->isLayoutBuilderEnabled() (Line: 382)
Drupal\layout_builder\Plugin\SectionStorage\DefaultsSectionStorage->access() (Line: 362)
Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage->access() (Line: 37)
Drupal\layout_builder\Access\LayoutBuilderAccessCheck->access()
....

Proposed resolution

To work around the problem, not being a Drupal developer, I simply added the missing method such as:

namespace Drupal\Core\Entity\Entity;
...
class EntityViewDisplay extends EntityDisplayBase implements EntityViewDisplayInterface {
...
  public function isLayoutBuilderEnabled() {
	return \Drupal::moduleHandler()->moduleExists('layout_builder') ;
  }
...
}
πŸ› Bug report
Status

Postponed: needs info

Version

9.5

Component
Layout builderΒ  β†’

Last updated 4 days ago

Created by

πŸ‡«πŸ‡·France marco5775

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

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

    This a problem with layout builder or layout builder library?

    Will need a test case for core to show this problem.

    Will leave in PNMI for a few more months before closing if no follow up.

  • Status changed to Closed: cannot reproduce 11 months ago
  • πŸ‡³πŸ‡ΏNew Zealand danielveza Brisbane, AU

    This has been PNMI for 6 months now with no further issue reports, and we have no steps to reproduce with just core. Closing this issue now, if someone can replicate this with just core feel free to reopen.

  • Status changed to Needs review 11 months ago
  • πŸ‡¨πŸ‡ΎCyprus alex.bukach

    @DanielVeza we faced the issue recently on several projects, with the patch #7 having resolved it.

  • Status changed to Needs work 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Steps to reproduce will still need to be added to issue summary.

    Bugs require test coverage.

  • Status changed to Postponed: needs info 11 months ago
  • πŸ‡³πŸ‡ΏNew Zealand danielveza Brisbane, AU

    Could we please get a stacktrace as well?

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

    I am seeing a similar issue occur. Occasionally when the cache clears (its not consistently happening), the entire site layout breaks and the PHP logs have this error:

    Uncaught PHP Exception Error: "Call to undefined method Drupal\Core\Entity\Entity\EntityViewDisplay::isOverridable()" at /var/www/html/docroot/core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php line 312

    The error can persist through a few cache clears until it finally resolves itself. It should be noted we are using Memcache on Acquia, and this only happens in the production environment and never dev or stage.

    The only LB related contributed modules we have are:

    • layout_builder_context
    • layout_builder_styles
    • layout_builder_iframe_modal
    • layout_builder_restrictions

    This issue can then cascade down and cause other errors that are not real, like other core classes not existing (when they do). Once the cache is completely purged and rebuilt, its fine.

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

    Happened again today, even with the patch above for isOverridable and isLayoutBuilderEnabled. Only this time, no logs.

    Our only other action here is removing Memcache on Acquia entirely and seeing if it persists.

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

    This issue is still happening at random, even with Memcache disabled.

    Should this even be possible at that point in the code in Layout Builder?

    Uncaught PHP Exception Error: "Call to undefined method Drupal\Core\Entity\Entity\EntityViewDisplay::isOverridable()" at /var/www/html/docroot/core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php line 312

    That method is defined as:

    /**
     * {@inheritdoc}
     */
    public function isOverridable() {
      $display = $this->getDisplay();
    
      return $this->getDisplay()->isOverridable();
    }
    

    getDisplay:

      /**
       * Gets the entity storing the defaults.
       *
       * @return \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface
       *   The entity storing the defaults.
       */
      protected function getDisplay() {
        return $this->getSectionList();
      }
    

    It says it should return an instance of LayoutEntityDisplayInterface, instead it returns an instance of EntityViewDisplay. Under what conditions could that happen? Trying to trace calls to isOverridable does not really produce much.

    SectionStorage defines its context definition as an entity view display:

    * @SectionStorage(
     *   id = "defaults",
     *   weight = 20,
     *   context_definitions = {
     *     "display" = @ContextDefinition("entity:entity_view_display"),
     *     "view_mode" = @ContextDefinition("string", default_value = "default"),
     *   },
     * )
    

    This is where the trail runs cold for me. Does anyone know how or when EntityViewDisplay could be returned instead of an expected LayoutEntityDisplayInterface object that triggers the error?

  • πŸ‡ΊπŸ‡ΈUnited States tim.plunkett Philadelphia

    What's the stack trace of the exception? Whatever it is, it's happening before layout_builder_entity_type_alter() has run, which shouldn't be possible.

  • πŸ‡³πŸ‡ΏNew Zealand danielveza Brisbane, AU

    @kevinquillen This may be unrelated, but the code you've posted for DefaultsSectionStorage::isOverridable is different to cores. Is there a chance you have a patch that may be causing issues?

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

    Sorry, that was an error as I was trying a few things. Everything is removed now and back to

      /**
       * {@inheritdoc}
       */
      public function isOverridable() {
        return $this->getDisplay()->isOverridable();
      }
    
  • πŸ‡ΊπŸ‡ΈUnited States luke.leber Pennsylvania

    I may have some tangentially related info here. We recently found that due to how layout builder works (prior to Drupal 10.3), the accumulation of derived field blocks resulted in a single cache item in `cache_discovery` having a size of over 6mb.

    This _may_ result in extreme performance problems for memcache users, because the default config won't store individual items over 1mb in size.

    Just a theory, but such a large, virtually uncatchable, record could explain a lot of the "this should not be able to happen under normal circumstances" responses to this issue. Systems break down in wild ways when the underlying infrastructure doesn't behave as expected.

    I'm curious if this happens in 10.3+ with most derived field blocks disabled so the block plugins CID falls below 1mb?

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

    I will add that we found this specific issue and error to happen far, far less with the application of this patch:

    https://www.drupal.org/project/drupal/issues/3207813#comment-14380171 πŸ› ModuleHandler skips all hook implementations when invoked before the module files have been loaded Needs review

    We then moved storage back from the database cache to memcache - but what Luke says in #20 is still true.

    I also found a way to replicate this issue:

    1. Clear the site cache
    2. Request random urls in the frontend of the site at the same time (literally within 1-3 seconds of cache clear initiation).

    I was able to get the behavior 90% of the time, which is why this was so hard to track down in prod. It was once in a blue moon where the caches would clear as site traffic was happening at the same time to a degree that would cause this. But if this is the case I do not think this is specifically a Layout Builder issue but something in core as the above patch alludes to, it just happens to affect Layout Builder.

    These may be related:

    1. #2765271: Rationalize use of the 'discovery' cache bin, since it's stored in the limited size APCu by default β†’
    2. πŸ› Multilingual config cached in "config" cache bin; quickly reaches APCu memory limits Needs work
    3. πŸ› Reduce the number of field blocks created for entities (possibly to zero) Fixed
  • πŸ‡ΊπŸ‡ΈUnited States kevinquillen

    This thread seems close to the issue at hand:

    https://www.drupal.org/project/shield/issues/3277210#comment-15083125 πŸ› Shield middleware invokes hooks before modules are loaded, corrupting module_implements cache Needs work

  • πŸ‡ΊπŸ‡ΈUnited States luke.leber Pennsylvania

    Potentially related issue on the same note as #22, albeit not in Middleware, but a different service constructor.

  • πŸ‡¦πŸ‡ΊAustralia Lan

    Hello everyone,

    I’ve been experiencing an issue related to Layout Builder on my site:

    Error: Call to undefined method Drupal\Core\Entity\Entity\EntityViewDisplay::isLayoutBuilderEnabled() in Drupal\layout_builder\Plugin\SectionStorage\DefaultsSectionStorage->isLayoutBuilderEnabled() (line 341 of docroot/core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php).

    To address this, I applied the patch (in #7). However, after applying the patch, I am now encountering a new error (same as #16):
    Error: Call to undefined method Drupal\Core\Entity\Entity\EntityViewDisplay::isOverridable() in Drupal\layout_builder\Plugin\SectionStorage\DefaultsSectionStorage->isOverridable() (line 318 of docroot/core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php).

    My Drupal version is 10.3.1 with Layout Builder enabled. My site only has one content type using Layout Builder and does not heavily rely on this module.

    Has anyone else faced a similar issue after applying this patch? If so, how did you resolve it? Any insights or suggestions would be greatly appreciated.

    Thanks in advance for your help!

Production build 0.71.5 2024