Name Field Developer Docs¶
This documentation is for developers integrating or extending the Drupal Name module in custom code.
What the module provides¶
The field stores structured name components:
titlegivenmiddlefamilygenerationalcredentials
It also provides:
- field type, widget, and formatter plugins
- a
#type => 'name'form element - service APIs for formatting, parsing, generation, and autocomplete
- integration plugins for modules like Token, Feeds, and Diff
- integration with Drupal core
inline_form_errors
Service-first quick start¶
For class-based code (controllers, plugins, services), use constructor injection:
use Drupal\name\Service\NameFormatterInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
final class ExampleController {
public function __construct(
private readonly NameFormatterInterface $nameFormatter,
) {}
public static function create(ContainerInterface $container): static {
return new static(
$container->get('name.formatter'),
);
}
}
For one-off scripts, you can still fetch services directly:
$formatter = \Drupal::service('name.formatter');
$label = $formatter->format([
'given' => 'Jane',
'family' => 'Smith',
], 'full');
Documentation map¶
- API Overview
- Services
- Formatter
- Parser
- Generator
- Autocomplete
- Options Provider
- Hooks
- Classes and Interfaces
- Code Examples
- Extending
- Integrations:
- Devel
- User
- Taxonomy
- Views
- Help
- Token
- Feeds
- Diff
- Migrate
- Inline Form Errors
Version requirements¶
- Drupal 10.3+ or Drupal 11+
- PHP 8.3+