You are here

protected function StaticContextConfigure::addContext in Page Manager 8.4

Same name and namespace in other branches
  1. 8 page_manager_ui/src/Form/StaticContextConfigure.php \Drupal\page_manager_ui\Form\StaticContextConfigure::addContext()

Custom logic for adding a context to the cached_values contexts array.

Parameters

array $cached_values: The cached_values currently in use.

string $context_id: The context identifier.

\Drupal\Core\Plugin\Context\ContextInterface $context: The context to add or update within the cached values.

Return value

mixed Return the $cached_values

Overrides ContextConfigure::addContext

File

page_manager_ui/src/Form/StaticContextConfigure.php, line 85

Class

StaticContextConfigure

Namespace

Drupal\page_manager_ui\Form

Code

protected function addContext($cached_values, $context_id, ContextInterface $context) {

  /** @var $page_variant \Drupal\page_manager\PageVariantInterface */
  $page_variant = $this
    ->getPageVariant($cached_values);
  $context_config = [
    'label' => $context
      ->getContextDefinition()
      ->getLabel(),
    'type' => $context
      ->getContextDefinition()
      ->getDataType(),
    'description' => $context
      ->getContextDefinition()
      ->getDescription(),
    'value' => strpos($context
      ->getContextDefinition()
      ->getDataType(), 'entity:') === 0 ? $context
      ->getContextValue()
      ->uuid() : $context
      ->getContextValue(),
  ];
  $page_variant
    ->setStaticContext($context_id, $context_config);
  $cached_values['page_variant'] = $page_variant;
  return $cached_values;
}