You are here

public function NameGenerator::loadSampleValues in Name Field 8

Service to load preconfigured names.

Parameters

int $limit: The number to load.

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

Return value

array An array of name components.

Overrides NameGeneratorInterface::loadSampleValues

File

src/NameGenerator.php, line 157

Class

NameGenerator
Handles name generation.

Namespace

Drupal\name

Code

public function loadSampleValues($limit = 3, FieldDefinitionInterface $field_definition = NULL, $random = FALSE) {
  $example_names = $this
    ->loadConfiguration('name.generate.examples', 'examples', $field_definition);

  // Randomly shuffle and get the required count.
  if ($random) {
    shuffle($example_names);
  }
  $example_names = array_slice($example_names, 0, $limit);

  // Filter to the enabled components if we have field context.
  if ($field_definition) {
    $example_names = $this
      ->filterByFieldSettings($field_definition, $example_names);
  }
  return $example_names;
}