Skip to content

Name Options Provider Service

Service identity

  • Service ID: name.options_provider
  • Interface: Drupal\name\Service\NameOptionInterface
  • Class: Drupal\name\Service\NameOptionService

Use this service to resolve option lists for components such as title and generational.

Quick use

$optionsProvider = \Drupal::service('name.options_provider');
$titles = $optionsProvider->getOptions($fieldDefinition, 'title');

Primary method

getOptions(FieldDefinitionInterface $field, $component)

Returns a normalized options array for a component:

  • reads field-level options ({component}_options)
  • expands taxonomy references such as [vocabulary:professional_titles]
  • removes duplicates
  • enforces max-length constraints

Injection example

use Drupal\name\Service\NameOptionInterface;

final class NameOptionConsumer {

  public function __construct(
    private readonly NameOptionInterface $options,
  ) {}
}