Version 1
[yaffs-website] / web / modules / contrib / ctools / src / Plugin / Relationship / TypedDataLanguageRelationship.php
1 <?php
2
3 namespace Drupal\ctools\Plugin\Relationship;
4 use Drupal\Core\Plugin\Context\Context;
5 use Drupal\Core\Plugin\Context\ContextDefinition;
6
7 /**
8  * @Relationship(
9  *   id = "typed_data_language_relationship",
10  *   deriver = "\Drupal\ctools\Plugin\Deriver\TypedDataLanguageRelationshipDeriver"
11  * )
12  */
13 class TypedDataLanguageRelationship extends TypedDataRelationship {
14
15   /**
16    * {@inheritdoc}
17    */
18   public function getRelationship() {
19     $plugin_definition = $this->getPluginDefinition();
20
21     $context_definition = new ContextDefinition("language", $plugin_definition['label']);
22     $context_value = NULL;
23
24     // If the 'base' context has a value, then get the property value to put on
25     // the context (otherwise, mapping hasn't occurred yet and we just want to
26     // return the context with the right definition and no value).
27     if ($this->getContext('base')->hasContextValue()) {
28       $context_value = $this->getData($this->getContext('base'))->language;
29     }
30
31     $context_definition->setDefaultValue($context_value);
32     return new Context($context_definition, $context_value);
33   }
34
35 }