Skip to content

Classes and Interfaces

This page highlights the classes most developers interact with.

Field API plugins

  • Drupal\name\Plugin\Field\FieldType\NameItem
  • field schema and settings for name values
  • Drupal\name\Plugin\Field\FieldWidget\NameWidget
  • form input for each component
  • Drupal\name\Plugin\Field\FieldFormatter\NameFormatter
  • render-time formatter plugin that delegates to name.formatter

Form and render classes

  • Drupal\name\Element\Name
  • composite form element (#type => 'name')
  • Drupal\name\Controller\AutocompleteController
  • endpoint that delegates matching to name.autocomplete

Service interfaces (preferred type hints)

  • Drupal\name\Service\NameFormatterInterface
  • Drupal\name\Service\NameFormatParserInterface
  • Drupal\name\Service\GeneratorInterface
  • Drupal\name\Service\AutocompleteInterface
  • Drupal\name\Service\NameOptionInterface
  • Drupal\name\Service\WidgetLayoutInterface
  • Drupal\name\Service\FormatOptionInterface (@internal)
  • Drupal\name\Service\AdditionalComponentInterface (@internal)
  • Drupal\name\Service\NameComponentMetadataInterface (@internal)
  • Drupal\name\Service\ElementValidatorInterface (@internal)
  • Drupal\name\Service\LinkTargetInterface (@internal)
  • Drupal\name\Service\NameFormatterSummaryInterface (@internal)

Traits

Shared behavior for field type, widget, formatter, and element code:

  • Drupal\name\Traits\NameFieldSettingsTrait — field storage settings form and defaults (components, autocomplete, options); see Field storage settings.
  • Drupal\name\Traits\NameFormDisplaySettingsTrait — widget display defaults (labels, size, title_display, layout flags).
  • Drupal\name\Traits\NameFormSettingsHelperTrait — field and widget settings table UI (#states, component visibility).
  • Drupal\name\Traits\NameAdditionalPreferredTrait — preferred/alternative field reference settings on field type and formatter.

Config entity classes

  • Drupal\name\Entity\NameFormat
  • Drupal\name\Entity\NameListFormat
  • Drupal\name\Entity\NameFormatInterface
  • Drupal\name\Entity\NameListFormatInterface

Format parsing utilities

These classes are marked @internal and implement the format-string pipeline behind name.format_parser. They are documented here for contributors and developers extending the service.

  • Drupal\name\Utility\NameFormatParser — static facade over the pipeline.
  • Drupal\name\Utility\NameFormatTokens — builds the token map from name components.
  • Drupal\name\Utility\NameFormatLexer — walks the format string and resolves tokens.
  • Drupal\name\Utility\NameFormatModifiers — applies casing, initials, and word-boundary modifiers.
  • Drupal\name\Utility\NameFormatAssembler — joins resolved pieces into a plain string.
  • Drupal\name\Utility\NameFormatOutput — wraps the assembled string in the appropriate Drupal renderable type.
  • Drupal\name\Utility\NameFormatHelp — provides translated token labels shared by the format edit form and the name.formats help topic.
  • Drupal\name\Utility\UnicodeExtras — multibyte explode/initials helpers used when building format tokens.

See Parser Service for the public API over this pipeline.

Hook API classes

Object-oriented hook implementations under Drupal\name\Hook\ (Drupal 11.1+). Procedural shims in name.module delegate here on older supported cores.

  • Drupal\name\Hook\HelpHookshook_help()
  • Drupal\name\Hook\TokenHooks — formatted name token metadata and replacements
  • Drupal\name\Hook\UserHooks — user display name (realname) preload and hook_user_format_name_alter()
  • Drupal\name\Hook\FieldConfigHooks — syncs name.settings:user_preferred when user Name fields are created or deleted
  • Drupal\name\Hook\FieldHooks — Views data and field type category info
  • Drupal\name\Hook\WidgetLayoutHooks — discovers hook_name_widget_layouts() implementations
  • Drupal\name\Hook\ThemeHooks — theme hook definitions

Token utilities

These classes are marked @internal. TokenHooks is the entry point; custom code should use token APIs and name.formatter, not these classes directly.

  • Drupal\name\Utility\FormattedNameTokenInfoRegistrar — registers formatted name token browser entries
  • Drupal\name\Utility\FormattedNameTokenParser — parses formatted token chains
  • Drupal\name\Utility\FormattedNameTokenReplacement — replaces formatted tokens via the formatter service
  • Drupal\name\Utility\TokenFieldSubTypeResolver — resolves field sub-type token paths

Autocomplete utilities

These classes are marked @internal. AutocompleteService orchestrates them.

  • Drupal\name\Utility\AutocompletePlanBuilder — builds match plans from field settings and user input
  • Drupal\name\Utility\AutocompleteMatcher — matches static option sources
  • Drupal\name\Utility\AutocompleteFieldValueLookup — queries stored field values for suggestions

Formatter services

These classes are marked @internal and are injected into the name field formatter plugin.

Render classes

  • Drupal\name\Render\NameListFormattableMarkup — joins multiple formatted names with a list delimiter for formatList() output (@internal).

Form utilities

These classes are marked @internal.

  • Drupal\name\Utility\ComponentBuilder — builds per-component form elements for the Name element and widget
  • Drupal\name\Utility\NameComponents — component keys, layout order, and validation helpers (coreKeys() is used by Feeds integration)
  • Drupal\name\Utility\NameOptionValidator — validates title and generational option lines

Twig extensions

  • Drupal\name\Twig\NameFormatHelpTwigExtension — registers name_format_token_help() for use in help topic templates via render_var(). Not intended for general theme use.

Integration classes

  • Feeds: Drupal\name\Feeds\Target\NameTarget
  • Diff: Drupal\name\Plugin\diff\Field\NameFieldBuilder
  • Views filter: Drupal\name\Plugin\views\filter\Fulltext
  • Migrate plugin: Drupal\name\Plugin\migrate\field\NameField
  • Migrate process plugin: Drupal\name\Plugin\migrate\process\NameField

Example: class-based DI

use Drupal\name\Service\NameFormatterInterface;

final class NamePresenter {

  public function __construct(
    private readonly NameFormatterInterface $formatter,
  ) {}
}