You are here

public function RadioactivityStorage::createWithSampleValues in Radioactivity 4.0.x

Creates an entity with sample field values.

Parameters

string|bool $bundle: (optional) The entity bundle.

array $values: (optional) Any default values to use during generation.

Return value

\Drupal\Core\Entity\FieldableEntityInterface A fieldable content entity.

Throws

\Drupal\Core\Entity\EntityStorageException Thrown if the bundle does not exist or was needed but not specified.

Overrides ContentEntityStorageBase::createWithSampleValues

File

src/RadioactivityStorage.php, line 15

Class

RadioactivityStorage
Defines the storage handler class for radioactivity entities.

Namespace

Drupal\radioactivity

Code

public function createWithSampleValues($bundle = FALSE, array $values = []) {

  // Only allow a limited set of field names.
  $values = array_intersect_key($values, array_flip([
    'energy',
    'timestamp',
    'langcode',
  ]));
  $values += [
    'energy' => rand(1, 100),
    'timestamp' => time(),
  ];
  return $this
    ->create($values);
}