You are here

function disable_language_page_attachments_alter in Disable language 8

Implements hook_page_attachments_alter().

File

./disable_language.module, line 162
Contains disable_language.module.

Code

function disable_language_page_attachments_alter(array &$attachments) {
  $disabledLanguages = \Drupal::service('disable_language.disable_language_manager')
    ->getDisabledLanguages();
  if (isset($attachments['#attached']['html_head_link'])) {
    foreach ($attachments['#attached']['html_head_link'] as $key => $value) {

      // Remove the hreflang tags for the disabled languages.
      if (isset($value[0]['hreflang']) && $disabledLanguages && in_array($value[0]['hreflang'], array_keys($disabledLanguages))) {
        unset($attachments['#attached']['html_head_link'][$key]);
      }
    }
  }
}