You are here

public static function SmartDateItem::generateSampleValue in Smart Date 3.1.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldType/SmartDateItem.php \Drupal\smart_date\Plugin\Field\FieldType\SmartDateItem::generateSampleValue()
  2. 8 src/Plugin/Field/FieldType/SmartDateItem.php \Drupal\smart_date\Plugin\Field\FieldType\SmartDateItem::generateSampleValue()
  3. 3.x src/Plugin/Field/FieldType/SmartDateItem.php \Drupal\smart_date\Plugin\Field\FieldType\SmartDateItem::generateSampleValue()
  4. 3.0.x src/Plugin/Field/FieldType/SmartDateItem.php \Drupal\smart_date\Plugin\Field\FieldType\SmartDateItem::generateSampleValue()
  5. 3.2.x src/Plugin/Field/FieldType/SmartDateItem.php \Drupal\smart_date\Plugin\Field\FieldType\SmartDateItem::generateSampleValue()
  6. 3.3.x src/Plugin/Field/FieldType/SmartDateItem.php \Drupal\smart_date\Plugin\Field\FieldType\SmartDateItem::generateSampleValue()
  7. 3.4.x src/Plugin/Field/FieldType/SmartDateItem.php \Drupal\smart_date\Plugin\Field\FieldType\SmartDateItem::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 TimestampItem::generateSampleValue

File

src/Plugin/Field/FieldType/SmartDateItem.php, line 133

Class

SmartDateItem
Plugin implementation of the 'smartdate' field type.

Namespace

Drupal\smart_date\Plugin\Field\FieldType

Code

public static function generateSampleValue(FieldDefinitionInterface $field_definition) {

  // Pick a random timestamp in the past year.
  $timestamp = \Drupal::time()
    ->getRequestTime() - mt_rand(0, 86400 * 365);
  $duration = 60;
  $values['value'] = $timestamp;
  $values['end_value'] = $timestamp + $duration * 60;
  $values['duration'] = $duration;
  $values['timezone'] = 'UTC';
  return $values;
}