UuidItem.php in Drupal 9
File
core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UuidItem.php
View source
<?php
namespace Drupal\Core\Field\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
class UuidItem extends StringItem {
public static function defaultStorageSettings() {
return [
'max_length' => 128,
'is_ascii' => TRUE,
] + parent::defaultStorageSettings();
}
public function applyDefaultValue($notify = TRUE) {
$uuid = \Drupal::service('uuid');
$this
->setValue([
'value' => $uuid
->generate(),
], $notify);
return $this;
}
public static function schema(FieldStorageDefinitionInterface $field_definition) {
$schema = parent::schema($field_definition);
$schema['unique keys']['value'] = [
'value',
];
return $schema;
}
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
$values['value'] = \Drupal::service('uuid')
->generate();
return $values;
}
}
Classes
Name |
Description |
UuidItem |
Defines the 'uuid' entity field type. |