Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ContextDefinition.php

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

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal