CreatedItem.php 720 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 14
 *   default_widget = "datetime_default",
 *   default_formatter = "timestamp"
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
 * )
 */
class CreatedItem extends TimestampItem {

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

}