Skip to content

Services Overview

Name module behavior is centered around container services. This is the recommended API surface for custom code.

Core services

Service ID Interface Class
name.formatter Drupal\name\Service\NameFormatterInterface Drupal\name\Service\NameFormatterService
name.format_parser Drupal\name\Service\NameFormatParserInterface Drupal\name\Service\NameFormatParserService
name.generator Drupal\name\Service\GeneratorInterface Drupal\name\Service\GeneratorService
name.autocomplete Drupal\name\Service\AutocompleteInterface Drupal\name\Service\AutocompleteService
name.options_provider Drupal\name\Service\NameOptionInterface Drupal\name\Service\NameOptionService

Additional services

Service ID Doc Notes
name.additional_component Additional Component Preferred/alternative field references (@internal)
name.format_options Format Options Format/list-format select options (@internal)
name.element_validator Element Validator Name element validation (@internal)
name.widget_layouts Widget Layouts hook Layout discovery and cache
name.link_target Link Target Formatter link targets (@internal)
name.formatter_summary Formatter Summary Formatter settings summary (@internal)
name.user_realname_preload User integration Preloads user for realname (@internal)
name.component_metadata Element Validator Component labels for settings UI (@internal)
name.twig.name_format_help Help integration Twig extension; not for general DI

name.twig.name_format_help registers name_format_token_help() for help topic templates only.

Use these when extending deeper module behavior (widget layouts, option maps, component metadata, or validation flow).

Dependency injection pattern

Prefer interface type hints and container injection:

use Drupal\name\Service\GeneratorInterface;

final class ExampleService {

  public function __construct(
    private readonly GeneratorInterface $generator,
  ) {}
}

If you need a quick ad hoc call:

$generator = \Drupal::service('name.generator');
$samples = $generator->generateSampleNames(3);

Legacy compatibility note

Some legacy interface aliases and wrapper functions remain for backward compatibility, but new development should target service interfaces and service IDs listed above. See API Overview — Legacy procedural helpers.