1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Install file for the link module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
39a181a4
|
Assos Assos
|
* Upgrade notes.
|
10 |
|
|
*
|
11 |
|
|
* Things we need to make sure work when upgrading from Drupal 6 to Drupal 7:.
|
12 |
85ad3d82
|
Assos Assos
|
*/
|
13 |
|
|
|
14 |
39a181a4
|
Assos Assos
|
/**
|
15 |
8e7483ab
|
Assos Assos
|
* Implements hook_install().
|
16 |
39a181a4
|
Assos Assos
|
*/
|
17 |
|
|
function link_install() {
|
18 |
|
|
// Notify the user they may want to install token.
|
19 |
|
|
if (!module_exists('token')) {
|
20 |
|
|
$t = get_t();
|
21 |
|
|
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(
|
22 |
|
|
'!url' => 'http://drupal.org/project/token',
|
23 |
|
|
)));
|
24 |
|
|
}
|
25 |
|
|
}
|
26 |
|
|
|
27 |
|
|
/**
|
28 |
|
|
* Removes unused link_extra_domains variable.
|
29 |
|
|
*/
|
30 |
|
|
function link_update_7002() {
|
31 |
|
|
variable_del('link_extra_domains');
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
/**
|
35 |
|
|
* Implements hook_uninstall().
|
36 |
|
|
*/
|
37 |
|
|
function link_uninstall() {
|
38 |
|
|
variable_del('link_allowed_domains');
|
39 |
bad4e148
|
Assos Assos
|
variable_del('link_default_protocol');
|
40 |
39a181a4
|
Assos Assos
|
}
|
41 |
|
|
|
42 |
85ad3d82
|
Assos Assos
|
/**
|
43 |
|
|
* Implements hook_field_schema().
|
44 |
|
|
*/
|
45 |
|
|
function link_field_schema($field) {
|
46 |
|
|
return array(
|
47 |
|
|
'columns' => array(
|
48 |
|
|
'url' => array(
|
49 |
|
|
'type' => 'varchar',
|
50 |
|
|
// Maximum URLs length.
|
51 |
|
|
'length' => 2048,
|
52 |
|
|
'not null' => FALSE,
|
53 |
|
|
'sortable' => TRUE,
|
54 |
|
|
),
|
55 |
|
|
'title' => array(
|
56 |
|
|
'type' => 'varchar',
|
57 |
|
|
'length' => 255,
|
58 |
|
|
'not null' => FALSE,
|
59 |
|
|
'sortable' => TRUE,
|
60 |
|
|
),
|
61 |
|
|
'attributes' => array(
|
62 |
|
|
'type' => 'text',
|
63 |
|
|
'size' => 'medium',
|
64 |
|
|
'not null' => FALSE,
|
65 |
|
|
),
|
66 |
|
|
),
|
67 |
|
|
);
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
/**
|
71 |
|
|
* Implements hook_update_last_removed().
|
72 |
|
|
*/
|
73 |
|
|
function link_update_last_removed() {
|
74 |
|
|
return 6001;
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
/**
|
78 |
39a181a4
|
Assos Assos
|
* Implements hook_update_N().
|
79 |
|
|
*
|
80 |
|
|
* Handles moving settings data from field_config.data to
|
81 |
|
|
* field_config_instance.data.
|
82 |
85ad3d82
|
Assos Assos
|
*/
|
83 |
|
|
function link_update_7000() {
|
84 |
39a181a4
|
Assos Assos
|
|
85 |
|
|
// For each field that is a link field, we need to copy the settings from the
|
86 |
|
|
// general field level down to the instance.
|
87 |
85ad3d82
|
Assos Assos
|
$result = db_query("SELECT id, field_name, data FROM {field_config} WHERE module = 'link' AND type = 'link_field'");
|
88 |
|
|
foreach ($result as $field) {
|
89 |
39a181a4
|
Assos Assos
|
|
90 |
85ad3d82
|
Assos Assos
|
$field_data = unserialize($field->data);
|
91 |
39a181a4
|
Assos Assos
|
|
92 |
|
|
$instances = db_query("SELECT id, data FROM {field_config_instance} WHERE field_id = :field_id", array(':field_id' => $field->id));
|
93 |
85ad3d82
|
Assos Assos
|
foreach ($instances as $instance) {
|
94 |
|
|
// If this field has been updated already, we want to skip it.
|
95 |
|
|
$instance_data = unserialize($instance->data);
|
96 |
|
|
$update_instance = FALSE;
|
97 |
|
|
if (!isset($instance_data['settings']['title'])) {
|
98 |
|
|
foreach ($field_data['settings'] as $key => $value) {
|
99 |
|
|
if (!isset($instance_data['settings'][$key])) {
|
100 |
|
|
$instance_data['settings'][$key] = $value;
|
101 |
|
|
$update_instance = TRUE;
|
102 |
|
|
}
|
103 |
|
|
}
|
104 |
|
|
if ($update_instance) {
|
105 |
39a181a4
|
Assos Assos
|
// Update the database.
|
106 |
|
|
db_update('field_config_instance')
|
107 |
85ad3d82
|
Assos Assos
|
->fields(array('data' => serialize($instance_data)))
|
108 |
|
|
->condition('id', $instance->id)
|
109 |
|
|
->execute();
|
110 |
|
|
}
|
111 |
|
|
}
|
112 |
|
|
}
|
113 |
|
|
}
|
114 |
39a181a4
|
Assos Assos
|
|
115 |
85ad3d82
|
Assos Assos
|
return t("Instance settings have been set with the data from the field settings.");
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
/**
|
119 |
39a181a4
|
Assos Assos
|
* Renames all displays from foobar to link_foobar.
|
120 |
85ad3d82
|
Assos Assos
|
*/
|
121 |
|
|
function link_update_7001() {
|
122 |
|
|
// Update the display type for each link field type.
|
123 |
|
|
$result = db_query("SELECT id, field_name, data FROM {field_config} WHERE module = 'link' AND type = 'link_field'");
|
124 |
|
|
foreach ($result as $field) {
|
125 |
39a181a4
|
Assos Assos
|
|
126 |
|
|
$instances = db_query("SELECT id, data FROM {field_config_instance} WHERE field_id = :field_id", array(':field_id' => $field->id));
|
127 |
85ad3d82
|
Assos Assos
|
foreach ($instances as $instance) {
|
128 |
|
|
// If this field has been updated already, we want to skip it.
|
129 |
|
|
$instance_data = unserialize($instance->data);
|
130 |
|
|
$update_instance = FALSE;
|
131 |
|
|
foreach ($instance_data['display'] as $display_name => $display_data) {
|
132 |
|
|
if ($display_data['type'] && (0 !== strpos($display_data['type'], 'link_'))) {
|
133 |
|
|
$instance_data['display'][$display_name]['type'] = 'link_' . $display_data['type'];
|
134 |
|
|
$update_instance = TRUE;
|
135 |
|
|
}
|
136 |
|
|
}
|
137 |
|
|
if ($update_instance) {
|
138 |
|
|
db_update('field_config_instance')
|
139 |
|
|
->fields(array('data' => serialize($instance_data)))
|
140 |
|
|
->condition('id', $instance->id)
|
141 |
|
|
->execute();
|
142 |
|
|
}
|
143 |
|
|
}
|
144 |
|
|
}
|
145 |
|
|
} |