You are here

public function ContextDefinition::getDataDefinition in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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

File

core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php, line 238
Contains \Drupal\Core\Plugin\Context\ContextDefinition.

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