CreatedItem.php 717 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11
<?php

namespace Drupal\Core\Field\Plugin\Field\FieldType;

/**
 * Defines the 'created' entity field type.
 *
 * @FieldType(
 *   id = "created",
 *   label = @Translation("Created"),
 *   description = @Translation("An entity field containing a UNIX timestamp of when the entity has been created."),
12
 *   no_ui = TRUE,
13
 *   default_widget = "datetime_timestamp",
14
 *   default_formatter = "timestamp"
15 16 17 18 19 20 21 22 23 24
 * )
 */
class CreatedItem extends TimestampItem {

  /**
   * {@inheritdoc}
   */
  public function applyDefaultValue($notify = TRUE) {
    parent::applyDefaultValue($notify);
    // Created fields default to the current timestamp.
25
    $this->setValue(['value' => REQUEST_TIME], $notify);
26 27 28 29
    return $this;
  }

}