function LayoutBuilderContextTrait::getPopulatedContexts

Same name in other branches
  1. 9 core/modules/layout_builder/src/Context/LayoutBuilderContextTrait.php \Drupal\layout_builder\Context\LayoutBuilderContextTrait::getPopulatedContexts()
  2. 10 core/modules/layout_builder/src/Context/LayoutBuilderContextTrait.php \Drupal\layout_builder\Context\LayoutBuilderContextTrait::getPopulatedContexts()

Returns all populated contexts, both global and section-storage-specific.

Parameters

\Drupal\layout_builder\SectionStorageInterface $section_storage: The section storage.

Return value

\Drupal\Core\Plugin\Context\ContextInterface[] The array of context objects.

7 calls to LayoutBuilderContextTrait::getPopulatedContexts()
ChooseBlockController::build in core/modules/layout_builder/src/Controller/ChooseBlockController.php
Provides the UI for choosing a new block.
ChooseBlockController::inlineBlockList in core/modules/layout_builder/src/Controller/ChooseBlockController.php
Provides the UI for choosing a new inline block.
ChooseSectionController::build in core/modules/layout_builder/src/Controller/ChooseSectionController.php
Choose a layout plugin to add as a section.
ConfigureBlockFormBase::doBuildForm in core/modules/layout_builder/src/Form/ConfigureBlockFormBase.php
Builds the form for the block.
ConfigureSectionForm::buildForm in core/modules/layout_builder/src/Form/ConfigureSectionForm.php

... See full list

File

core/modules/layout_builder/src/Context/LayoutBuilderContextTrait.php, line 42

Class

LayoutBuilderContextTrait
Provides a wrapper around getting contexts from a section storage object.

Namespace

Drupal\layout_builder\Context

Code

protected function getPopulatedContexts(SectionStorageInterface $section_storage) : array {
    // Get all known globally available contexts IDs.
    $available_context_ids = array_keys($this->contextRepository()
        ->getAvailableContexts());
    // Filter to those that are populated.
    $contexts = array_filter($this->contextRepository()
        ->getRuntimeContexts($available_context_ids), function (ContextInterface $context) {
        return $context->hasContextValue();
    });
    // Add in the per-section_storage contexts.
    $contexts += $section_storage->getContextsDuringPreview();
    return $contexts;
}

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