### Problem/Motivation
`orejime_page_attachments_alter()` in `orejime.module` accesses `$attachment[0]['#tag']` without first checking whether the key exists. When the `#attached / html_head` array contains attachments that do not define a `#tag` key (which is perfectly valid — `#tag` is optional in many `html_head` structures), PHP 8.x emits a warning on every page load:
```
Warning: Undefined array key "#tag" in orejime_page_attachments_alter() (line 110 of modules/contrib/orejime/orejime.module)
```
On sites with significant anonymous traffic this clogs `admin/reports/dblog` (one row per request) and adds avoidable I/O on every page render.
### Steps to reproduce
1. Drupal 10.6.10, PHP 8.4, Orejime 3.0.0-rc2.
2. Have any module attached that adds an `html_head` element without a `#tag` key — common sources: `simple_sitemap`, several SEO / Open Graph modules, custom hook implementations using only `#attributes` or `#noscript`.
3. Load any anonymous page on the site.
4. Check `admin/reports/dblog` — the warning is logged.
In our environment (four art-collection sites on Drupal 10.6.10) the warning logs roughly every 5 to 10 seconds under normal anonymous traffic.
### Proposed resolution
Guard the `#tag` access with `isset()` before the comparison. This preserves the existing logic (the conditional is only entered when `#tag === 'script'`) while making the iteration safe over `html_head` items that don't define `#tag`.
```diff
--- a/orejime.module
+++ b/orejime.module
@@ -107,7 +107,7 @@ function orejime_page_attachments_alter(array &$attachments) {
// Automatically opt-in for tracking by GTM and GA.
if (isset($attachments['#attached']['html_head'])) {
foreach ($attachments['#attached']['html_head'] as &$attachment) {
- if ($attachment[0]['#tag'] == 'script' &&
+ if (isset($attachment[0]['#tag']) && $attachment[0]['#tag'] == 'script' &&
($attachment[1] == 'google_analytics_tracking_script' || strpos($attachment[1], 'google_tag_script_tag__') === 0)) {
$script = $attachment[0];
$attachment[0] = [
```
A patch file is attached.
### Remaining tasks
- Review.
- Commit to `3.0.x`.
- Backport to `2.x` if the same code path exists there (it does in 2.0.16 at minimum).
### User interface changes
None.
### API changes
None.
### Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| orejime-undefined-tag-isset-3.0.x.patch | 673 bytes | jbfelix |
Issue fork orejime-3592970
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
Comment #4
akashkumar07 commentedAdded an MR for an attached patch for quick merge and commit.
Needs review. Thanks!
Comment #5
fabsgugu commented