metatag_favicons.module 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * @file
  4. * Custom hook implementations for Metatag Favicons.
  5. */
  6. use Drupal\Core\Routing\RouteMatchInterface;
  7. /**
  8. * Implements hook_help().
  9. */
  10. function metatag_favicons_help($route_name, RouteMatchInterface $route_match) {
  11. switch ($route_name) {
  12. // Main module help for the metatag_favicons module.
  13. case 'help.page.metatag_favicons':
  14. $output = '';
  15. $output .= '<h3>' . t('About') . '</h3>';
  16. $output .= '<p>' . t('Provides support for many different favicons.') . '</p>';
  17. return $output;
  18. default:
  19. }
  20. }
  21. /**
  22. * Implements hook_page_attachments_alter().
  23. */
  24. function metatag_favicons_page_attachments_alter(array &$attachments) {
  25. // Check html_head_link on attached tags in head.
  26. if (!isset($attachments['#attached']['html_head_link'])) {
  27. return;
  28. }
  29. // Remove the default shortcut icon if one was set by Metatag.
  30. foreach ($attachments['#attached']['html_head'] as $element) {
  31. if (isset($element[1]) && $element[1] == 'shortcut_icon') {
  32. foreach ($attachments['#attached']['html_head_link'] as $key => $value) {
  33. if (isset($value[0]['rel']) && $value[0]['rel'] == 'shortcut icon') {
  34. unset($attachments['#attached']['html_head_link'][$key]);
  35. }
  36. }
  37. }
  38. }
  39. }