public function TypedDataRelationship::getRelationship in Chaos Tool Suite (ctools) 8.3
Generates a context based on this plugin's configuration.
Return value
\Drupal\Core\Plugin\Context\ContextInterface
Overrides RelationshipInterface::getRelationship
2 methods override TypedDataRelationship::getRelationship()
- TypedDataEntityRelationship::getRelationship in src/
Plugin/ Relationship/ TypedDataEntityRelationship.php - Generates a context based on this plugin's configuration.
- TypedDataLanguageRelationship::getRelationship in src/
Plugin/ Relationship/ TypedDataLanguageRelationship.php - Generates a context based on this plugin's configuration.
File
- src/
Plugin/ Relationship/ TypedDataRelationship.php, line 25
Class
- TypedDataRelationship
- Plugin annotation @Relationship( id = "typed_data_relationship", deriver = "\Drupal\ctools\Plugin\Deriver\TypedDataRelationshipDeriver" )
Namespace
Drupal\ctools\Plugin\RelationshipCode
public function getRelationship() {
$plugin_definition = $this
->getPluginDefinition();
$data_type = $plugin_definition['data_type'];
if (strpos($data_type, 'entity:') === 0) {
$context_definition = new EntityContextDefinition($data_type, $plugin_definition['label']);
}
else {
$context_definition = new ContextDefinition($data_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'));
$property = $this
->getMainPropertyName($data);
$context_value = $data
->get($property)
->getValue();
}
$context_definition
->setDefaultValue($context_value);
return new Context($context_definition, $context_value);
}