5 * Contains metatag_mobile.module..
8 use Drupal\Core\Routing\RouteMatchInterface;
11 * Implements hook_help().
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':
18 $output .= '<h3>' . t('About') . '</h3>';
19 $output .= '<p>' . t('Provides support for meta tags used to control the mobile browser experience.') . '</p>';
27 * Implements hook_theme().
29 function metatag_mobile_theme() {
30 $info['metatag_mobile_android_app'] = [
31 'render element' => 'element',
33 $info['metatag_mobile_ios_app'] = [
34 'render element' => 'element',
41 * Implements hook_page_attachments_alter().
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.
50 'MobileOptimized' => 'mobileoptimized',
51 'HandheldFriendly' => 'handheldfriendly',
52 'viewport' => 'viewport',
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.
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;
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]);
80 * Theme callback for an Android app link meta tag.
83 * <link rel="alternate" href="android-app://com.example.Example/sitesection/sitepage/thispage" />
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'];
90 return theme('metatag_link_rel', $variables);
94 * Theme callback for an iOS app link meta tag.
97 * <link rel="alternate" href="ios-app://123456/example/hello-screen" />
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'];
104 return theme('metatag_link_rel', $variables);
113 * apple-mobile-web-app-capable
114 * apple-mobile-web-app-status-bar-style