From a5c86354224ac8504fff06251da5f8e58ca15356 Mon Sep 17 00:00:00 2001 From: tadean <51835841+tadean@users.noreply.github.com> Date: Wed, 11 Sep 2024 10:48:09 -0700 Subject: [PATCH] Fixes #3678 Add Generator Metatag (#3680) --- modules/custom/az_core/az_core.module | 20 ++++++++++++ modules/custom/az_core/az_core.services.yml | 4 +++ .../EventSubscriber/AZGeneratorSubscriber.php | 31 +++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 modules/custom/az_core/src/EventSubscriber/AZGeneratorSubscriber.php diff --git a/modules/custom/az_core/az_core.module b/modules/custom/az_core/az_core.module index b05052ded0..d5fdefb246 100644 --- a/modules/custom/az_core/az_core.module +++ b/modules/custom/az_core/az_core.module @@ -372,6 +372,26 @@ function _az_core_check_attribute_form(array &$form, FormStateInterface $form_st } } +/** + * Implements hook_page_attachments_alter(). + * + * Override Drupal core generator metatag for distribution. + */ +function az_core_page_attachments_alter(array &$page) { + // Verify we're not trying to add tag to some page that should not have it. + if (!empty($page['#attached']['html_head'])) { + foreach ($page['#attached']['html_head'] as &$head_item) { + // Check if the current item is the meta generator. + if (is_array($head_item) && in_array('system_meta_generator', $head_item, TRUE)) { + // Update the tag if it's present. + if (!empty($head_item[0]['#attributes']['content'])) { + $head_item[0]['#attributes']['content'] = 'Arizona Quickstart (https://quickstart.arizona.edu)'; + } + } + } + } +} + /** * Form validation that fails validation on protected term pages. * diff --git a/modules/custom/az_core/az_core.services.yml b/modules/custom/az_core/az_core.services.yml index 2fc8135496..7140618f19 100755 --- a/modules/custom/az_core/az_core.services.yml +++ b/modules/custom/az_core/az_core.services.yml @@ -7,6 +7,10 @@ services: - '@current_route_match' tags: - { name: page_cache_response_policy } + az_core_generator: + public: false + class: Drupal\az_core\EventSubscriber\AZGeneratorSubscriber + decorates: response_generator_subscriber logger.channel.az_core: parent: logger.channel_base arguments: diff --git a/modules/custom/az_core/src/EventSubscriber/AZGeneratorSubscriber.php b/modules/custom/az_core/src/EventSubscriber/AZGeneratorSubscriber.php new file mode 100644 index 0000000000..b8b5036d28 --- /dev/null +++ b/modules/custom/az_core/src/EventSubscriber/AZGeneratorSubscriber.php @@ -0,0 +1,31 @@ +isMainRequest()) { + return; + } + + $response = $event->getResponse(); + + $response->headers->set('X-Generator', 'Arizona Quickstart (https://quickstart.arizona.edu)'); + } + +}