-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink.install
144 lines (130 loc) · 4.01 KB
/
link.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/**
* @file
* Install file for the link module.
*/
/**
* Upgrade notes.
*
* Things we need to make sure work when upgrading from Drupal 6 to Drupal 7:.
*/
/**
* Implements hook_install().
*/
function link_install() {
// Notify the user they may want to install token.
if (!module_exists('token')) {
$t = get_t();
drupal_set_message($t('If you install the <a href="!url" target="blank">Token</a>, static title can use any other entity field as its value.', array(
'!url' => 'http://drupal.org/project/token',
)));
}
}
/**
* Removes unused link_extra_domains variable.
*/
function link_update_7002() {
variable_del('link_extra_domains');
}
/**
* Implements hook_uninstall().
*/
function link_uninstall() {
variable_del('link_allowed_domains');
}
/**
* Implements hook_field_schema().
*/
function link_field_schema($field) {
return array(
'columns' => array(
'url' => array(
'type' => 'varchar',
// Maximum URLs length.
'length' => 2048,
'not null' => FALSE,
'sortable' => TRUE,
),
'title' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'sortable' => TRUE,
),
'attributes' => array(
'type' => 'text',
'size' => 'medium',
'not null' => FALSE,
),
),
);
}
/**
* Implements hook_update_last_removed().
*/
function link_update_last_removed() {
return 6001;
}
/**
* Implements hook_update_N().
*
* Handles moving settings data from field_config.data to
* field_config_instance.data.
*/
function link_update_7000() {
// For each field that is a link field, we need to copy the settings from the
// general field level down to the instance.
$result = db_query("SELECT id, field_name, data FROM {field_config} WHERE module = 'link' AND type = 'link_field'");
foreach ($result as $field) {
$field_data = unserialize($field->data);
$instances = db_query("SELECT id, data FROM {field_config_instance} WHERE field_id = :field_id", array(':field_id' => $field->id));
foreach ($instances as $instance) {
// If this field has been updated already, we want to skip it.
$instance_data = unserialize($instance->data);
$update_instance = FALSE;
if (!isset($instance_data['settings']['title'])) {
foreach ($field_data['settings'] as $key => $value) {
if (!isset($instance_data['settings'][$key])) {
$instance_data['settings'][$key] = $value;
$update_instance = TRUE;
}
}
if ($update_instance) {
// Update the database.
db_update('field_config_instance')
->fields(array('data' => serialize($instance_data)))
->condition('id', $instance->id)
->execute();
}
}
}
}
return t("Instance settings have been set with the data from the field settings.");
}
/**
* Renames all displays from foobar to link_foobar.
*/
function link_update_7001() {
// Update the display type for each link field type.
$result = db_query("SELECT id, field_name, data FROM {field_config} WHERE module = 'link' AND type = 'link_field'");
foreach ($result as $field) {
$instances = db_query("SELECT id, data FROM {field_config_instance} WHERE field_id = :field_id", array(':field_id' => $field->id));
foreach ($instances as $instance) {
// If this field has been updated already, we want to skip it.
$instance_data = unserialize($instance->data);
$update_instance = FALSE;
foreach ($instance_data['display'] as $display_name => $display_data) {
if ($display_data['type'] && (0 !== strpos($display_data['type'], 'link_'))) {
$instance_data['display'][$display_name]['type'] = 'link_' . $display_data['type'];
$update_instance = TRUE;
}
}
if ($update_instance) {
db_update('field_config_instance')
->fields(array('data' => serialize($instance_data)))
->condition('id', $instance->id)
->execute();
}
}
}
}