Same filename and directory in other branches
  1. 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldType/CreatedItem.php
  2. 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/CreatedItem.php

Namespace

Drupal\Core\Field\Plugin\Field\FieldType

File

core/lib/Drupal/Core/Field/Plugin/Field/FieldType/CreatedItem.php
View source
<?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."),
 *   no_ui = TRUE,
 *   default_widget = "datetime_timestamp",
 *   default_formatter = "timestamp"
 * )
 */
class CreatedItem extends TimestampItem {

  /**
   * {@inheritdoc}
   */
  public function applyDefaultValue($notify = TRUE) {
    parent::applyDefaultValue($notify);

    // Created fields default to the current timestamp.
    $this
      ->setValue([
      'value' => \Drupal::time()
        ->getRequestTime(),
    ], $notify);
    return $this;
  }

}

Classes

Namesort descending Description
CreatedItem Defines the 'created' entity field type.