function DataReferenceDefinition::createFromDataType

Same name in other branches
  1. 9 core/lib/Drupal/Core/TypedData/DataReferenceDefinition.php \Drupal\Core\TypedData\DataReferenceDefinition::createFromDataType()
  2. 10 core/lib/Drupal/Core/TypedData/DataReferenceDefinition.php \Drupal\Core\TypedData\DataReferenceDefinition::createFromDataType()
  3. 11.x core/lib/Drupal/Core/TypedData/DataReferenceDefinition.php \Drupal\Core\TypedData\DataReferenceDefinition::createFromDataType()

Overrides DataDefinition::createFromDataType

File

core/lib/Drupal/Core/TypedData/DataReferenceDefinition.php, line 37

Class

DataReferenceDefinition
A typed data definition class for defining references.

Namespace

Drupal\Core\TypedData

Code

public static function createFromDataType($data_type) {
    if (substr($data_type, -strlen('_reference')) != '_reference') {
        throw new \InvalidArgumentException('Data type must be of the form "{TARGET_TYPE}_reference"');
    }
    // Cut of the _reference suffix.
    return static::create(substr($data_type, 0, strlen($data_type) - strlen('_reference')));
}

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