public static function DataReferenceDefinition::createFromDataType

public static DataReferenceDefinition::createFromDataType($data_type)

Creates a new data definition object.

This method is typically used by \Drupal\Core\TypedData\TypedDataManager::createDataDefinition() to build a definition object for an arbitrary data type. When the definition class is known, it is recommended to directly use the static create() method on that class instead; e.g.:

  $map_definition = \Drupal\Core\TypedData\MapDataDefinition::create();

Parameters

string $data_type: The data type, for which a data definition should be created.

Return value

static

Throws

\InvalidArgumentException If an unsupported data type gets passed to the class; e.g., 'string' to a definition class handling 'entity:* data types.

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

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!TypedData!DataReferenceDefinition.php/function/DataReferenceDefinition::createFromDataType/8.1.x