contextRepository) { $this->contextRepository = \Drupal::service('context.repository'); } return $this->contextRepository; } /** * Provides all available contexts, both global and section_storage-specific. * * @param \Drupal\layout_builder\SectionStorageInterface $section_storage * The section storage. * * @return \Drupal\Core\Plugin\Context\ContextInterface[] * The array of context objects. */ protected function getAvailableContexts(SectionStorageInterface $section_storage) { // Get all globally available contexts that have a defined value. $contexts = array_filter($this->contextRepository()->getAvailableContexts(), function (ContextInterface $context) { return $context->hasContextValue(); }); // Add in the per-section_storage contexts. $contexts += $section_storage->getContexts(); return $contexts; } }