class TypedDataRelationship
Same name in other branches
- 8.x-3.x src/Plugin/Relationship/TypedDataRelationship.php \Drupal\ctools\Plugin\Relationship\TypedDataRelationship
Plugin annotation
@Relationship(
id = "typed_data_relationship",
deriver = "\Drupal\ctools\Plugin\Deriver\TypedDataRelationshipDeriver"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
- class \Drupal\ctools\Plugin\RelationshipBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\ctools\Plugin\RelationshipInterface uses \Drupal\Core\Plugin\ContextAwarePluginTrait
- class \Drupal\ctools\Plugin\Relationship\TypedDataRelationship extends \Drupal\ctools\Plugin\RelationshipBase
- class \Drupal\ctools\Plugin\RelationshipBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\ctools\Plugin\RelationshipInterface uses \Drupal\Core\Plugin\ContextAwarePluginTrait
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
Expanded class hierarchy of TypedDataRelationship
File
-
src/
Plugin/ Relationship/ TypedDataRelationship.php, line 20
Namespace
Drupal\ctools\Plugin\RelationshipView source
class TypedDataRelationship extends RelationshipBase {
/**
* {@inheritdoc}
*/
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);
}
/**
*
*/
public function getName() {
return $this->getPluginDefinition()['property_name'];
}
/**
*
*/
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;
}
/**
*
*/
protected function getMainPropertyName(FieldItemInterface $data) {
return $data->getFieldDefinition()
->getFieldStorageDefinition()
->getMainPropertyName();
}
/**
*
*/
public function getRelationshipValue() {
$property = $this->getMainPropertyName();
/** @var \Drupal\Core\TypedData\ComplexDataInterface $data */
$data = $this->getRelationship()
->getContextData();
$data->get($property)
->getValue();
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
TypedDataRelationship::getData | protected | function | ||
TypedDataRelationship::getMainPropertyName | protected | function | ||
TypedDataRelationship::getName | public | function | ||
TypedDataRelationship::getRelationship | public | function | 2 | |
TypedDataRelationship::getRelationshipValue | public | function |