Problem/Motivation

Currently, the module supports a single "lower environment" value that applies to all non-production environments (dev, stage, test, etc.). However,
different environments may need different values.

For example:

  • Staging might need to point to https://api-staging.example.com
  • Development might need to point to https://api-dev.example.com
  • Local might need to point to http://localhost:8000

Users currently have to maintain separate trackers or manually update values when syncing to different environments, which is error-prone and
time-consuming.

Steps to reproduce

  1. Create a field value tracker with a lower environment value
  2. Sync database to staging environment and run drush fvt:update
  3. Sync database to dev environment and run drush fvt:update
  4. Notice both environments receive the same value, when they may need different values

Proposed resolution

Add support for environment-specific values while maintaining backward compatibility:

  1. Configurable environments - Add simple YAML config (field_value_tracker.environments.yml) listing available environments
    with labels and descriptions
  2. Environment-specific values field - Add environment_values map field to store per-environment values
  3. Enhanced Drush command - Add --env flag to specify which environment to use:
    drush fvt:update --env=stage
      drush fvt:update --env=dev
      drush fvt:update  # Uses default "all" value
  4. Smart fallback logic - If no environment-specific value exists for the specified environment, fall back to the default
    lower_env_value
  5. Backward compatibility - Existing trackers continue to work unchanged; lower_env_value becomes the "all environments"
    default
  6. Update hook - Provide update hook to install new configuration and add new field

Remaining tasks

  • ✅ Create config schema for environments
  • ✅ Create default environments config YAML
  • ✅ Add environment_values field to entity
  • ✅ Update form with environment-specific value fields using proper DI
  • ✅ Add --env flag to Drush command
  • ✅ Update Drush command logic for environment-specific values
  • ✅ Create update hook for migration
  • ✅ Add comprehensive tests
  • ⬜ Code review
  • ⬜ Manual testing on real environments
  • ⬜ Update documentation (README)

User interface changes

The tracker edit form at /admin/config/development/field-value-tracker/{id}/edit will show:

  • Lower Environment Value - Relabeled as "All Environments (Default)" with description explaining it's used as the fallback
  • Environment-specific Values - New collapsible details section containing:
    • Dynamic textarea fields for each configured environment (stage, dev, etc.)
    • Each field labeled with the environment's human-readable label
    • Optional - leave empty to use the default "all" value

Screenshot: (Will be added after manual testing)

API changes

New field on field_value_tracker entity:

  • environment_values - Map field storing environment ID => value pairs

Updated Drush command:

  • field-value-tracker:update (alias: fvt:update)
    • New option: --env=ENVIRONMENT - Specify target environment
    • Backward compatible - running without --env uses default value

New configuration:

  • field_value_tracker.environments - Simple config listing available environments

Data model changes

field_value_tracker entity:

  • New field: environment_values
    • Type: map
    • Required: No
    • Stores: Array of environment_id => value mappings
  • Existing field: lower_env_value
    • Behavior change: Now serves as "all environments" default
    • Still required
    • Backward compatible

New configuration object:

  • field_value_tracker.environments.yml
    • Structure: Keyed array of environment definitions
    • Each environment has: label and description
    • Ships with: all, stage, dev
    • User-customizable via config management

Update hook:

  • field_value_tracker_update_11001() - Installs new config and adds environment_values field to existing entities
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jhedstrom created an issue. See original summary.

jhedstrom’s picture

Status: Active » Needs review