You are here

function remove_http_headers_page_attachments_alter in Remove HTTP headers 8

Remove the "Generator" meta tag from the <head> section.

If the "X-Generator" should be removed.


<head>
   <meta name="Generator" content="Drupal 8 (https://www.drupal.org)">
</head>

File

./remove_http_headers.module, line 21
Contains remove_http_headers module hooks.

Code

function remove_http_headers_page_attachments_alter(array &$attachments) : void {

  /** @var \Drupal\remove_http_headers\Config\ConfigManager $config_manager */
  $config_manager = \Drupal::service('remove_http_headers.config_manager');
  if ($config_manager
    ->shouldHeaderBeRemoved('X-Generator')) {
    foreach ($attachments['#attached']['html_head'] as $key => $attachment) {
      if ($attachment[1] == 'system_meta_generator') {
        unset($attachments['#attached']['html_head'][$key]);
      }
    }
  }
}