EnvironmentIndicator::getVersionIdentifier() causes fatal error if value happens to be a number

Created on 16 June 2025, 18 days ago

Problem/Motivation

The getVersionIdentifier() function of the new EnvironmentIndicator service specifies a return type of "string". This value can come from something like a Git commit hash that could possibly be a number. If that happens, this causes a fatal error:

TypeError: Drupal\environment_indicator\Service\EnvironmentIndicator::getVersionIdentifier(): Return value must be of type ?string, int returned in Drupal\environment_indicator\Service\EnvironmentIndicator->getVersionIdentifier() (line 100 of modules/contrib/environment_indicator/src/Service/EnvironmentIndicator.php).

Steps to reproduce

  1. Set the "Source of version identifier to display" to "Environment Indicator Current Release".
  2. Set the environment_indicator.current_release State value to a number using the Drush command drush state:set environment_indicator.current_release '12345678'
  3. Flush the cache and load a page for a user that sees the admin toolbar with the version identifier.
  4. See the error.

Proposed resolution

EnvironmentIndicator::getVersionIdentifier() should handle values that happen to be numbers. We can do this by casting what it's returning as a string.

Remaining tasks

  1. Patch code.
  2. Write tests.
  3. Merge fix.

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

4.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jrb Raleigh-Durham Area, NC, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024