-
Notifications
You must be signed in to change notification settings - Fork 3
/
integrate_with_metatag-2061359.patch
71 lines (70 loc) · 2.89 KB
/
integrate_with_metatag-2061359.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
diff --git a/smart_paging.module b/smart_paging.module
index 4c53821..6e76d00 100644
--- a/smart_paging.module
+++ b/smart_paging.module
@@ -869,15 +869,21 @@ function smart_paging_field_attach_view_alter(&$build, $context) {
preg_match_all('#<!--smartpagingmeta [[:punct:][:alnum:][:space:]]*-->#', $sub_content, $matched_tags);
if (!empty($matched_tags[0])) {
$smart_paging_seo = preg_replace('#<!--smartpagingmeta |<!--smartpagingurl [[:punct:][:alnum:][:space:]]*-->|-->#', '', $matched_tags[0][0]);
- drupal_add_html_head(array(
- '#attributes' => array(
- 'name' => 'Smart_Paging',
- 'content' => $smart_paging_seo,
- ),
- '#tag' => 'meta'
- ), 'smart_paging_seo');
- // Call this function to register the additional html head
- drupal_get_html_head();
+ if (!module_exists('metatag')) {
+ drupal_add_html_head(array(
+ '#attributes' => array(
+ 'name' => 'Smart_Paging',
+ 'content' => $smart_paging_seo,
+ ),
+ '#tag' => 'meta'
+ ), 'smart_paging_seo');
+ // Call this function to register the additional html head
+ drupal_get_html_head();
+ }
+ else {
+ $output = &drupal_static('smart_paging');
+ $output = json_decode($smart_paging_seo, TRUE);
+ }
}
}
}
@@ -1739,3 +1745,35 @@ function _smart_paging_href_replace($match) {
return 'href="/' . $path_info['path'] . '?' . urldecode($path_info['query']) . '"';
}
+/**
+ * Implements hook_metatags_view_alter().
+ */
+function smart_paging_metatag_metatags_view_alter(&$output, $instance) {
+ // Load metatags set for this page.
+ $page_metatags = drupal_static('smart_paging');
+
+ if (!empty($page_metatags)) {
+ $metatags = array();
+ $output_metatags = array();
+ $options['instance'] = $instance;
+ $node = menu_get_object();
+ // Rearrange the array so that we can use metatag module classes.
+ foreach ($page_metatags as $metatag => $value) {
+ if (isset($value) && !empty($value)) {
+ $target_tag = explode('_', $metatag);
+ if (isset($target_tag[0]) && isset($target_tag[1]) && isset($target_tag[2]) && isset($target_tag[3])) {
+ $metatags[$target_tag[2]] = array('value' => token_replace($value, array('node' => $node)));
+ }
+ }
+ }
+ // Create objects for each metatag so that we get all required information.
+ foreach ($metatags as $metatag => $data) {
+ if ($metatag_instance = metatag_get_instance($metatag, $data)) {
+ $output_metatags[$metatag] = $metatag_instance->getElement($options);
+ }
+ }
+
+ // Merge with metatags provided by other modules.
+ $output = array_merge($output, $output_metatags);
+ }
+}