1 |
ca0757b9
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Install, update and uninstall functions for the Media WYSIWYG module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
1e39edcb
|
Assos Assos
|
/**
|
9 |
|
|
* Implements hook_schema().
|
10 |
|
|
*/
|
11 |
|
|
function media_wysiwyg_schema() {
|
12 |
|
|
$schema['media_restrict_wysiwyg'] = array(
|
13 |
|
|
'description' => 'Stores media displays restricted in wysiwyg.',
|
14 |
|
|
'fields' => array(
|
15 |
|
|
'type' => array(
|
16 |
|
|
'description' => 'The machine name of the file type.',
|
17 |
|
|
'type' => 'varchar',
|
18 |
|
|
'length' => 255,
|
19 |
|
|
'not null' => TRUE,
|
20 |
|
|
'default' => '',
|
21 |
|
|
),
|
22 |
|
|
'display' => array(
|
23 |
|
|
'description' => 'The restricted display.',
|
24 |
|
|
'type' => 'varchar',
|
25 |
|
|
'length' => '255',
|
26 |
|
|
'not null' => TRUE,
|
27 |
|
|
'default' => '',
|
28 |
|
|
),
|
29 |
|
|
),
|
30 |
|
|
);
|
31 |
|
|
$schema['media_view_mode_wysiwyg'] = array(
|
32 |
|
|
'description' => 'Maps WYSIWYG view modes to file types.',
|
33 |
|
|
'fields' => array(
|
34 |
|
|
'type' => array(
|
35 |
|
|
'description' => 'The machine name of the file type.',
|
36 |
|
|
'type' => 'varchar',
|
37 |
|
|
'length' => 255,
|
38 |
|
|
'not null' => TRUE,
|
39 |
|
|
'default' => '',
|
40 |
|
|
),
|
41 |
|
|
'view_mode' => array(
|
42 |
|
|
'description' => 'WYSIWYG view mode mapped to this file type.',
|
43 |
|
|
'type' => 'varchar',
|
44 |
|
|
'length' => 255,
|
45 |
|
|
'not null' => TRUE,
|
46 |
|
|
'default' => '',
|
47 |
|
|
),
|
48 |
|
|
|
49 |
|
|
),
|
50 |
|
|
);
|
51 |
|
|
return $schema;
|
52 |
|
|
}
|
53 |
|
|
|
54 |
da542b7b
|
Assos Assos
|
/**
|
55 |
|
|
* Implements hook_install().
|
56 |
|
|
*/
|
57 |
|
|
function media_wysiwyg_install() {
|
58 |
|
|
media_wysiwyg_update_7204();
|
59 |
|
|
}
|
60 |
|
|
|
61 |
ca0757b9
|
Assos Assos
|
/**
|
62 |
|
|
* Implements hook_uninstall().
|
63 |
|
|
*/
|
64 |
|
|
function media_wysiwyg_uninstall() {
|
65 |
|
|
// Remove variables.
|
66 |
|
|
variable_del('media_wysiwyg_wysiwyg_title');
|
67 |
|
|
variable_del('media_wysiwyg_wysiwyg_icon_title');
|
68 |
|
|
variable_del('media_wysiwyg_wysiwyg_default_view_mode');
|
69 |
|
|
variable_del('media_wysiwyg_wysiwyg_upload_directory');
|
70 |
|
|
variable_del('media_wysiwyg_wysiwyg_allowed_types');
|
71 |
|
|
variable_del('media_wysiwyg_wysiwyg_allowed_attributes');
|
72 |
|
|
variable_del('media_wysiwyg_wysiwyg_browser_plugins');
|
73 |
da542b7b
|
Assos Assos
|
variable_del('media_wysiwyg_wysiwyg_override_field_types');
|
74 |
ca0757b9
|
Assos Assos
|
}
|
75 |
bf3c8457
|
Florent Torregrosa
|
|
76 |
|
|
/**
|
77 |
|
|
* Implements hook_update_dependencies().
|
78 |
|
|
*/
|
79 |
|
|
function media_wysiwyg_update_dependencies() {
|
80 |
|
|
// Ensure the "access media browser" permission is granted to users before
|
81 |
|
|
// using it to grant the "use media wysiwyg" permission.
|
82 |
|
|
$dependencies['media_wysiwyg'][7201] = array(
|
83 |
|
|
'media' => 7226,
|
84 |
|
|
);
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
/**
|
88 |
|
|
* Grant existing user access to new media wysiwyg permission.
|
89 |
|
|
*/
|
90 |
|
|
function media_wysiwyg_update_7201() {
|
91 |
|
|
$roles = user_roles(TRUE, 'access media browser');
|
92 |
|
|
foreach ($roles as $rid => $role) {
|
93 |
|
|
user_role_grant_permissions($rid, array('use media wysiwyg'));
|
94 |
|
|
}
|
95 |
|
|
|
96 |
|
|
return t('Use Media WYSIWYG permission was granted to: @roles.', array(
|
97 |
|
|
'@roles' => check_plain(implode(', ', $roles)),
|
98 |
|
|
));
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
/**
|
102 |
|
|
* Use the legacy file entity rendering method for existing sites.
|
103 |
|
|
*
|
104 |
|
|
* Existing sites can change this setting at admin/config/media/browser.
|
105 |
|
|
*/
|
106 |
|
|
function media_wysiwyg_update_7202() {
|
107 |
|
|
variable_set('media_wysiwyg_default_render', 'field_attach');
|
108 |
|
|
}
|
109 |
0ccfec7f
|
Assos Assos
|
|
110 |
|
|
/**
|
111 |
|
|
* Move integration with the stand-alone CKEditor module into the Media CKEditor module.
|
112 |
|
|
*/
|
113 |
|
|
function media_wysiwyg_update_7203() {
|
114 |
|
|
$output = '';
|
115 |
|
|
|
116 |
|
|
if (module_exists('ckeditor')) {
|
117 |
|
|
$output .= t('CKEditor integration has been moved to the Media CKEditor module.');
|
118 |
|
|
$output .= t('If you are using the stand-alone CKEditor module in combination with the CKEditor plugin provided by Media WYSIWYG then you must download and enable the <a href="@url">Media CKEditor</a> module.', array('@url' => 'https://www.drupal.org/project/media_ckeditor'));
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
return $output;
|
122 |
|
|
}
|
123 |
da542b7b
|
Assos Assos
|
/**
|
124 |
|
|
* Whitelists certain fields for WYSIWYG overriding.
|
125 |
|
|
*/
|
126 |
|
|
function media_wysiwyg_update_7204() {
|
127 |
|
|
$instances = field_read_instances(array('entity_type' => 'file'));
|
128 |
|
|
$updated = array();
|
129 |
|
|
$set_to_default = array();
|
130 |
|
|
foreach ($instances as $instance) {
|
131 |
|
|
$field_info = field_info_field($instance['field_name']);
|
132 |
|
|
$allowed_field_types = variable_get('media_wysiwyg_wysiwyg_override_field_types', array('text', 'text_long'));
|
133 |
|
|
if (in_array($field_info['type'], $allowed_field_types)) {
|
134 |
|
|
if (!isset($instance['settings']['wysiwyg_override'])) {
|
135 |
|
|
$instance['settings']['wysiwyg_override'] = 1;
|
136 |
|
|
field_update_instance($instance);
|
137 |
|
|
$set_to_default[] = $instance['field_name'];
|
138 |
|
|
}
|
139 |
|
|
}
|
140 |
|
|
elseif (isset($instance['settings']['wysiwyg_override'])) {
|
141 |
|
|
unset($instance['settings']['wysiwyg_override']);
|
142 |
|
|
field_update_instance($instance);
|
143 |
|
|
$updated[] = $instance['field_name'];
|
144 |
|
|
}
|
145 |
|
|
}
|
146 |
|
|
if (count($updated) || count($set_to_default)) {
|
147 |
|
|
$updated_string = implode(', ', $updated);
|
148 |
|
|
$default_string = implode(', ', $set_to_default);
|
149 |
|
|
return t("Updated the following field instances: @updated_string so they can't be overridden when the file is inserted in the WYSIWYG. Updated the following fields @default_string so that they continue to show up when a file is inserted.", array(
|
150 |
|
|
'@updated_string' => $updated_string,
|
151 |
|
|
'@default_string' => $default_string,
|
152 |
|
|
));
|
153 |
|
|
}
|
154 |
|
|
}
|
155 |
1e39edcb
|
Assos Assos
|
|
156 |
|
|
/**
|
157 |
|
|
* Install {media_restrict_wysiwyg} and {media_view_mode_wysiwyg}.
|
158 |
|
|
*
|
159 |
|
|
* Remove variables media_wysiwyg_view_mode_%.
|
160 |
|
|
*
|
161 |
|
|
* Uninstall media_wysiwyg_view_mode module.
|
162 |
|
|
*/
|
163 |
|
|
function media_wysiwyg_update_7205() {
|
164 |
|
|
$schema = media_wysiwyg_schema();
|
165 |
|
|
|
166 |
|
|
if (!db_table_exists('media_restrict_wysiwyg')) {
|
167 |
|
|
db_create_table('media_restrict_wysiwyg', $schema['media_restrict_wysiwyg']);
|
168 |
|
|
db_create_table('media_view_mode_wysiwyg', $schema['media_view_mode_wysiwyg']);
|
169 |
|
|
}
|
170 |
|
|
|
171 |
|
|
db_delete('variable')->condition('name', "media_wysiwyg_view_mode_%", "LIKE")->execute();
|
172 |
|
|
|
173 |
|
|
// Disable and uninstall View Mode module.Since the view mode module is
|
174 |
|
|
// deleted, this copies from module_disable() and drupal_uninstall_modules().
|
175 |
|
|
// Disable first.
|
176 |
|
|
$module = 'media_wysiwyg_view_mode';
|
177 |
|
|
db_update('system')
|
178 |
|
|
->fields(array('status' => 0))
|
179 |
|
|
->condition('type', 'module')
|
180 |
|
|
->condition('name', $module)
|
181 |
|
|
->execute();
|
182 |
|
|
system_list_reset();
|
183 |
|
|
module_list(TRUE);
|
184 |
|
|
module_implements('', FALSE, TRUE);
|
185 |
|
|
entity_info_cache_clear();
|
186 |
|
|
// Invoke hook_modules_disabled before disabling modules,
|
187 |
|
|
// so we can still call module hooks to get information.
|
188 |
|
|
module_invoke_all('modules_disabled', array($module));
|
189 |
|
|
// Update the registry to remove the newly-disabled module.
|
190 |
|
|
registry_update();
|
191 |
|
|
_system_update_bootstrap_status();
|
192 |
|
|
// Update the theme registry to remove the newly-disabled module.
|
193 |
|
|
drupal_theme_rebuild();
|
194 |
|
|
|
195 |
|
|
// Now uninstall.
|
196 |
|
|
drupal_uninstall_schema($module);
|
197 |
|
|
drupal_set_installed_schema_version($module, SCHEMA_UNINSTALLED);
|
198 |
|
|
|
199 |
|
|
module_invoke_all('modules_uninstalled', array($module));
|
200 |
|
|
} |