You are here

public function TypedDataLanguageRelationship::getRelationship in Chaos Tool Suite (ctools) 8.3

Generates a context based on this plugin's configuration.

Return value

\Drupal\Core\Plugin\Context\ContextInterface

Overrides TypedDataRelationship::getRelationship

File

src/Plugin/Relationship/TypedDataLanguageRelationship.php, line 19

Class

TypedDataLanguageRelationship
Plugin annotation @Relationship( id = "typed_data_language_relationship", deriver = "\Drupal\ctools\Plugin\Deriver\TypedDataLanguageRelationshipDeriver" )

Namespace

Drupal\ctools\Plugin\Relationship

Code

public function getRelationship() {
  $plugin_definition = $this
    ->getPluginDefinition();
  $context_definition = new ContextDefinition("language", $plugin_definition['label']);
  $context_value = NULL;

  // If the 'base' context has a value, then get the property value to put on
  // the context (otherwise, mapping hasn't occurred yet and we just want to
  // return the context with the right definition and no value).
  if ($this
    ->getContext('base')
    ->hasContextValue()) {
    $context_value = $this
      ->getData($this
      ->getContext('base'))->language;
  }
  $context_definition
    ->setDefaultValue($context_value);
  return new Context($context_definition, $context_value);
}