You are here

public static function DateTimeItem::generateSampleValue in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItem.php \Drupal\datetime\Plugin\Field\FieldType\DateTimeItem::generateSampleValue()

Generates placeholder field values.

Useful when populating site with placeholder content during site building or profiling.

Parameters

\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition.

Return value

array An associative array of values.

Overrides FieldItemBase::generateSampleValue

File

core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItem.php, line 108
Contains \Drupal\datetime\Plugin\Field\FieldType\DateTimeItem.

Class

DateTimeItem
Plugin implementation of the 'datetime' field type.

Namespace

Drupal\datetime\Plugin\Field\FieldType

Code

public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
  $type = $field_definition
    ->getSetting('datetime_type');

  // Just pick a date in the past year. No guidance is provided by this Field
  // type.
  $timestamp = REQUEST_TIME - mt_rand(0, 86400 * 365);
  if ($type == DateTimeItem::DATETIME_TYPE_DATE) {
    $values['value'] = gmdate(DATETIME_DATE_STORAGE_FORMAT, $timestamp);
  }
  else {
    $values['value'] = gmdate(DATETIME_DATETIME_STORAGE_FORMAT, $timestamp);
  }
  return $values;
}