Favicon

Hook for adding favicons and locations. 

/**
 * Responsive favicon.
 *
 * Implements hook_page_attachments_alter().
 */
function mantra_starter_page_attachments_alter(array &$attachments) {
  $theme_path = \Drupal::service('extension.list.theme')->getPath('mantra_starter');

  $icons = [
    // Scalable, adapts to light/dark via the SVG's own media query.
    ['rel' => 'icon', 'type' => 'image/svg+xml', 'href' => "/$theme_path/logo.svg"],
    // Legacy .ico fallback.
    ['rel' => 'icon', 'type' => 'image/x-icon', 'href' => "/$theme_path/favicon/favicon.ico"],
    // iOS.
    ['rel' => 'apple-touch-icon', 'sizes' => '180x180', 'href' => "/$theme_path/favicon/apple-touch-icon.png"],
    // PWA manifest.
    ['rel' => 'manifest', 'href' => "/$theme_path/favicon/manifest.webmanifest"],
  ];

  foreach ($icons as $i => $attrs) {
    $attachments['#attached']['html_head'][] = [
      ['#tag' => 'link', '#attributes' => $attrs],
      "mantra_starter_favicon_$i",
    ];
  }
}