Version 1
[yaffs-website] / web / modules / contrib / ctools / src / Plugin / Relationship / TypedDataEntityRelationship.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_entity_relationship",
10  *   deriver = "\Drupal\ctools\Plugin\Deriver\TypedDataEntityRelationshipDeriver"
11  * )
12  */
13 class TypedDataEntityRelationship extends TypedDataRelationship {
14
15   /**
16    * {@inheritdoc}
17    */
18   public function getRelationship() {
19     $plugin_definition = $this->getPluginDefinition();
20
21     $entity_type = $this->getData($this->getContext('base'))->getDataDefinition()->getSetting('target_type');
22     $context_definition = new ContextDefinition("entity:$entity_type", $plugin_definition['label']);
23     $context_value = NULL;
24
25     // If the 'base' context has a value, then get the property value to put on
26     // the context (otherwise, mapping hasn't occurred yet and we just want to
27     // return the context with the right definition and no value).
28     if ($this->getContext('base')->hasContextValue()) {
29       $context_value = $this->getData($this->getContext('base'))->entity;
30     }
31
32     $context_definition->setDefaultValue($context_value);
33     return new Context($context_definition, $context_value);
34   }
35
36 }