function DataReferenceDefinition::create

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

Creates a new data reference definition.

Parameters

string $target_data_type: The data type of the referenced data.

Return value

static

Overrides DataDefinition::create

4 calls to DataReferenceDefinition::create()
DataReferenceDefinition::createFromDataType in core/lib/Drupal/Core/TypedData/DataReferenceDefinition.php
EntityTypedDataDefinitionTest::testEntityReferences in core/tests/Drupal/KernelTests/Core/Entity/EntityTypedDataDefinitionTest.php
Tests deriving metadata from entity references.
TypedDataDefinitionTest::testDataReferences in core/tests/Drupal/KernelTests/Core/TypedData/TypedDataDefinitionTest.php
Tests deriving metadata from data references.
TypedDataDefinitionTest::testNotImplementedGetType in core/tests/Drupal/KernelTests/Core/TypedData/TypedDataDefinitionTest.php
Tests getString() throws exception when getType() is not implemented.

File

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

Class

DataReferenceDefinition
A typed data definition class for defining references.

Namespace

Drupal\Core\TypedData

Code

public static function create($target_data_type) {
    // This assumes implementations use a "TYPE_reference" naming pattern.
    $definition = parent::create($target_data_type . '_reference');
    return $definition->setTargetDefinition(\Drupal::typedDataManager()->createDataDefinition($target_data_type));
}

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