Projet

Général

Profil

Paste
Télécharger (6,48 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / media / modules / media_wysiwyg / media_wysiwyg.install @ 98df731a

1
<?php
2

    
3
/**
4
 * @file
5
 * Install, update and uninstall functions for the Media WYSIWYG module.
6
 */
7

    
8
 /**
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
/**
55
 * Implements hook_install().
56
 */
57
function media_wysiwyg_install() {
58
  media_wysiwyg_update_7204();
59
}
60

    
61
/**
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
  variable_del('media_wysiwyg_wysiwyg_override_field_types');
74
  variable_del('media_wysiwyg_use_link_text_for_filename');
75
}
76

    
77
/**
78
 * Implements hook_update_dependencies().
79
 */
80
function media_wysiwyg_update_dependencies() {
81
  // Ensure the "access media browser" permission is granted to users before
82
  // using it to grant the "use media wysiwyg" permission.
83
  $dependencies['media_wysiwyg'][7201] = array(
84
    'media' => 7226,
85
  );
86
}
87

    
88
/**
89
 * Grant existing user access to new media wysiwyg permission.
90
 */
91
function media_wysiwyg_update_7201() {
92
  $roles = user_roles(TRUE, 'access media browser');
93
  foreach ($roles as $rid => $role) {
94
    user_role_grant_permissions($rid, array('use media wysiwyg'));
95
  }
96

    
97
  return t('Use Media WYSIWYG permission was granted to: @roles.', array(
98
    '@roles' => check_plain(implode(', ', $roles)),
99
  ));
100
}
101

    
102
/**
103
 * Use the legacy file entity rendering method for existing sites.
104
 *
105
 * Existing sites can change this setting at admin/config/media/browser.
106
 */
107
function media_wysiwyg_update_7202() {
108
  variable_set('media_wysiwyg_default_render', 'field_attach');
109
}
110

    
111
/**
112
 * Move integration with the stand-alone CKEditor module into the Media CKEditor module.
113
 */
114
function media_wysiwyg_update_7203() {
115
  $output = '';
116

    
117
  if (module_exists('ckeditor')) {
118
    $output .= t('CKEditor integration has been moved to the Media CKEditor module.');
119
    $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'));
120
  }
121

    
122
  return $output;
123
}
124
/**
125
 * Whitelists certain fields for WYSIWYG overriding.
126
 */
127
function media_wysiwyg_update_7204() {
128
  $instances = field_read_instances(array('entity_type' => 'file'));
129
  $updated = array();
130
  $set_to_default = array();
131
  foreach ($instances as $instance) {
132
    $field_info = field_info_field($instance['field_name']);
133
    $allowed_field_types = variable_get('media_wysiwyg_wysiwyg_override_field_types', array('text', 'text_long'));
134
    if (in_array($field_info['type'], $allowed_field_types)) {
135
      if (!isset($instance['settings']['wysiwyg_override'])) {
136
        $instance['settings']['wysiwyg_override'] = 1;
137
        field_update_instance($instance);
138
        $set_to_default[] = $instance['field_name'];
139
      }
140
    }
141
    elseif (isset($instance['settings']['wysiwyg_override'])) {
142
      unset($instance['settings']['wysiwyg_override']);
143
      field_update_instance($instance);
144
      $updated[] = $instance['field_name'];
145
    }
146
  }
147
  if (count($updated) || count($set_to_default)) {
148
    $updated_string = implode(', ', $updated);
149
    $default_string = implode(', ', $set_to_default);
150
    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(
151
      '@updated_string' => $updated_string,
152
      '@default_string' => $default_string,
153
    ));
154
  }
155
}
156

    
157
/**
158
 * Install {media_restrict_wysiwyg} and {media_view_mode_wysiwyg}.
159
 *
160
 * Remove variables media_wysiwyg_view_mode_%.
161
 *
162
 * Uninstall media_wysiwyg_view_mode module.
163
 */
164
function media_wysiwyg_update_7205() {
165
  $schema = media_wysiwyg_schema();
166

    
167
  if (!db_table_exists('media_restrict_wysiwyg')) {
168
    db_create_table('media_restrict_wysiwyg',  $schema['media_restrict_wysiwyg']);
169
    db_create_table('media_view_mode_wysiwyg', $schema['media_view_mode_wysiwyg']);
170
  }
171

    
172
  db_delete('variable')->condition('name', "media_wysiwyg_view_mode_%", "LIKE")->execute();
173

    
174
  // Disable and uninstall View Mode module.Since the view mode module is
175
  // deleted, this copies from  module_disable() and drupal_uninstall_modules().
176
  // Disable first.
177
  $module = 'media_wysiwyg_view_mode';
178
  db_update('system')
179
    ->fields(array('status' => 0))
180
    ->condition('type', 'module')
181
    ->condition('name', $module)
182
    ->execute();
183
  system_list_reset();
184
  module_list(TRUE);
185
  module_implements('', FALSE, TRUE);
186
  entity_info_cache_clear();
187
  // Invoke hook_modules_disabled before disabling modules,
188
  // so we can still call module hooks to get information.
189
  module_invoke_all('modules_disabled', array($module));
190
  // Update the registry to remove the newly-disabled module.
191
  registry_update();
192
  _system_update_bootstrap_status();
193
  // Update the theme registry to remove the newly-disabled module.
194
  drupal_theme_rebuild();
195

    
196
  // Now uninstall.
197
  drupal_uninstall_schema($module);
198
  drupal_set_installed_schema_version($module, SCHEMA_UNINSTALLED);
199

    
200
  module_invoke_all('modules_uninstalled', array($module));
201
}