function ContextDefinition::getDataDefinition

Same name in other branches
  1. 9 core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php \Drupal\Core\Plugin\Context\ContextDefinition::getDataDefinition()
  2. 8.9.x core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php \Drupal\Core\Plugin\Context\ContextDefinition::getDataDefinition()
  3. 11.x core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php \Drupal\Core\Plugin\Context\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\Context

Code

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.