Problem/Motivation

Since version 4.0.11, the toolbar item includes a random string of characters in parentheses to the left of the environment name. This appears to be where the release state information would appear. We don't set this state in our site and the random string of characters never appeared before version 4.0.11.

environment name with random characters

Steps to reproduce

1. Update to 4.0.11.
2. Do not set or unset a environment_indicator.current_release version state.

Proposed resolution

A merge request has been submitted to address this issue: MR #44.

The proposed solution in the merge request makes several changes:
1. Introduces new configuration settings for `version_identifier` and `version_identifier_fallback` in `environment_indicator.settings.yml`.
2. Adds these settings to the schema and a new update hook to initialize them.
3. Updates the `ToolbarHandler` class to use these new settings and display the appropriate version identifier.
4. Updates the settings form to allow selecting the source of the version identifier and a fallback option.

For existing sites, the update hook `environment_indicator_update_8101` ensures backward compatibility by initializing the new settings with default values if they are not already set:

  function environment_indicator_update_8101() {
    $config_factory = \Drupal::configFactory();
    $settings = $config_factory->getEditable('environment_indicator.settings');
    if ($settings->get('version_identifier') === NULL) {
      $settings->set('version_identifier', 'environment_indicator_current_release');
    }
    if ($settings->get('version_identifier_fallback') === NULL) {
      $settings->set('version_identifier_fallback', 'deployment_identifier');
    }
    $settings->save();
  }

When I set a release state with the recommended Drush command on the environment indicator settings screen, the random characters go away and the release version I set appears. (drush sset environment_indicator.current_release v1.2.44)

This confirms that the random string issue is due to the missing release state. The merge request will resolve this by ensuring the release state is only displayed when it is explicitly set.

How to test

1. Ensure the Environment Indicator UI module is enabled.
2. Update your site to the latest version including the merge request changes.
3. Navigate to the environment indicator settings page at `/admin/config/development/environment-indicator`.
4. Verify that the new settings for `version_identifier` and `version_identifier_fallback` are present.
5. Ensure the default values are set correctly for both settings.
6. Test by not setting the `environment_indicator.current_release` state and observe that no random string appears.
7. Set a release state using the command: drush sset environment_indicator.current_release v1.2.44 and verify that the release version appears correctly.
8. Change the `version_identifier` setting to different options (e.g., `deployment_identifier`, `drupal_version`, `none`) and verify the output in the toolbar.
9. Ensure the fallback option works by setting `version_identifier` to a non-existing source and checking if the fallback value is used.

For convenience, a Landofile is provided in the merge request body for those who want to use it.

Screenshots of the New UI

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

timwood created an issue. See original summary.

ankitjhakal’s picture

Assigned: Unassigned » ankitjhakal
utcwebdev’s picture

I see this issue as well. Thanks for reporting, I was just about to report it myself.

ankitjhakal’s picture

Hi All, I followed the steps. Required and installed the module. Cleared all cache, ran drush sdel environment_indicator.current_release command and testing after saving the setting form with toolbar and show favicon checkbox. Still i am not seeing any random string here. Can you elaborate little bit more when this one occurring or i have done something wrong with debugging.
I am using D9.4.8 and php 8.1.
Module V4.0.11.

ankitjhakal’s picture

public function getCurrentRelease() {
    $current_release = $this->state->get('environment_indicator.current_release');
    if ($current_release !== NULL) {
      return (string) $current_release;
    }

    $deployment_identifier = $this->settings->get('deployment_identifier');
    if ($deployment_identifier !== NULL) {
      return (string) $deployment_identifier;
    }

    return NULL;
  }

This code is returning NULL in starting as there is no state var set for current_release and uncommented deployment_identifier line in settings.php file.

utcwebdev’s picture

@ankitjhakal

What was apparently a random string is actually the text content of my project's deployment_identifier file (in my current docker container Lando appserver environment this is "G %9[+R=").

I'll do more research on this and how the file gets created in my local development environment.

It looks like a build artifact from Acquia BLT setup script commands.

utcwebdev’s picture

Confirmed: the deployment_identifier file is created as a random string during Acquia BLT setup during drupal:install, and during artifact generation during blt deploy, where it can be specified as a tag for the deploy release.

Looks like this is not a bug.

ankitjhakal’s picture

Assigned: ankitjhakal » Unassigned

Hi utcwebdev, so can you please move this issue in closed status.

darktek’s picture

StatusFileSize
new1.18 KB

@utcwebdev It is in fact a bug, because the module should be taking the BLT commands in consideration, I'm having the same issue.

I created a patch to get rid of the identifier version in the title. Maybe we could have some kind of settings asking us if we want to have the version indentifier before the title, that could fix the issue in these cases

utcwebdev’s picture

StatusFileSize
new41.27 KB

@DarkteK Thank you for the patch. I agree, an option to disable/enable the identifier would be helpful.

I think the module is behaving as designed, but not as expected, when used with the BLT workflow. Unless there is a tag specified during a deployment, BLT generates the random string as deployment_identifier. I still see a seemingly random string after CI/CD develop-build branch deployment to our hosted Acquia dev environment, though it looks suspiciously like a failed timestamp. Also, the favicon icon overlay text is borked.

~Yd/D ) Cloud Dev" as text in the indicator

Perhaps this is more of a BLT issue where the deployment identifier could be improved. The BLT developer justification for it to be a random string is because "Drupal uses the deployment identifier to seed the APCu cache", and generating a random string is the most efficient/fast method. The identifier helps to clear the Twig cache when theme updates are deployed, and class autoloader cache when a module is updated.

devkinetic’s picture

+1 to making it optional, I guess that was an oversight when I initially added it.

Having the option is really nice when using, for example, tag based deployments where you use ENV to set the deployment_identifier like so in settings:

if (getenv('GIT_BRANCH')) {
  $settings['deployment_identifier'] = getenv('GIT_BRANCH');
}

It's useful when you are already using deployment identifier in a unique way, so you don't have to set the state as well on top of it. Not everyone is using deployment identifier (you should), or does but it doesn't provide anything meaningful in the case of BLT, so making it optional is nice.

While on the topic of deployment identifier, but somewhat off-topic, I am using the following in my settings.local.php to set it to the current branch, this works out really well!

// Set deployment_identifier to current branch
$git_path = __DIR__ . '/'.'../../../.git/'; //adjust path based on your project structure
if (file_exists($git_path)) {
  $settings['deployment_identifier'] = str_replace('refs/heads/', '', trim(substr(file_get_contents($git_path . 'HEAD'), 4)));
}
kurttrowbridge’s picture

Thanks for reporting this! Just chiming in to add that this also shows up on Pantheon, where the latest commit hash appears before the environment name when on the development environment, and the Pantheon deployment ID (e.g. "test_35") appears in test and live.

I personally agree with the suggestion of this being a configurable option that could be enabled or disabled. Even if not, I wonder about the possibility of moving it to display after the environment name, rather than before [e.g. Local (rbVZt`Z= )], which would prevent the favicon overlay from being affected.

Thanks!

dabblela’s picture

Configurable would be nice but thankfully there is a straightforward code path to changing this behavior if you need to:

/**
 * Implements hook_toolbar_alter().
 */
function hook_toolbar_alter(&$items) {
  if (!empty($items['environment_indicator'])) {
    $env_name = \Drupal::service('config.factory')
      ->get('environment_indicator.indicator')
      ->get('name');
    $items['environment_indicator']['tab']['#title'] = $env_name;
    $items['environment_indicator']['tab']['#attached']['drupalSettings']['environmentIndicator']['name'] = $env_name;
  }
}

lisastreeter’s picture

Also seeing the "random" string on a platform.sh site. Wasn't displayed on local environment but appeared once I deployed code to a platform.sh environment.

pcate’s picture

+1 for this being configurable. It can be confusing to editors who don't know what the (seemingly) random string is.

devkinetic’s picture

Until there is a patch, literally the easiest thing to do is set the state for the current release per the README. You can see in the code https://git.drupalcode.org/project/environment_indicator/-/blob/4.x/src/... that the deployment identifier is only used as a fallback.

joegraduate’s picture

Title: New toolbar handler prints random string for release when there is none » Whether deployment identifier is used as current_release value should be configurable
Version: 4.0.11 » 4.x-dev
Status: Active » Needs work
Issue tags: +Needs issue summary update
Related issues: +#2610208: Move procedural functions to a manager

Needs IS summary update for suggested new configuration setting. Affects all 4.x-dev (and all 4.x releases since 4.0.11).

Issue was introduced with the changes committed for #2610208: Move procedural functions to a manager due to the deployment identifier now being used (if available) as a fallback for current_release value that is prepended to the environment title when the current_release value is not set in the state.

joegraduate’s picture

Closed #3325538: Remove extra strings added to the environment title after upgraded to 4.0.11 as duplicate of this issue. Credit should be included for the contributors to that issue when this fixed.

joegraduate’s picture

Title: Whether deployment identifier is used as current_release value should be configurable » Whether deployment identifier is used as fallback for current_release should be configurable
ericjenkins’s picture

We have also been experiencing the random characters in parentheses prepended to the environment label. We also observed that the characters come from a deployment_identifier file located in our project's root directory.

I'm submitting patch #20 which is similar to #9, but it keeps the environment_indicator.current_release state variable check. It only replaces the deployment_identifier fallback with a \Drupal::VERSION fallback.

pameeela’s picture

I was for disabling the fallback but I really like @ericjenkins' idea of showing the Drupal version. I think that would be useful info to highlight, whereas the deploy ID is really really not.

trackleft2 made their first commit to this issue’s fork.

trackleft2’s picture

Adding static patch for CI tools with all the changes in the merge request as of 17c96bd7b7b4d916f43bd30dd58806e21fc956bf against the 4.x branch.

trackleft2’s picture

Status: Needs work » Needs review

trackleft2’s picture

trackleft2’s picture

trackleft2’s picture

Suggestion: when the none option is selected for the Source of version identifier to display field, a fall back option should not be allowed.

trackleft2’s picture

I've updated the merge request to disallow setting a fallback if a primary version indicator source is set to none.

trackleft2’s picture

Title: Whether deployment identifier is used as fallback for current_release should be configurable » Make version indicator source and version indicator source fallback configurable.
trackleft2’s picture

Category: Bug report » Feature request
trackleft2’s picture

trackleft2’s picture

Issue summary: View changes
trackleft2’s picture

trackleft2 changed the visibility of the branch environment_indicator-3324621-3324621-with-fallback to hidden.

joegraduate’s picture

Status: Needs review » Reviewed & tested by the community

The changes in @trackleft2's MR work great for me in my testing. I really like that it adds additional configuration options for what is used as the version indicator and the fallback.

joegraduate’s picture

StatusFileSize
new17.29 KB

Uploading static patch with latest changes from MR (usable with 4.0.19).

isholgueras made their first commit to this issue’s fork.

isholgueras’s picture

Status: Reviewed & tested by the community » Fixed

Excelent work. I'll release it in the 4.0.20 version.

isholgueras’s picture

Status: Fixed » Closed (fixed)