3 namespace Drupal\ctools\Plugin\Relationship;
4 use Drupal\Core\Plugin\Context\Context;
5 use Drupal\Core\Plugin\Context\ContextDefinition;
9 * id = "typed_data_entity_relationship",
10 * deriver = "\Drupal\ctools\Plugin\Deriver\TypedDataEntityRelationshipDeriver"
13 class TypedDataEntityRelationship extends TypedDataRelationship {
18 public function getRelationship() {
19 $plugin_definition = $this->getPluginDefinition();
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;
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;
32 $context_definition->setDefaultValue($context_value);
33 return new Context($context_definition, $context_value);