You are here

function metatag_preprocess_html in Metatag 8

Same name and namespace in other branches
  1. 7 metatag.module \metatag_preprocess_html()

Implements template_preprocess_html().

File

./metatag.module, line 452
Contains metatag.module.

Code

function metatag_preprocess_html(&$variables) {
  if (!metatag_is_current_route_supported()) {
    return NULL;
  }
  $metatag_attachments =& drupal_static('metatag_attachments');
  if (is_null($metatag_attachments)) {
    $metatag_attachments = metatag_get_tags_from_route();
  }
  if (!$metatag_attachments) {
    return NULL;
  }

  // Copy the "title" meta tag into the regular <title> tag. The redundant meta
  // tag is never added to $variables['#attached'].
  // @see metatag_page_attachments()
  if (!empty($metatag_attachments['#attached']['html_head'])) {
    foreach ($metatag_attachments['#attached']['html_head'] as $attachment) {
      if (!empty($attachment[1]) && $attachment[1] == 'title') {

        // Empty head_title to avoid the site name and slogan to be appended to
        // the meta title.
        $variables['head_title'] = [];
        $variables['head_title']['title'] = html_entity_decode($attachment[0]['#attributes']['content'], ENT_QUOTES);

        // No need to do anything else after this.
        break;
      }
    }
  }
}