public function ContextDefinition::getDataDefinition in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php \Drupal\Core\Plugin\Context\ContextDefinition::getDataDefinition()
Returns the data definition of the defined context.
Return value
\Drupal\Core\TypedData\DataDefinitionInterface The data definition object.
Overrides ContextDefinitionInterface::getDataDefinition
1 call to ContextDefinition::getDataDefinition()
- ContextDefinition::getSampleValues in core/
lib/ Drupal/ Core/ Plugin/ Context/ ContextDefinition.php - Returns typed data objects representing this context definition.
File
- core/
lib/ Drupal/ Core/ Plugin/ Context/ ContextDefinition.php, line 243
Class
- ContextDefinition
- Defines a class for context definitions.
Namespace
Drupal\Core\Plugin\ContextCode
public function getDataDefinition() {
if ($this
->isMultiple()) {
$definition = $this
->getTypedDataManager()
->createListDataDefinition($this
->getDataType());
}
else {
$definition = $this
->getTypedDataManager()
->createDataDefinition($this
->getDataType());
}
if (!$definition) {
throw new \Exception("The data type '{$this->getDataType()}' is invalid");
}
$definition
->setLabel($this
->getLabel())
->setDescription($this
->getDescription())
->setRequired($this
->isRequired());
$constraints = $definition
->getConstraints() + $this
->getConstraints();
$definition
->setConstraints($constraints);
return $definition;
}