You are here

function responsive_favicons_page_attachments in Responsive Favicons 8

Implements hook_page_attachments().

Adds responsive favicons to HTML head. A trailing newline is added to ensure the next tag in the HTML head section starts on the next line.

File

./responsive_favicons.module, line 35
Contains responsive_favicons.module.

Code

function responsive_favicons_page_attachments(array &$page) {
  $tags = responsive_favicons_load_all_icons();
  if (!empty($tags['found'])) {
    $html = [
      '#tag' => 'meta',
      '#attributes' => [
        'name' => 'favicon-generator',
        'content' => 'Drupal responsive_favicons + realfavicongenerator.net',
      ],
      // This seems like the only way to inject raw HTML into the head section
      // of Drupal 8.
      // @todo find a way to make this better.
      '#prefix' => Markup::create(implode(PHP_EOL, $tags['found']) . PHP_EOL),
      '#suffix' => '',
    ];
    $page['#attached']['html_head'][] = [
      $html,
      'responsive_favicons',
    ];
  }
}