function TypedDataRelationship::getData

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

File

src/Plugin/Relationship/TypedDataRelationship.php, line 60

Class

TypedDataRelationship
Plugin annotation @Relationship( id = "typed_data_relationship", deriver = "\Drupal\ctools\Plugin\Deriver\TypedDataRelationshipDeriver" )

Namespace

Drupal\ctools\Plugin\Relationship

Code

protected function getData(ContextInterface $context) {
    
    /** @var \Drupal\Core\TypedData\ComplexDataInterface $base */
    $base = $context->getContextValue();
    $name = $this->getPluginDefinition()['property_name'];
    $data = $base->get($name);
    // @todo add configuration to get N instead of first.
    if ($data instanceof ListInterface) {
        $data = $data->first();
    }
    if ($data instanceof DataReferenceInterface) {
        $data = $data->getTarget();
    }
    return $data;
}