Further modules included.
[yaffs-website] / web / modules / contrib / metatag / metatag_mobile / metatag_mobile.module
1 <?php
2
3 /**
4  * @file
5  * Contains metatag_mobile.module..
6  */
7
8 use Drupal\Core\Routing\RouteMatchInterface;
9
10 /**
11  * Implements hook_help().
12  */
13 function metatag_mobile_help($route_name, RouteMatchInterface $route_match) {
14   switch ($route_name) {
15     // Main module help for the metatag_mobile module.
16     case 'help.page.metatag_mobile':
17       $output = '';
18       $output .= '<h3>' . t('About') . '</h3>';
19       $output .= '<p>' . t('Provides support for meta tags used to control the mobile browser experience.') . '</p>';
20       return $output;
21
22     default:
23   }
24 }
25
26 /**
27  * Implements hook_theme().
28  */
29 function metatag_mobile_theme() {
30   $info['metatag_mobile_android_app'] = [
31     'render element' => 'element',
32   ];
33   $info['metatag_mobile_ios_app'] = [
34     'render element' => 'element',
35   ];
36
37   return $info;
38 }
39
40 /**
41  * Implements hook_page_attachments_alter().
42  */
43 function metatag_mobile_page_attachments_alter(array &$attachments) {
44   if (isset($attachments['#attached']['html_head'])) {
45     // A list of core tags that will be replaced, in the format:
46     //   core tag => Metatag-supplied tag
47     // This assumes that the module's meta tags are output *before* the core
48     // tags, if this changes then We're Going To Have A Bad Time.
49     $dupes = [
50       'MobileOptimized' => 'mobileoptimized',
51       'HandheldFriendly' => 'handheldfriendly',
52       'viewport' => 'viewport',
53     ];
54
55     // Keep track of when the Metatag-supplied meta tags are found, so if the
56     // core tag is also found it can be removed.
57     $found = [];
58
59     foreach ($dupes as $core_tag => $meta_tag) {
60       foreach ($attachments['#attached']['html_head'] as $key => $item) {
61         // The Metatag values are output before core's, so skip the first item
62         // found so it can be picked up as the dupe; this is important for the
63         // "viewport" meta tag where both core and Metatag use the same name.
64         if ($item[1] == $meta_tag && !isset($found[$meta_tag])) {
65           $found[$meta_tag] = $key;
66         }
67         elseif ($item[1] == $core_tag) {
68           if (isset($found[$meta_tag])) {
69             // @todo This ought to work, but doesn't?
70             // $attachments['#attached']['html_head'][$key]['#access'] = FALSE;
71             unset($attachments['#attached']['html_head'][$key]);
72           }
73         }
74       }
75     }
76   }
77 }
78
79 /**
80  * Theme callback for an Android app link meta tag.
81  *
82  * The format is:
83  * <link rel="alternate" href="android-app://com.example.Example/sitesection/sitepage/thispage" />
84  */
85 function theme_metatag_mobile_android_app($variables) {
86   // Pass everything through to the normal 'link' tag theme.
87   $variables['element']['#name'] = 'alternative';
88   $variables['element']['#value'] = 'android-app://' . $variables['element']['#value'];
89
90   return theme('metatag_link_rel', $variables);
91 }
92
93 /**
94  * Theme callback for an iOS app link meta tag.
95  *
96  * The format is:
97  * <link rel="alternate" href="ios-app://123456/example/hello-screen" />
98  */
99 function theme_metatag_mobile_ios_app($variables) {
100   // Pass everything through to the normal 'link' tag theme.
101   $variables['element']['#name'] = 'alternative';
102   $variables['element']['#value'] = 'ios-app://' . $variables['element']['#value'];
103
104   return theme('metatag_link_rel', $variables);
105 }
106
107 /*
108 * theme-color
109 * MobileOptimized
110 * HandheldFriendly
111 * viewport
112 * cleartype
113 * apple-mobile-web-app-capable
114 * apple-mobile-web-app-status-bar-style
115 * format-detection
116 * android-app
117 */