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

/**
 * @file
5
 * Contains \Drupal\Core\Field\Plugin\Field\FieldType\TimestampItem.
6 7 8 9
 */

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

10
use Drupal\Core\Field\FieldStorageDefinitionInterface;
11 12 13 14 15 16 17 18 19 20
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."),
21
 *   no_ui = TRUE,
22
 *   default_widget = "datetime_default",
23 24 25 26 27 28 29 30 31 32 33 34
 *   default_formatter = "timestamp",
 *   constraints = {
 *     "ComplexData" = {
 *       "value" = {
 *         "Range" = {
 *           "min" = "-2147483648",
 *           "max" = "2147483648",
 *         }
 *       }
 *     }
 *   }
 * )
35 36 37 38 39 40 41
 * )
 */
class TimestampItem extends FieldItemBase {

  /**
   * {@inheritdoc}
   */
42
  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
43
    $properties['value'] = DataDefinition::create('timestamp')
44 45
      ->setLabel(t('Timestamp value'))
      ->setRequired(TRUE);
46 47 48 49 50 51
    return $properties;
  }

  /**
   * {@inheritdoc}
   */
52
  public static function schema(FieldStorageDefinitionInterface $field_definition) {
53 54 55 56 57 58 59 60
    return array(
      'columns' => array(
        'value' => array(
          'type' => 'int',
        ),
      ),
    );
  }
61

62
}