protected function TokenCustomStorage::doCreate in Custom Tokens 8
Performs storage-specific creation of entities.
Parameters
array $values: An array of values to set, keyed by property name.
Return value
\Drupal\Core\Entity\EntityInterface
Overrides ContentEntityStorageBase::doCreate
File
- src/
TokenCustomStorage.php, line 17
Class
- TokenCustomStorage
- Defines the storage for custom_token entities.
Namespace
Drupal\token_customCode
protected function doCreate(array $values) {
// When creating a new custom_token use any custom_token_type.
if (empty($values['type'])) {
$types = TokenCustomType::loadMultiple();
if ($types) {
$values['type'] = current($types)
->id();
}
else {
throw new EntityStorageException('Cannot create token_custom because no token_custom_type has been created.');
}
}
return parent::doCreate($values);
}