Entity Prepopulate epp

Prepopulates entity field values with tokens and YAML-formatted data, working at the entity level for robust field prepopulation on entity forms.

1,403
sites
43
Stars
Drupal 8 · Drupal 9 · Drupal 10 · Drupal 11
Compatible
GNU General Public License, version 2 or later
License

Overview

Entity Prepopulate allows you to automatically fill entity fields with predefined values containing tokens. Unlike the original Prepopulate module that works at the form level, this module operates at the entity level, providing a more robust and secure approach to field prepopulation.

The module supports YAML syntax, enabling complex configurations including multi-value fields and multi-property fields (like geofields). All prepopulation is explicit through field configuration, which improves security. Values are only applied when all tokens are successfully replaced, and field validation ensures that invalid values are never set.

Configuration is done per-field through the standard Drupal Field UI, where an "Entity Prepopulate" fieldset is added to field settings forms. You can specify the prepopulation value (with token support) and choose whether to apply values only on new entities or also when updating existing ones.

Install

Drupal 11, 10, 9, 8 v8.x-1.7
composer require 'drupal/epp:8.x-1.7'

Features

  • Prepopulates any entity field with configurable values containing tokens
  • Works at the entity level rather than form level for more robust behavior
  • Supports YAML syntax for multi-value fields and multi-property fields (e.g., geofield with lat/lng)
  • Values are only applied when all tokens are successfully replaced, preventing partial data
  • Field validation prevents invalid values from being set
  • Optional 'on update' setting to apply prepopulation when editing existing entities
  • Integrates with Token module for expanded token support and token browser
  • Displays available field properties as a help reference in the configuration form
  • Explicit configuration per field ensures secure prepopulation
  • Works with any fieldable entity type (nodes, users, taxonomy terms, etc.)

Use Cases

Prepopulate a text field with the site name

Configure a text field to automatically display the site name when creating new content. Set the Value field to '[site:name]' in the field's EPP settings. When users create new content, the field will be pre-filled with the actual site name.

Set default author reference to current user

Configure an entity reference field (e.g., 'Author') to prepopulate with the currently logged-in user. Use the token '[current-user:uid]' as the value to automatically set the current user as the default selection.

Prepopulate multiple values in a multi-value field

For fields with cardinality greater than 1, use YAML list syntax to prepopulate multiple values. For example: - first [site:name] - second value - third value This will fill the first three field items with the respective values.

Prepopulate a geofield with specific coordinates

For multi-property fields like geofield, use YAML mapping syntax to target specific properties: lat: 51.5074 lng: -0.1278 This sets the latitude and longitude properties separately.

Auto-fill status field on update

Configure a status field with 'Also on update' enabled to ensure a specific value is always applied when editing entities. This is useful for workflow states or tracking fields that should be reset on each edit.

Dynamic date prepopulation

Use date tokens like '[current-date:custom:Y-m-d]' to prepopulate date fields with the current date when creating new content. Useful for tracking creation dates or setting default deadlines.

Conditional prepopulation with token safety

Since values are only applied when ALL tokens are replaced successfully, you can safely use tokens that may not always be available. If a token cannot be replaced (e.g., context-dependent tokens), the field simply won't be prepopulated, preventing partial or broken data.

Tips

  • Use the 'Available field properties' expandable section to see which properties you can target with YAML syntax for complex field types
  • Install the Token module to get a token browser and access to many additional tokens beyond core
  • Values are only applied if ALL tokens are replaced - this is a feature, not a bug, preventing partial data
  • The 'Also on update' option is useful for fields that should be reset or recalculated on every edit
  • For multi-value fields, use YAML list syntax with dash markers (- item1)
  • For multi-property fields (like address or geofield), use YAML mapping syntax (property: value)
  • Check Drupal logs (admin/reports/dblog) for EPP-related messages when debugging prepopulation issues
  • This module works at the entity level, so prepopulated values will be visible in any form display for the entity

Related Projects

Token

When the Token module is installed, Entity Prepopulate displays a token browser link in the configuration form and gains access to additional tokens beyond Drupal core tokens. The module description recommends installing Token for enhanced functionality.

Field UI

Entity Prepopulate integrates with Field UI by adding configuration fields to the field_config_edit_form and base_field_override_edit_form forms, allowing administrators to configure prepopulation through the standard Drupal field management interface.

Admin Pages

Title Path Description
Field Settings (Entity Prepopulate section) /admin/structure/types/manage/[content-type]/fields/[entity_type].[bundle].[field_name] Entity Prepopulate adds a fieldset to existing field configuration forms (both regular field config and base field overrides) where you can configure prepopulation values. This appears on any field configuration page in Drupal.

Hooks

Hook Description
hook_entity_prepare_form Implements the core prepopulation logic. When an entity form is being prepared, this hook iterates through all fields, checks for EPP third-party settings, replaces tokens, parses YAML, validates values, and sets the field values on the entity.
hook_form_alter Alters field_config_edit_form and base_field_override_edit_form to add the EPP configuration fieldset with Value textarea, token browser, field properties help, and Also on update checkbox.

Troubleshooting

Field is not being prepopulated even though a value is configured

Check the Drupal logs for EPP-related messages. Common causes include: 1) Not all tokens were replaced (if using tokens that require specific context), 2) The value failed field validation (e.g., setting text in a number field), 3) The user doesn't have edit access to the field, or 4) 'Also on update' is not checked when editing existing entities.

YAML syntax errors

YAML parse errors are logged. Ensure proper YAML formatting: use consistent indentation (spaces, not tabs), proper list markers (- item), and valid mapping syntax (key: value). Test your YAML in a validator before using it.

Tokens are not being replaced

Install the Token module for more tokens and the token browser. Verify token syntax is correct with the browser. Remember that some tokens require specific context (e.g., [node:title] requires an existing node) which may not be available on entity create forms.

Value is invalid for the field type

The module validates prepopulated values against field constraints. If validation fails, the previous value is restored and a notice is logged. Ensure your prepopulation value matches the expected field format (numbers for integer fields, valid entity IDs for references, etc.).

Module dependency shows up when EPP is not actually used

If both the Value and 'Also on update' settings are empty/unchecked and you save the field configuration, EPP third-party settings are automatically removed to prevent unnecessary module dependencies.

Security Notes

  • All prepopulation is explicit through configuration - no URL parameter injection like the original Prepopulate module
  • Field edit access is checked before applying prepopulation values
  • Values are validated against field constraints before being set
  • Invalid values are logged but not applied, preventing data integrity issues
  • This module has security coverage from the Drupal Security Team

Meta

Author
geek-merlin
License
GNU General Public License, version 2 or later
Security
Covered
Created
2019/11/04
Updated
2025/10/15