Commit 519f9a10 authored by catch's avatar catch
Browse files

fix: #3060985 Layout Builder attempts to builds sections to determine if it is disabled

By: fago
By: tedbow
By: acbramley
By: catch
By: dcam
By: danielveza
By: tim.plunkett
By: kim.pepper
By: akram khan
By: larowlan
By: godotislate
(cherry picked from commit cc44d665)
parent 354ff717
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -7,4 +7,4 @@
/**
 * Defines an interface for an object that stores layout sections for defaults.
 */
interface DefaultsSectionStorageInterface extends SectionStorageInterface, ThirdPartySettingsInterface, LayoutBuilderEnabledInterface, LayoutBuilderOverridableInterface {}
interface DefaultsSectionStorageInterface extends SupportAwareSectionStorageInterface, ThirdPartySettingsInterface, LayoutBuilderEnabledInterface, LayoutBuilderOverridableInterface {}
+5 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
use Drupal\layout_builder\Section;
use Drupal\layout_builder\SectionComponent;
use Drupal\layout_builder\SectionListTrait;
use Drupal\layout_builder\SectionStorage\SupportAwareSectionStorageManagerInterface;

/**
 * Provides an entity view display entity that has a layout.
@@ -300,7 +301,11 @@ public function buildMultiple(array $entities) {
      return $build_list;
    }

    $sectionStorageManager = $this->sectionStorageManager();
    foreach ($entities as $id => $entity) {
      if ($sectionStorageManager instanceof SupportAwareSectionStorageManagerInterface && $sectionStorageManager->notSupported($entity->getEntityTypeId(), $entity->bundle(), $this->mode)) {
        continue;
      }
      $build_list[$id]['_layout_builder'] = $this->buildSections($entity);

      // If there are any sections, remove all fields with configurable display
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
/**
 * Defines an interface for an object that stores layout sections for overrides.
 */
interface OverridesSectionStorageInterface extends SectionStorageInterface {
interface OverridesSectionStorageInterface extends SupportAwareSectionStorageInterface {

  /**
   * Returns the corresponding defaults section storage for this override.
+12 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
use Drupal\layout_builder\Attribute\SectionStorage;
use Drupal\layout_builder\DefaultsSectionStorageInterface;
use Drupal\layout_builder\Entity\SampleEntityGeneratorInterface;
use Drupal\layout_builder\LayoutBuilderEnabledInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\RouteCollection;

@@ -413,4 +414,15 @@ public function setContext($name, ComponentContextInterface $context) {
    parent::setContext($name, $context);
  }

  /**
   * {@inheritdoc}
   */
  public function isSupported(string $entity_type_id, string $bundle, string $view_mode): bool {
    $id = "$entity_type_id.$bundle.$view_mode";

    $storage = $this->entityTypeManager->getStorage('entity_view_display');
    $display = $storage->load($id) ?? $storage->load("$entity_type_id.$bundle.default");
    return $display instanceof LayoutBuilderEnabledInterface && $display->isLayoutBuilderEnabled();
  }

}
+16 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
use Drupal\Core\Url;
use Drupal\layout_builder\Attribute\SectionStorage;
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
use Drupal\layout_builder\Entity\LayoutEntityDisplayInterface;
use Drupal\layout_builder\LayoutEntityHelperTrait;
use Drupal\layout_builder\OverridesSectionStorageInterface;
use Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface;
@@ -402,4 +403,19 @@ public function isOverridden() {
    return !empty($this->getSections());
  }

  /**
   * {@inheritdoc}
   */
  public function isSupported(string $entity_type_id, string $bundle, string $view_mode): bool {
    // Layout builder currently only supports the default view mode.
    // @see https://www.drupal.org/node/2907413
    if ($view_mode !== 'default') {
      return FALSE;
    }
    $id = "$entity_type_id.$bundle.$view_mode";
    $storage = $this->entityTypeManager->getStorage('entity_view_display');
    $display = $storage->load($id);
    return $display instanceof LayoutEntityDisplayInterface && $display->isOverridable();
  }

}
Loading