-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta_tags.install
113 lines (98 loc) · 2.73 KB
/
meta_tags.install
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* Implements hook_install()
*/
function meta_tags_install() {
// Check to see if the annotation field exists.
$field = field_info_field('meta_title');
// If the annotation field does not exist then create it.
if (empty($field)) {
$field = array(
'field_name' => 'meta_title',
'entity_types' => array('node'),
'translatable' => TRUE,
'type' => 'text',
);
$field = field_create_field($field);
}
// Check to see if the annotation field exists.
$field = field_info_field('meta_desc');
// If the annotation field does not exist then create it.
if (empty($field)) {
$field = array(
'field_name' => 'meta_desc',
'type' => 'text',
'entity_types' => array('node'),
'translatable' => TRUE,
'widget' => array(
'type' => 'text_textarea_with_summary',
'settings' => array(
'rows' => 10,
'summary_rows' => 3,
),
),
);
$field = field_create_field($field);
}
// Check to see if the annotation field exists.
$field = field_info_field('meta_keywords');
// If the annotation field does not exist then create it.
if (empty($field)) {
$field = array(
'field_name' => 'meta_keywords',
'type' => 'text',
'entity_types' => array('node'),
'translatable' => TRUE,
'widget' => array(
'type' => 'text_textarea_with_summary',
'settings' => array(
'rows' => 10,
'summary_rows' => 3,
),
),
);
$field = field_create_field($field);
}
drupal_set_message('Module installed');
}
/**
* Implements hook_uninstall()
*/
function meta_tags_uninstall() {
watchdog("Meta tags Module", "Uninstalling module and deleting fields");
$types = node_type_get_types();
foreach($types as $type) {
meta_tags_delete_meta_tags($type);
}
$field = field_info_field('meta_title');
if ($field) {
field_delete_field('meta_title');
}
$field = field_info_field('meta_desc');
if ($field) {
field_delete_field('meta_desc');
}
$field = field_info_field('meta_keywords');
if ($field) {
field_delete_field('meta_keywords');
}
variable_del('meta_tags_default_keywords');
variable_del('meta_tags_default_desc');
variable_del('meta_tags_default_title');
variable_del('meta_tags_node_types');
cache_clear_all('variables', 'cache');
}
function meta_tags_delete_meta_tags($type) {
$instance = field_info_instance('node', 'meta_title', $type->type);
if ($instance) {
field_delete_instance($instance, false);
}
$instance = field_info_instance('node', 'meta_desc', $type->type);
if ($instance) {
field_delete_instance($instance, false);
}
$instance = field_info_instance('node', 'meta_keywords', $type->type);
if ($instance) {
field_delete_instance($instance, false);
}
}