Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / metatag / metatag_favicons / metatag_favicons.module
index 00e1fba1dd7b2c5bc17d1aec326660729142e926..39a0b19eea182e070995dca73b3bc432767a40d7 100644 (file)
@@ -2,7 +2,7 @@
 
 /**
  * @file
- * Contains metatag_favicons.module.
+ * Custom hook implementations for Metatag Favicons.
  */
 
 use Drupal\Core\Routing\RouteMatchInterface;
@@ -22,3 +22,24 @@ function metatag_favicons_help($route_name, RouteMatchInterface $route_match) {
     default:
   }
 }
+
+/**
+ * Implements hook_page_attachments_alter().
+ */
+function metatag_favicons_page_attachments_alter(array &$attachments) {
+  // Check html_head_link on attached tags in head.
+  if (!isset($attachments['#attached']['html_head_link'])) {
+    return;
+  }
+
+  // Remove the default shortcut icon if one was set by Metatag.
+  foreach ($attachments['#attached']['html_head'] as $element) {
+    if (isset($element[1]) && $element[1] == 'shortcut_icon') {
+      foreach ($attachments['#attached']['html_head_link'] as $key => $value) {
+        if (isset($value[0]['rel']) && $value[0]['rel'] == 'shortcut icon') {
+          unset($attachments['#attached']['html_head_link'][$key]);
+        }
+      }
+    }
+  }
+}