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
namevalues 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\NameFormatterInterfaceDrupal\name\Service\NameFormatParserInterfaceDrupal\name\Service\GeneratorInterfaceDrupal\name\Service\AutocompleteInterfaceDrupal\name\Service\NameOptionInterfaceDrupal\name\Service\WidgetLayoutInterfaceDrupal\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\NameFormatDrupal\name\Entity\NameListFormatDrupal\name\Entity\NameFormatInterfaceDrupal\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 thename.formatshelp 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\HelpHooks—hook_help()Drupal\name\Hook\TokenHooks— formatted name token metadata and replacementsDrupal\name\Hook\UserHooks— user display name (realname) preload andhook_user_format_name_alter()Drupal\name\Hook\FieldConfigHooks— syncsname.settings:user_preferredwhen user Name fields are created or deletedDrupal\name\Hook\FieldHooks— Views data and field type category infoDrupal\name\Hook\WidgetLayoutHooks— discovershook_name_widget_layouts()implementationsDrupal\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 entriesDrupal\name\Utility\FormattedNameTokenParser— parses formatted token chainsDrupal\name\Utility\FormattedNameTokenReplacement— replaces formatted tokens via the formatter serviceDrupal\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 inputDrupal\name\Utility\AutocompleteMatcher— matches static option sourcesDrupal\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.
Drupal\name\Service\LinkTargetService— Link Target service (name.link_target)Drupal\name\Service\NameFormatterSummaryService— Formatter Summary service (name.formatter_summary)
Render classes¶
Drupal\name\Render\NameListFormattableMarkup— joins multiple formatted names with a list delimiter forformatList()output (@internal).
Form utilities¶
These classes are marked @internal.
Drupal\name\Utility\ComponentBuilder— builds per-component form elements for theNameelement and widgetDrupal\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— registersname_format_token_help()for use in help topic templates viarender_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,
) {}
}