Creates a new typed data object wrapping the passed value.
array $definition: The data definition array with the following array keys and values:
Further keys may be supported in certain usages, e.g. for further keys supported for entity field definitions see Drupal\Core\Entity\StorageControllerInterface::getPropertyDefinitions().
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.
array $context: (optional) An array describing the context of the data object, e.g. its name or parent data structure. The context should be passed if a typed data object is created as part of a data structure. The following keys are supported:
Drupal\Core\TypedData\TypedDataInterface
Drupal\Core\TypedData\Type\Integer
Drupal\Core\TypedData\Type\Float
Drupal\Core\TypedData\Type\String
Drupal\Core\TypedData\Type\Boolean
Drupal\Core\TypedData\Type\Duration
Drupal\Core\TypedData\Type\Date
Drupal\Core\TypedData\Type\Uri
Drupal\Core\TypedData\Type\Binary
Drupal\Core\Entity\Field\EntityWrapper
function create(array $definition, $value = NULL, array $context = array()) {
$wrapper = $this
->createInstance($definition['type'], $definition);
if (isset($value)) {
$wrapper
->setValue($value);
}
if ($wrapper instanceof ContextAwareInterface) {
if (isset($context['name'])) {
$wrapper
->setName($context['name']);
}
if (isset($context['parent'])) {
$wrapper
->setParent($context['parent']);
}
}
return $wrapper;
}