TimestampItem.php 1.26 KB
Newer Older
1 2 3 4
<?php

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

5
use Drupal\Core\Field\FieldStorageDefinitionInterface;
6 7 8 9 10 11 12 13 14 15
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\TypedData\DataDefinition;

/**
 * Defines the 'timestamp' entity field type.
 *
 * @FieldType(
 *   id = "timestamp",
 *   label = @Translation("Timestamp"),
 *   description = @Translation("An entity field containing a UNIX timestamp value."),
16
 *   default_widget = "datetime_default",
17 18 19 20 21 22 23 24 25 26 27 28
 *   default_formatter = "timestamp",
 *   constraints = {
 *     "ComplexData" = {
 *       "value" = {
 *         "Range" = {
 *           "min" = "-2147483648",
 *           "max" = "2147483648",
 *         }
 *       }
 *     }
 *   }
 * )
29 30 31 32 33 34 35
 * )
 */
class TimestampItem extends FieldItemBase {

  /**
   * {@inheritdoc}
   */
36
  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
37
    $properties['value'] = DataDefinition::create('timestamp')
38 39
      ->setLabel(t('Timestamp value'))
      ->setRequired(TRUE);
40 41 42 43 44 45
    return $properties;
  }

  /**
   * {@inheritdoc}
   */
46
  public static function schema(FieldStorageDefinitionInterface $field_definition) {
47 48 49 50 51 52 53 54
    return array(
      'columns' => array(
        'value' => array(
          'type' => 'int',
        ),
      ),
    );
  }
55

56
}