function TypedDataEntityRelationship::getRelationship

Same name in other branches
  1. 4.0.x src/Plugin/Relationship/TypedDataEntityRelationship.php \Drupal\ctools\Plugin\Relationship\TypedDataEntityRelationship::getRelationship()

Overrides TypedDataRelationship::getRelationship

File

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

Class

TypedDataEntityRelationship
Plugin annotation @Relationship( id = "typed_data_entity_relationship", deriver = "\Drupal\ctools\Plugin\Deriver\TypedDataEntityRelationshipDeriver" )

Namespace

Drupal\ctools\Plugin\Relationship

Code

public function getRelationship() {
    $plugin_definition = $this->getPluginDefinition();
    $context_definition = new EntityContextDefinition("entity:{$plugin_definition['target_entity_type']}", $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()) {
        $data = $this->getData($this->getContext('base'));
        if ($data) {
            $context_value = $data->entity;
        }
    }
    $context_definition->setDefaultValue($context_value);
    return new Context($context_definition, $context_value);
}