CreatedItem.php 805 Bytes
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\Core\Field\Plugin\Field\FieldType\CreatedItem.
6 7 8 9 10 11 12 13 14 15 16
 */

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."),
17
 *   no_ui = TRUE,
18 19
 *   default_widget = "datetime_default",
 *   default_formatter = "timestamp"
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
 * )
 */
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;
  }

}