CreatedItem.php

Same filename in other branches
  1. 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/CreatedItem.php
  2. 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldType/CreatedItem.php
  3. 10 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;

use Drupal\Core\Field\Attribute\FieldType;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Defines the 'created' entity field type.
 */
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

Title Deprecated Summary
CreatedItem Defines the 'created' entity field type.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.