function LayoutBuilderEntityViewDisplayForm::isCanonicalMode

Same name in other branches
  1. 9 core/modules/layout_builder/src/Form/LayoutBuilderEntityViewDisplayForm.php \Drupal\layout_builder\Form\LayoutBuilderEntityViewDisplayForm::isCanonicalMode()
  2. 8.9.x core/modules/layout_builder/src/Form/LayoutBuilderEntityViewDisplayForm.php \Drupal\layout_builder\Form\LayoutBuilderEntityViewDisplayForm::isCanonicalMode()
  3. 11.x core/modules/layout_builder/src/Form/LayoutBuilderEntityViewDisplayForm.php \Drupal\layout_builder\Form\LayoutBuilderEntityViewDisplayForm::isCanonicalMode()

Determines if the mode is used by the canonical route.

Parameters

string $mode: The view mode.

Return value

bool TRUE if the mode is valid, FALSE otherwise.

1 call to LayoutBuilderEntityViewDisplayForm::isCanonicalMode()
LayoutBuilderEntityViewDisplayForm::form in core/modules/layout_builder/src/Form/LayoutBuilderEntityViewDisplayForm.php
Gets the actual form array to be built.

File

core/modules/layout_builder/src/Form/LayoutBuilderEntityViewDisplayForm.php, line 135

Class

LayoutBuilderEntityViewDisplayForm
Edit form for the LayoutBuilderEntityViewDisplay entity type.

Namespace

Drupal\layout_builder\Form

Code

protected function isCanonicalMode($mode) {
    // @todo This is a convention core uses but is not a given, nor is it easily
    //   introspectable. Address in https://www.drupal.org/node/2907413.
    $canonical_mode = 'full';
    if ($mode === $canonical_mode) {
        return TRUE;
    }
    // The default mode is valid if the canonical mode is not enabled.
    if ($mode === 'default') {
        
        /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $storage */
        $storage = $this->entityTypeManager
            ->getStorage($this->entity
            ->getEntityTypeId());
        $query = $storage->getQuery()
            ->condition('targetEntityType', $this->entity
            ->getTargetEntityTypeId())
            ->condition('bundle', $this->entity
            ->getTargetBundle())
            ->condition('status', TRUE)
            ->condition('mode', $canonical_mode);
        return !$query->count()
            ->execute();
    }
    return FALSE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.