Projet

Général

Profil

Révision 5721e759

Ajouté par Assos Assos il y a presque 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/token_insert/token_insert.module
16 16
}
17 17

  
18 18
function token_insert_menu() {
19
  
19

  
20 20
  $items['admin/config/content/token_insert'] = array(
21 21
    'title' => 'Token insert',
22 22
    'description' => 'Change the token users can insert.',
......
25 25
    'page arguments' => array('token_insert_settings_form'),
26 26
    'access arguments' => array('administer token insert settings'),
27 27
  );
28
  
28

  
29 29
  return $items;
30 30
}
31 31

  
32
/**
33
 * Implements hook_theme().
34
 */
35
function token_insert_theme() {
36
  $info['token_insert_tree'] = array(
37
    'variables' => array(
38
    ),
39
  );
40

  
41
  return $info;
42
}
43

  
32 44
function token_insert_settings_form($form_state) {
33 45
  $form = array();
34
  $form['tokens'] = array(
35
      '#type' => 'vertical_tabs',
46
  $form['general'] = array(
47
    '#type' => 'fieldset',
48
    '#title' => t('General settings'),
49
    '#description' => t('Configure general token insert settings'),
50
    '#collapsible' => FALSE,
36 51
  );
37
  $form['tokens_per_role'] = array(
38
      '#type' => 'fieldset',
39
      '#title' => t('Token Insert per role'),
40
      '#description' => t('Configure available tokens per user role'),
41
      '#collapsible' => FALSE,
52

  
53
  $form['general']['token_insert_use_tokens_per_role'] = array(
54
    '#type' => 'checkbox',
55
    '#title' => t('Use tokens per role'),
56
    '#default_value' => variable_get('token_insert_use_tokens_per_role', 0),
42 57
  );
43 58

  
44
  $form['tokens_per_role']['token_insert_use_tokens_per_role'] = array(
45
      '#type' => 'checkbox',
46
      '#title' => t('Use tokens per role'),
47
      '#default_value' => variable_get('token_insert_use_tokens_per_role', 0),
59
  $form['general']['token_insert_max_depth'] = array(
60
    '#type' => 'textfield',
61
    '#title' => t('Maximum depth'),
62
    '#default_value' => variable_get('token_insert_max_depth', 1),
63
    '#description' => t('An integer with the maximum number of token levels to recurse'),
64
    '#element_validate' => array('element_validate_integer_positive'),
48 65
  );
49 66

  
50 67
  $roles ['global'] = 'global';
51
  if(variable_get('token_insert_use_tokens_per_role', 0)){
68
  if (variable_get('token_insert_use_tokens_per_role', 0)) {
52 69
    $roles += user_roles(TRUE, 'use token insert');
53 70
  }
54 71
  $all_tokens = token_get_info();
55 72

  
56
  foreach($roles as $rid => $role){
57
    $title = t("Available tokens for $role");
58
    $description = t("Available tokens for users with the '$role' role");
59
    if($rid == 'global'){
73
  foreach ($roles as $rid => $role) {
74
    $title = t("Available tokens for @role", array('@role' => $role));
75
    $description = t("Available tokens for users with the '@role' role", array('@role' => $role));
76
    if ($rid == 'global') {
60 77
      $title = t('Globally available tokens');
61 78
      $description = t('Tokens available for every user');
62 79
    }
......
67 84
      '#collapsible' => TRUE,
68 85
      '#collapsed' => TRUE,
69 86
    );
87
    $form[$rid . '_available_tokens'][$rid . '_tokens'] = array(
88
      '#type' => 'vertical_tabs',
89
    );
70 90
    foreach ($all_tokens['tokens'] as $category => $tokens) {
71

  
72
      $form[$rid . '_available_tokens'][$category] = array(
91
      $form[$rid . '_available_tokens']['tokens'][$category] = array(
73 92
        '#type' => 'fieldset',
74
        '#title' => t($category),
93
        '#title' => t($all_tokens['types'][$category]['name']),
75 94
        '#collapsible' => TRUE,
76 95
        '#collapsed' => TRUE,
96
        '#group' => $rid . '_tokens',
97
        '#description' => t('Select ' . $all_tokens['types'][$category]['name'] . ' tokens available for insertion.'),
77 98
      );
78 99

  
79 100
      $options = array();
80 101
      $defaults = array();
81 102

  
82 103
      foreach ($tokens as $token => $description) {
83
        $options[$token] = $category . ' : [' . $token . '] : ' . t($description['description']);
84
        $defaults[$token] = 0;
104
        $full_token = '[' . $category . ':' . $token . ']';
105
        $options[$full_token] = $category . ' : [' . $token . '] : ' . t($description['description']);
106
        $defaults[$full_token] = 0;
85 107
      }
86 108

  
109
      $form[$rid . '_available_tokens']['tokens'][$category]['token_insert_' . $rid . '_all_tokens_' . $category] = array(
110
        '#type' => 'checkbox',
111
        '#title' => t('All tokens'),
112
        '#default_value' => variable_get('token_insert_' . $rid . '_all_tokens_' . $category, FALSE),
113
        '#description' => t('Make all ' . $all_tokens['types'][$category]['name'] . ' tokens available for insertion.'),
114
      );
87 115

  
88
      $form[$rid . '_available_tokens'][$category]['token_insert_' . $rid . '_used_tokens_' . $category] = array(
116
      $form[$rid . '_available_tokens']['tokens'][$category]['token_insert_' . $rid . '_used_tokens_' . $category] = array(
89 117
        '#type' => 'checkboxes',
90 118
        '#title' => t('Select tokens'),
91 119
        '#default_value' => variable_get('token_insert_' . $rid . '_used_tokens_' . $category, array()),
92 120
        '#options' => $options,
93
        '#description' => t('Select ' . $category . ' tokens available for insert.')
121
        '#states' => array(
122
          'visible' => array(   // action to take.
123
            ':input[name=token_insert_' . $rid . '_all_tokens_' . $category . ']' => array('checked' => FALSE),
124
          ),
125
        ),
126

  
94 127
      );
95 128
    }
96 129
  }
97
  
130

  
98 131
  return system_settings_form($form);
99 132
}
100 133

  
101
function token_insert_help($path, $arg){
102
  if($path == 'admin/help#token_insert'){
134
function token_insert_help($path, $arg) {
135
  if ($path == 'admin/help#token_insert') {
103 136
    $output = <<<EOT
104 137
    <h3>Description</h3>
105 138
    <p>This module allows you to insert tokens into a textarea. It supports both plain text and wysiwyg textareas. The format used for the insert is compatible with Token filter.</p>
......
126 159
  return $output;
127 160
  }
128 161

  
129
}
162
}
163

  
164
function theme_token_insert_tree() {
165
  module_load_include('pages.inc', 'token');
166
  module_load_include('inc', 'token_insert');
167
  $info = token_get_info();
168

  
169
  $options = array(
170
    'flat' => FALSE,
171
    'restricted' => FALSE,
172
    'depth' => variable_get('token_insert_max_depth', 1) <= 0 ? 1 : variable_get('token_insert_max_depth', 1),
173
  );
174
  $tokens = token_insert_get_tokens(TRUE);
175
  foreach (token_insert_get_allowed_token_types() as $token_type) {
176
    $row = _token_token_tree_format_row($token_type, $info['types'][$token_type], TRUE);
177
    unset($row['data']['value']);
178
    $rows[] = $row;
179
    $tree = token_flatten_tree(array_intersect_key(token_build_tree($token_type, $options), $tokens));
180
    foreach ($tree as $token => $token_info) {
181
      if (!isset($token_info['parent'])) {
182
        $token_info['parent'] = $token_type;
183
      }
184
      $row = _token_token_tree_format_row($token, $token_info);
185
      unset($row['data']['value']);
186
      $rows[] = $row;
187
    }
188
  }
189
  $element = array(
190
    '#theme' => 'tree_table',
191
    '#header' => array(
192
      t('Name'),
193
      t('Token'),
194
      t('Description'),
195
    ),
196
    '#rows' => $rows,
197
    '#attributes' => array('class' => array('token-tree', 'token-insert-table')),
198
    '#empty' => t('No tokens available'),
199
    '#attached' => array(
200
      'js' => array(drupal_get_path('module', 'token') . '/token.js'),
201
      'css' => array(drupal_get_path('module', 'token') . '/token.css'),
202
      'library' => array(array('token', 'treeTable')),
203
    ),
204
    '#caption' => t('Click a token to insert it into the field.'),
205
    '#click_insert' => FALSE,
206
  );
207
  $output = drupal_render($element);
208
  return $output;
209
}

Formats disponibles : Unified diff