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 if (isset($item[1])) {
62 // The Metatag values are output before core's, so skip the first item
63 // found so it can be picked up as the dupe; this is important for the
64 // "viewport" meta tag where both core and Metatag use the same name.
65 if ($item[1] == $meta_tag && !isset($found[$meta_tag])) {
66 $found[$meta_tag] = $key;
68 elseif ($item[1] == $core_tag && 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.
82 * The format is (all on oneline):
83 * <link rel="alternate" href="android-app://com.example.Example
84 * /sitesection/sitepage/thispage" />
86 function theme_metatag_mobile_android_app($variables) {
87 // Pass everything through to the normal 'link' tag theme.
88 $variables['element']['#name'] = 'alternative';
89 $variables['element']['#value'] = 'android-app://' . $variables['element']['#value'];
91 return theme('metatag_link_rel', $variables);
95 * Theme callback for an iOS app link meta tag.
98 * <link rel="alternate" href="ios-app://123456/example/hello-screen" />
100 function theme_metatag_mobile_ios_app($variables) {
101 // Pass everything through to the normal 'link' tag theme.
102 $variables['element']['#name'] = 'alternative';
103 $variables['element']['#value'] = 'ios-app://' . $variables['element']['#value'];
105 return theme('metatag_link_rel', $variables);