W3cubDocs

/Drupal 8

public function TypedDataManager::create

public TypedDataManager::create(DataDefinitionInterface $definition, $value = NULL, $name = NULL, $parent = NULL)

Creates a new typed data object instance.

Parameters

\Drupal\Core\TypedData\DataDefinitionInterface $definition: The data definition of the typed data object. For backwards-compatibility an array representation of the data definition may be passed also.

mixed $value: (optional) The data value. If set, it has to match one of the supported data type format as documented for the data type classes.

string $name: (optional) If a property or list item is to be created, the name of the property or the delta of the list item.

mixed $parent: (optional) If a property or list item is to be created, the parent typed data object implementing either the ListInterface or the ComplexDataInterface.

Return value

\Drupal\Core\TypedData\TypedDataInterface The instantiated typed data object.

Overrides TypedDataManagerInterface::create

See also

\Drupal\Core\TypedData\TypedDataManager::getPropertyInstance()

\Drupal\Core\TypedData\Plugin\DataType\BinaryData

\Drupal\Core\TypedData\Plugin\DataType\BooleanData

\Drupal\Core\TypedData\Plugin\DataType\Date

\Drupal\Core\TypedData\Plugin\DataType\Duration

\Drupal\Core\TypedData\Plugin\DataType\FloatData

\Drupal\Core\TypedData\Plugin\DataType\IntegerData

\Drupal\Core\TypedData\Plugin\DataType\StringData

\Drupal\Core\TypedData\Plugin\DataType\Uri

File

core/lib/Drupal/Core/TypedData/TypedDataManager.php, line 99

Class

TypedDataManager
Manages data type plugins.

Namespace

Drupal\Core\TypedData

Code

public function create(DataDefinitionInterface $definition, $value = NULL, $name = NULL, $parent = NULL) {
  $typed_data = $this->createInstance($definition->getDataType(), array(
    'data_definition' => $definition,
    'name' => $name,
    'parent' => $parent,
  ));
  if (isset($value)) {
    $typed_data->setValue($value, FALSE);
  }
  return $typed_data;
}

© 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!TypedDataManager.php/function/TypedDataManager::create/8.1.x