You are here

public static function DateTimeDayItem::generateSampleValue in Date time day 8

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 DateTimeItem::generateSampleValue

File

src/Plugin/Field/FieldType/DateTimeDayItem.php, line 124

Class

DateTimeDayItem
Plugin implementation of the 'datetimeday' field type.

Namespace

Drupal\date_time_day\Plugin\Field\FieldType

Code

public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
  $values = parent::generateSampleValue($field_definition);
  $timestamp = microtime() - mt_rand(0, 86400 * 365);
  $start = $timestamp - 3600;
  $end = $start + 3600;
  $type = $field_definition
    ->getSetting('time_type');
  if ($type === static::DATEDAY_TIME_DEFAULT_TYPE_FORMAT) {
    $values['start_time_value'] = gmdate(static::DATE_TIME_DAY_H_I_FORMAT_STORAGE_FORMAT, $start);
    $values['end_time_value'] = gmdate(static::DATE_TIME_DAY_H_I_FORMAT_STORAGE_FORMAT, $end);
  }
  if ($type === static::DATEDAY_TIME_TYPE_SECONDS_FORMAT) {
    $values['start_time_value'] = gmdate(static::DATE_TIME_DAY_H_I_S_FORMAT_STORAGE_FORMAT, $start);
    $values['end_time_value'] = gmdate(static::DATE_TIME_DAY_H_I_S_FORMAT_STORAGE_FORMAT, $end);
  }
  return $values;
}