Resolve #3421335 "Only require gtag.ajax if other ajax libs are added."
Closes #3421335
Here is my .lando.yml
file for easy review and development.
name: google_tag
recipe: drupal10
config:
php: '8.2'
via: apache:2.4
webroot: web
database: mariadb:10.4
xdebug: false
services:
database:
type: compose
services:
image: mariadb:10.4
command: docker-entrypoint.sh mariadbd
restart: always
ports:
- '3306'
environment:
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: 'true'
MARIADB_DATABASE: drupal10
MYSQL_DATABASE: drupal10
MARIADB_USER: drupal10
MARIADB_PASSWORD: drupal10
appserver:
overrides:
environment:
SIMPLETEST_DB: 'mysql://drupal10:drupal10@database/drupal10'
SIMPLETEST_BASE_URL: 'http://appserver'
volumes:
# Don't share our host working directory as /app. We want /app empty for composer.
- /app
# Instead share our host working directory as a standalone package.
- .:/usr/local/google_tag
build:
# Create a new Drupal project and use the module as a non-packagist repository.
- composer create-project --dev drupal/recommended-project:10.2.x /app
- composer config extra.enable-patching true
- composer config extra.composer-exit-on-patch-failure true
- composer config allow-plugins.cweagans/composer-patches true
- composer require cweagans/composer-patches
- composer config minimum-stability dev
- composer config allow-plugins.phpstan/extension-installer true
- composer require --dev drupal/core-dev:^10.2 drush/drush phpspec/prophecy-phpunit:* phpstan/extension-installer mglaman/phpstan-drupal phpstan/phpstan-deprecation-rules drupal/config_inspector
- composer config repositories.localdev path /usr/local/google_tag && composer require drupal/google_tag:\*@dev
tooling:
# Provide a command to install Drupal.
install:
service: appserver
cmd:
- /app/vendor/bin/drush --root=/app/web site:install --account-mail=noreply@example.com --account-name=admin --account-pass=admin --db-url=mysql://drupal10:drupal10@database:3306/drupal10 -y --verbose
- /app/vendor/bin/drush en -y google_tag
# Provide Drush tooling to automatically know the Drupal root.
drush:
service: appserver
cmd: /app/vendor/bin/drush --root=/app/web
phpcs:
service: appserver
cmd: /app/vendor/bin/phpcs -s --colors --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml web/modules/contrib/google_tag
# Provide PHPCBF tooling to fix coding standards.
phpcbf:
service: appserver
cmd: /app/vendor/bin/phpcbf -s --colors --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml web/modules/contrib/google_tag
# Provide phpstan tooling to check for code quality and deprecated code.
phpstan:
service: appserver
cmd: /app/vendor/bin/phpstan analyse --configuration web/modules/contrib/google_tag/phpstan.neon web/modules/contrib/google_tag
# Provide phpunit tooling to run unit tests.
phpunit:
service: appserver
cmd: /app/vendor/bin/phpunit --configuration /app/web/core/phpunit.xml.dist --bootstrap /app/web/core/tests/bootstrap.php /app/web/modules/contrib/google_tag
If I print the $attachments var in the event subscriber on a views page with ajax enabled, here is what I see.
array:6 [▼
"html_head" => array:6 [▼
0 => array:2 [▼
0 => array:3 [▼
"#tag" => "meta"
"#noscript" => true
"#attributes" => array:2 [▶]
]
1 => "big_pipe_detect_nojs"
]
1 => array:2 [▼
0 => array:3 [▼
"#tag" => "meta"
"#attributes" => array:1 [▶]
"#weight" => -1000
]
1 => "system_meta_content_type"
]
2 => array:2 [▼
0 => array:3 [▼
"#type" => "html_tag"
"#tag" => "meta"
"#attributes" => array:2 [▶]
]
1 => "system_meta_generator"
]
3 => array:2 [▼
0 => array:2 [▼
"#tag" => "meta"
"#attributes" => array:2 [▶]
]
1 => "MobileOptimized"
]
4 => array:2 [▼
0 => array:2 [▼
"#tag" => "meta"
"#attributes" => array:2 [▶]
]
1 => "HandheldFriendly"
]
5 => array:2 [▼
0 => array:2 [▼
"#tag" => "meta"
"#attributes" => array:2 [▼
"name" => "viewport"
"content" => "width=device-width, initial-scale=1.0"
]
]
1 => "viewport"
]
]
"library" => array:22 [▼
0 => "contextual/drupal.contextual-links"
1 => "system/base"
2 => "olivero/global-styling"
3 => "core/drupal.active-link"
4 => "google_tag/gtm"
5 => "google_tag/gtag"
6 => "olivero/powered-by-block"
7 => "olivero/feed"
8 => "views/views.module"
9 => "views/views.ajax"
10 => "views/views.module"
11 => "views/views.ajax"
12 => "olivero/navigation-secondary"
13 => "olivero/search-wide"
14 => "olivero/navigation-primary"
15 => "olivero/search-narrow"
16 => "toolbar/toolbar"
17 => "devel/devel-toolbar"
18 => "user/drupal.user.icons"
19 => "contextual/drupal.contextual-toolbar"
20 => "shortcut/drupal.shortcut"
21 => "toolbar/toolbar.escapeAdmin"
]
"html_head_link" => array:3 [▼
0 => array:1 [▼
0 => array:3 [▼
"rel" => "icon"
"href" => "/core/themes/olivero/favicon.ico"
"type" => "image/vnd.microsoft.icon"
]
]
1 => array:1 [▼
0 => array:4 [▼
"rel" => "alternate"
"type" => "application/rss+xml"
"title" => ""
"href" => "https://googletag.lndo.site/rss.xml"
]
]
2 => array:1 [▼
0 => array:4 [▼
"rel" => "alternate"
"type" => "application/rss+xml"
"title" => ""
"href" => "https://googletag.lndo.site/rss.xml"
]
]
]
"html_response_attachment_placeholders" => array:4 [▼
"styles" => "<css-placeholder token="KTHomi4oxQStb6_W1b9JhpxkZk7mzIV48BS08OSfmDca340JVON7GayNFnEVz3PkCQ_d49zfsA">"
"scripts" => "<js-placeholder token="KTHomi4oxQStb6_W1b9JhpxkZk7mzIV48BS08OSfmDca340JVON7GayNFnEVz3PkCQ_d49zfsA">"
"scripts_bottom" => "<js-bottom-placeholder token="KTHomi4oxQStb6_W1b9JhpxkZk7mzIV48BS08OSfmDca340JVON7GayNFnEVz3PkCQ_d49zfsA">"
"head" => "<head-placeholder token="KTHomi4oxQStb6_W1b9JhpxkZk7mzIV48BS08OSfmDca340JVON7GayNFnEVz3PkCQ_d49zfsA">"
]
"drupalSettings" => array:5 [▼
"gtm" => array:2 [▼
"tagIds" => array:1 [▶]
"settings" => array:7 [▼
"data_layer" => "dataLayer"
"include_classes" => false
"allowlist_classes" => ""
"blocklist_classes" => ""
"include_environment" => false
"environment_id" => ""
"environment_token" => ""
]
]
"gtag" => array:5 [▼
"tagId" => ""
"otherIds" => []
"consentMode" => false
"events" => []
"additionalConfigInfo" => []
]
"views" => array:2 [▼
"ajax_path" => "/views/ajax"
"ajaxViews" => array:1 [▶]
]
"ajaxTrustedUrl" => array:1 [▼
"/search/node" => true
]
"toolbar" => array:2 [▼
"breakpoints" => array:3 [▶]
"subtreesHash" => "g0npP83EmiVh3S33o-B8LQZZ626GNz6wn7pWNrFjXD0"
]
]
"placeholders" => array:6 [▼
"<drupal-render-placeholder callback="Drupal\Core\Render\Element\StatusMessages::renderMessages" arguments="0" token="_HAdUpwWmet0TOTe2PSiJuMntExoshbm1kh2wQzzzAA"></drupal-render-placeholder>" => array:1 [▶]
"<drupal-render-placeholder callback="announcements_feed.lazy_builders:renderAnnouncements" token="m--BNYDqgTao0j2QoLFf1TwfQN-Bm9xPlckw9QAC1h4"></drupal-render-placeholder>" => array:2 [▶]
"<drupal-render-placeholder callback="devel.lazy_builders:renderMenu" token="3SaamyNrJZMMYe_kyv4Lc7-K5z3OkYidDaYEaMx_yVs"></drupal-render-placeholder>" => array:1 [▶]
"<drupal-render-placeholder callback="user.toolbar_link_builder:renderToolbarLinks" token="QPmvukHqpEJJ4rYEzUUFx0ERxrtfmQ9TMOp_hvyLHEk"></drupal-render-placeholder>" => array:2 [▶]
"<drupal-render-placeholder callback="user.toolbar_link_builder:renderDisplayName" token="XGROnxBLjNjdNZJ_VcOhVZtenx2tDkIKPfojS_uZFXA"></drupal-render-placeholder>" => array:2 [▶]
"<drupal-render-placeholder callback="shortcut.lazy_builders:lazyLinks" token="5-XBI-QHgyU_l7Bu0FizHR7YBqK2bTVTBFF8Z0DVTis"></drupal-render-placeholder>" => array:3 [▶]
]
]
Edited by Chris Green