Projet

Général

Profil

Paste
Télécharger (3,67 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / media / modules / media_wysiwyg / media_wysiwyg.install @ da542b7b

1
<?php
2

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

    
8
/**
9
 * Implements hook_install().
10
 */
11
function media_wysiwyg_install() {
12
  media_wysiwyg_update_7204();
13
}
14

    
15
/**
16
 * Implements hook_uninstall().
17
 */
18
function media_wysiwyg_uninstall() {
19
  // Remove variables.
20
  variable_del('media_wysiwyg_wysiwyg_title');
21
  variable_del('media_wysiwyg_wysiwyg_icon_title');
22
  variable_del('media_wysiwyg_wysiwyg_default_view_mode');
23
  variable_del('media_wysiwyg_wysiwyg_upload_directory');
24
  variable_del('media_wysiwyg_wysiwyg_allowed_types');
25
  variable_del('media_wysiwyg_wysiwyg_allowed_attributes');
26
  variable_del('media_wysiwyg_wysiwyg_browser_plugins');
27
  variable_del('media_wysiwyg_wysiwyg_override_field_types');
28
}
29

    
30
/**
31
 * Implements hook_update_dependencies().
32
 */
33
function media_wysiwyg_update_dependencies() {
34
  // Ensure the "access media browser" permission is granted to users before
35
  // using it to grant the "use media wysiwyg" permission.
36
  $dependencies['media_wysiwyg'][7201] = array(
37
    'media' => 7226,
38
  );
39
}
40

    
41
/**
42
 * Grant existing user access to new media wysiwyg permission.
43
 */
44
function media_wysiwyg_update_7201() {
45
  $roles = user_roles(TRUE, 'access media browser');
46
  foreach ($roles as $rid => $role) {
47
    user_role_grant_permissions($rid, array('use media wysiwyg'));
48
  }
49

    
50
  return t('Use Media WYSIWYG permission was granted to: @roles.', array(
51
    '@roles' => check_plain(implode(', ', $roles)),
52
  ));
53
}
54

    
55
/**
56
 * Use the legacy file entity rendering method for existing sites.
57
 *
58
 * Existing sites can change this setting at admin/config/media/browser.
59
 */
60
function media_wysiwyg_update_7202() {
61
  variable_set('media_wysiwyg_default_render', 'field_attach');
62
}
63

    
64
/**
65
 * Move integration with the stand-alone CKEditor module into the Media CKEditor module.
66
 */
67
function media_wysiwyg_update_7203() {
68
  $output = '';
69

    
70
  if (module_exists('ckeditor')) {
71
    $output .= t('CKEditor integration has been moved to the Media CKEditor module.');
72
    $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'));
73
  }
74

    
75
  return $output;
76
}
77
/**
78
 * Whitelists certain fields for WYSIWYG overriding.
79
 */
80
function media_wysiwyg_update_7204() {
81
  $instances = field_read_instances(array('entity_type' => 'file'));
82
  $updated = array();
83
  $set_to_default = array();
84
  foreach ($instances as $instance) {
85
    $field_info = field_info_field($instance['field_name']);
86
    $allowed_field_types = variable_get('media_wysiwyg_wysiwyg_override_field_types', array('text', 'text_long'));
87
    if (in_array($field_info['type'], $allowed_field_types)) {
88
      if (!isset($instance['settings']['wysiwyg_override'])) {
89
        $instance['settings']['wysiwyg_override'] = 1;
90
        field_update_instance($instance);
91
        $set_to_default[] = $instance['field_name'];
92
      }
93
    }
94
    elseif (isset($instance['settings']['wysiwyg_override'])) {
95
      unset($instance['settings']['wysiwyg_override']);
96
      field_update_instance($instance);
97
      $updated[] = $instance['field_name'];
98
    }
99
  }
100
  if (count($updated) || count($set_to_default)) {
101
    $updated_string = implode(', ', $updated);
102
    $default_string = implode(', ', $set_to_default);
103
    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(
104
      '@updated_string' => $updated_string,
105
      '@default_string' => $default_string,
106
    ));
107
  }
108
}