function ContextDefinition::getDataDefinition
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 247
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;
}