Problem/Motivation

There is code that doesn't check for the existence of an array key before using it which causes a PHP warning when the key is missing. The code was added as part of this issue.

Steps to reproduce

Run drupal on a server which doesn't allow $_SERVER['HTTP_REFERER']. Open an entity browser with an iframe display.

You'll get this error message in the modal, but everything will work:
Warning: Undefined array key "HTTP_REFERER" in Drupal\entity_browser\Plugin\EntityBrowser\Display\IFrame->displayEntityBrowser() (line 101 of modules/contrib/entity_browser/src/Plugin/EntityBrowser/Display/IFrame.php).

Proposed resolution

Check for the existence of the array key before using it.

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

very_random_man created an issue. See original summary.

very_random_man’s picture

Status: Active » Needs review
benstallings’s picture

Status: Needs review » Reviewed & tested by the community

Claude Code says:

Assessment — Correct but minimal:

1. Fixes the bug correctly. The old code assigned $_SERVER['HTTP_REFERER'] to $referer unconditionally, triggering the warning. The new code gates access behind !empty(). Simple and right.
2. Pre-existing concern (not this patch's fault): Direct access to $_SERVER['HTTP_REFERER'] is a Drupal anti-pattern. The request object is already available via the $this->request property (or could be injected). The idiomatic approach would be $this->request->server->get('HTTP_REFERER') or $this->request->headers->get('referer'), which return NULL gracefully without needing the !empty() check at all. But that's a separate cleanup, not a reason to block this fix.
3. Net reduction of one line — cleaner than the original.

This is a straightforward, safe fix. Good to merge.

anybody’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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