You are here

protected function OgContext::getOgContext in Organic groups 8

Returns the context object containing the relevant group.

Return value

\Drupal\Core\Plugin\Context\Context A context object containing the group which is relevant in the current context as a value. If there is no relevant group in the current context then the value will be empty.

1 call to OgContext::getOgContext()
OgContext::getRuntimeContexts in src/ContextProvider/OgContext.php
Gets runtime context values for the given context IDs.

File

src/ContextProvider/OgContext.php, line 100

Class

OgContext
Provides the group that best matches the current context.

Namespace

Drupal\og\ContextProvider

Code

protected function getOgContext() {
  $context_definition = new ContextDefinition('entity', $this
    ->t('Active group'), FALSE);
  $candidate = $this
    ->getBestCandidate();
  $group = !empty($candidate['entity']) ? $candidate['entity'] : NULL;
  $context = new Context($context_definition, $group);
  $cacheability = new CacheableMetadata();
  if (!empty($candidate['cache_contexts'])) {
    $cacheability
      ->setCacheContexts($candidate['cache_contexts']);
  }
  $context
    ->addCacheableDependency($cacheability);
  return $context;
}