UuidItem.php 788 Bytes
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\Core\Entity\Plugin\Field\FieldType\UuidItem.
6 7
 */

8
namespace Drupal\Core\Field\Plugin\Field\FieldType;
9 10

/**
11
 * Defines the 'uuid' entity field type.
12 13 14
 *
 * The field uses a newly generated UUID as default value.
 *
15 16 17
 * @FieldType(
 *   id = "uuid",
 *   label = @Translation("UUID"),
18
 *   description = @Translation("An entity field containing a UUID."),
19 20 21 22
 *   settings = {
 *     "max_length" = "128"
 *   },
 *   configurable = FALSE
23 24 25 26 27 28 29 30 31
 * )
 */
class UuidItem extends StringItem {

  /**
   * {@inheritdoc}
   */
  public function applyDefaultValue($notify = TRUE) {
    // Default to one field item with a generated UUID.
32
    $uuid = \Drupal::service('uuid');
33 34 35 36
    $this->setValue(array('value' => $uuid->generate()), $notify);
    return $this;
  }
}