You are here

protected function LayoutBuilderContextTrait::getPopulatedContexts in Drupal 9

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.

8 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
Form constructor.

... See full list

File

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

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;
}