Skip to main content
gave credits to the code shown in the answer
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

The invocation of theDrupal 8 doesn't use hook_html_head_alter() was removed from Drupal core.
Issue - Its usage has been removed in Remove invocation of hook_html_head_alter().

D8 has a new hook As described in drupal_add_*() deprecated in favour of #attached, in Drupal 8 is possible to achieve ituse :hook_page_attachments() and hook_page_attachments_alter().

Code fromhook_page_attachments_alter(), for example using code similar to the change recordfollowing one, suggested in :one of the comments for the change record.

function MYTHEME_page_attachments_alter(array &$page) {
    $viewport = [
      '#type' => 'html_tag',
      '#tag' => 'meta',
      '#attributes' => [
        'name' => 'viewport',
        'content' => 'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no',
      ],
    ];
    $page['#attached']['html_head'][] = [$viewport, 'viewport'];
  }
function MYTHEME_page_attachments_alter(array &$page) {
  $viewport = [
    '#type' => 'html_tag',
    '#tag' => 'meta',
    '#attributes' => [
      'name' => 'viewport',
      'content' => 'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no',
    ],
  ];
  
  $page['#attached']['html_head'][] = [$viewport, 'viewport'];
}

The invocation of the hook_html_head_alter was removed from Drupal core.
Issue - Remove invocation of hook_html_head_alter().

D8 has a new hook to achieve it : hook_page_attachments_alter().

Code from the change record :

function MYTHEME_page_attachments_alter(array &$page) {
    $viewport = [
      '#type' => 'html_tag',
      '#tag' => 'meta',
      '#attributes' => [
        'name' => 'viewport',
        'content' => 'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no',
      ],
    ];
    $page['#attached']['html_head'][] = [$viewport, 'viewport'];
  }

Drupal 8 doesn't use hook_html_head_alter(). Its usage has been removed in Remove invocation of hook_html_head_alter(). As described in drupal_add_*() deprecated in favour of #attached, in Drupal 8 is possible to use hook_page_attachments() and hook_page_attachments_alter(), for example using code similar to the following one, suggested in one of the comments for the change record.

function MYTHEME_page_attachments_alter(array &$page) {
  $viewport = [
    '#type' => 'html_tag',
    '#tag' => 'meta',
    '#attributes' => [
      'name' => 'viewport',
      'content' => 'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no',
    ],
  ];
  
  $page['#attached']['html_head'][] = [$viewport, 'viewport'];
}
convert to short array syntax
Source Link
AjitS
  • 10.9k
  • 7
  • 41
  • 73

The invocation of the hook_html_head_alter was removed from Drupal core.
Issue - Remove invocation of hook_html_head_alter().

D8 has a new hook to achieve it : hook_page_attachments_alter().

Code from the change record :

function MYTHEME_page_attachments_alter(array &$page) {
    $viewport = array([
      '#type' => 'html_tag',
      '#tag' => 'meta',
      '#attributes' => array([
        'name' => 'viewport',
        'content' => 'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no',
      )],
    );];
    $page['#attached']['html_head'][] = [$viewport, 'viewport'];
  }

The invocation of the hook_html_head_alter was removed from Drupal core.
Issue - Remove invocation of hook_html_head_alter().

D8 has a new hook to achieve it : hook_page_attachments_alter().

Code from the change record :

function MYTHEME_page_attachments_alter(array &$page) {
    $viewport = array(
      '#type' => 'html_tag',
      '#tag' => 'meta',
      '#attributes' => array(
        'name' => 'viewport',
        'content' => 'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no',
      ),
    );
    $page['#attached']['html_head'][] = [$viewport, 'viewport'];
  }

The invocation of the hook_html_head_alter was removed from Drupal core.
Issue - Remove invocation of hook_html_head_alter().

D8 has a new hook to achieve it : hook_page_attachments_alter().

Code from the change record :

function MYTHEME_page_attachments_alter(array &$page) {
    $viewport = [
      '#type' => 'html_tag',
      '#tag' => 'meta',
      '#attributes' => [
        'name' => 'viewport',
        'content' => 'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no',
      ],
    ];
    $page['#attached']['html_head'][] = [$viewport, 'viewport'];
  }
Source Link
AjitS
  • 10.9k
  • 7
  • 41
  • 73

The invocation of the hook_html_head_alter was removed from Drupal core.
Issue - Remove invocation of hook_html_head_alter().

D8 has a new hook to achieve it : hook_page_attachments_alter().

Code from the change record :

function MYTHEME_page_attachments_alter(array &$page) {
    $viewport = array(
      '#type' => 'html_tag',
      '#tag' => 'meta',
      '#attributes' => array(
        'name' => 'viewport',
        'content' => 'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no',
      ),
    );
    $page['#attached']['html_head'][] = [$viewport, 'viewport'];
  }