Empty Fields
Provides options for displaying empty fields that would otherwise be hidden, using configurable display formatter settings.
empty_fields
Install
composer require 'drupal/empty_fields:8.x-1.0'
Overview
The Empty Fields module provides a way to show fields that are empty by adding new display formatter settings. By default, Drupal hides fields that have no value. This module allows site administrators to configure what should be displayed when a field is empty, rather than hiding the field entirely.
The module works by adding a third-party setting to all field formatters, allowing you to select an "Empty value behavior" for each field on each view mode. When a field is empty and has a configured handler, the module renders the field with the specified replacement content instead of hiding it.
The module provides a plugin system that allows developers to create custom empty field handlers. Out of the box, it includes handlers for displaying custom text (with token support) and non-breaking spaces. Additional handlers can be added by other modules using the plugin API.
Features
- Displays empty fields that would normally be hidden by Drupal
- Configurable per-field and per-view-mode settings through the Manage Display interface
- Display custom text when a field is empty with full token replacement support
- Display non-breaking space ( ) to maintain field layout structure
- Plugin-based architecture allowing developers to create custom empty field handlers
- Automatic fallback handling for missing or broken plugins
- Adds CSS classes to empty field output for theming (empty-fields, empty-fields__[handler])
- Respects field access permissions - only displays empty content if user has view access
Use Cases
Display placeholder text for missing profile fields
On user profile pages, display 'Not specified' or 'No information provided' for empty biographical fields instead of hiding them. This maintains consistent layout and informs visitors that the information was intentionally left blank rather than being a display error.
Maintain table-like layouts with non-breaking spaces
When displaying content in a grid or table-like layout where CSS depends on content being present, use the non-breaking space handler to ensure empty fields still render their container, preventing layout collapse.
Show dynamic placeholder content based on context
Use the custom text handler with token replacement to display context-aware placeholder content. For example, display 'Edit your [current-user:name] profile to add this information' when a field is empty.
Consistent field display across view modes
Ensure all fields are visible on full content view mode for editorial review, while hiding empty fields on teaser displays. Configure different empty field behaviors per view mode.
Debug content completeness
During content migration or entry, display 'EMPTY - Needs Review' for empty required fields to help editors identify content that needs attention.
Tips
- Use token replacement in custom text to create dynamic, context-aware empty field messages
- Add custom CSS targeting the .empty-fields class to style empty field displays differently from fields with values
- Create custom EmptyField plugins for complex use cases like displaying related content or calling external services
- Remember that empty field settings are per-view-mode, so you can have different behaviors for full, teaser, and other display modes
- The module respects field access permissions, so empty content will only display if the user has permission to view the field
Technical Details
Hooks 3
hook_field_formatter_third_party_settings_form
Adds the Empty value behavior select field to all field formatter settings forms, allowing configuration of what to display when a field is empty.
hook_field_formatter_settings_summary_alter
Alters the formatter settings summary to include the configured empty field behavior.
hook_entity_display_build_alter
Alters the entity display build to inject empty field content when a field is empty but has an empty field handler configured.
Troubleshooting 4
Verify that the field's formatter settings have 'Empty value behavior' configured to something other than '- Default -'. Also check that the user has permission to view the field.
The configured empty field handler plugin no longer exists. This can happen if a module providing a custom handler was uninstalled. Reconfigure the field's empty value behavior in Manage Display.
Ensure the Token module is installed and enabled. Also verify you're using the correct token syntax for the entity type being displayed.
Check that your theme's CSS is targeting the correct classes. Empty fields have both 'empty-fields' and 'empty-fields__[handler]' classes on the field wrapper.