Problem/Motivation

After upgrading to 4.0.11, our site crashes when the current environment has no title set in the config. The Watchdog error reports an issue with line 226 of /var/www/html/web/modules/contrib/environment_indicator/src/ToolbarHandler.php (see attached stack trace).

Proposed resolution

A logic check in the getTitle() function solves the issue:

$environment = $this->activeEnvironment->get('name') ?: "";

Patch attached.

Comments

JI_Gravityworks created an issue. See original summary.

jane_irwin’s picture

ankitjhakal’s picture

Assigned: Unassigned » ankitjhakal
ankitjhakal’s picture

Assigned: ankitjhakal » Unassigned
Status: Active » Needs review
StatusFileSize
new550 bytes

Above patch is not applying so created other one. Kindly review it. Issue is occurring when module is installed. Check any page it will throw error so after applying attached patch it's working fine.

syeda-farheen’s picture

Status: Needs review » Reviewed & tested by the community
aramboyajyan’s picture

Attaching updated patch; #4 didn't work for me, line number was wrong.

aramboyajyan’s picture

Updated patch file (without the .txt extension)

alexgreyhead’s picture

Patch file at #4 is correct - the patches at #6 and #7 have full paths which result in a file not found error when composer tries to apply the patch.

In case it helps, you need the following in your composer.json:

{
    "extra": {
        "patches": {
            "drupal/environment_indicator": {
                "getTitle() in Toolbar Handler returns null value, crashes site - Drupal.org issue #3324429 patch from comment #4": "patches/issue-3324429.patch"
            }
        }
    }    
}

You'll also need to save patch #4 into a patches/ directory located alongside your composer.json.

Run composer install to patch the file:

> Drupal\Core\Composer\Composer::vendorTestCodeCleanup
  - Applying patches for drupal/environment_indicator
    patches/DD-1421-environment_indicator-toolbar_handler_returns_null-3324429-4.patch.txt (getTitle() in Toolbar Handler returns null value, crashes site - Drupal.org issue #3324429 patch from comment #4)

/Alex

jane_irwin’s picture

Oh! Sorry for not truncating those filepaths. Thanks for the reminder!

amjad1233’s picture

Patch #4 worked for me. Latest patch as mentioned had error.

alexgreyhead’s picture

> Oh! Sorry for not truncating those filepaths. Thanks for the reminder!

No woz - apologies if my message sounded grumpy; it wasn't intended to be :-)

/Al

joegl’s picture

Patch in #4 resolved fatal errors/test failures for us. Good mitigation of the issue for now.

dagmar’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new9.36 KB

While #4 fix the fatal error I don't think it is the proper fix. The environment name may not exist so getTitle() does not always return a string. Also it breaks the UI like this:

broken ui

dagmar’s picture

Status: Needs work » Needs review
StatusFileSize
new7.93 KB
new9.11 KB
new877 bytes

Here is a different approach.

When no environment name is set:

When the environment name is set:

dagmar’s picture

StatusFileSize
new959 bytes

Sorry wrong patch.

amjad1233’s picture

+++ b/src/ToolbarHandler.php
@@ -218,9 +219,9 @@ class ToolbarHandler implements ContainerInjectionInterface {
     return ($release) ? '(' . $release . ') ' . $environment : $environment;

Side note but should this use $this->t instead ? I mean should it not return translatable markup ?

jlopes23’s picture

I'd the same issue and the patch on https://www.drupal.org/project/environment_indicator/issues/3324429#comm... works as expected.

I've follow the same approach and to fix the issue before find the patch

thanks

jive01’s picture

I can verify that Patch 4 works.

kurttrowbridge’s picture

I'm in the same boat as #14: I tested on a local environment that doesn't have an environment name set, and patch #4 results in a misalignment in the UI (see first attached screenshot; the red box is just from me redacting the username). I then tested patch #16 and confirmed that that is working (see second screenshot).

I'll wait to mark as RTBC until someone who does have an environment name tests #16, but that one looks good to me.

Thanks!

mayankguptadotcom’s picture

I can confirm that Patch 16 works with Drupal 9.5.0 on DDEV environment.
Here's what my patches object looks like in composer.json

"patches": {
            "drupal/environment_indicator": {
                "getTitle() in Toolbar Handler returns null value, crashes site - Drupal.org issue #3324429 patch from comment #16": "https://www.drupal.org/files/issues/2022-12-08/3324429-16.patch"
            }
        }

And then composer update

  • e0ipso committed 1e3fcfbf on 4.x authored by dagmar
    Issue #3324429 by dagmar, JI_Gravityworks, aramboyajyan, ankitjhakal,...
e0ipso’s picture

Status: Needs review » Fixed

Thanks for the contribution everyone!

e0ipso’s picture

This was released in 4.0.12.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.