Skip to content

Format Options Service

Service identity

  • Service ID: name.format_options
  • Interface: Drupal\name\Service\FormatOptionInterface
  • Class: Drupal\name\Service\FormatOptionService
  • Visibility: @internal — used by formatter/widget settings forms; prefer config entities or formatter APIs for application code.

Loads labels and patterns from name_format and name_list_format config entities for select lists and programmatic format lookup.

Methods

getCustomFormatOptions(): array

Returns machine-name => label pairs for all name_format entities (sorted).

getCustomListFormatOptions(): array

Returns machine-name => label pairs for all name_list_format entities.

getFormatPatternByMachineName(string $machine_name): ?string

Returns the pattern string for a format entity, or NULL when not found.

FormatOptionInterface::normalizeLegacyFormatMachineName(mixed $raw): ?string

Static helper for legacy callers and theme variables; coerces untyped format ids before loading config entities.

Legacy replacement

Deprecated wrappers in name.module delegate here:

  • name_get_custom_format_options()
  • name_get_custom_list_format_options()
  • name_get_format_by_machine_name()

See API Overview — Legacy procedural helpers.