You are here

protected function NameGenerator::filterByFieldSettings in Name Field 8

Helper function to filter the name components by the field definition.

Parameters

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

array $example_names: Array of names to filter.

Return value

array A nested array of name components.

2 calls to NameGenerator::filterByFieldSettings()
NameGenerator::generateSampleNames in src/NameGenerator.php
Service to generate random names.
NameGenerator::loadSampleValues in src/NameGenerator.php
Service to load preconfigured names.

File

src/NameGenerator.php, line 214

Class

NameGenerator
Handles name generation.

Namespace

Drupal\name

Code

protected function filterByFieldSettings(FieldDefinitionInterface $field_definition, array $example_names = []) {
  $settings = $field_definition
    ->getSettings();
  $components = array_keys(array_filter($settings['components']));
  $components = array_combine($components, $components);
  foreach ($example_names as $delta => $example_name) {
    $example_names[$delta] = array_intersect_key($example_name, $components);

    // This allows non-field defined properties like preferred through.
    $example_names[$delta] += array_diff_key($example_name, _name_component_keys());
  }
  return $example_names;
}