Projet

Général

Profil

Révision 136a805a

Ajouté par Assos Assos il y a plus de 7 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/ctools/term_depth/plugins/access/term_depth.inc
25 25
 * Settings form for the 'term depth' access plugin.
26 26
 */
27 27
function term_depth_term_depth_ctools_access_settings($form, &$form_state, $conf) {
28
  // If no configuration was saved before, set some defaults.
29
  if (empty($conf)) {
30
    $conf = array(
31
      'vid' => 0,
32
    );
33
  }
34
  if (!isset($conf['vid'])) {
35
    $conf['vid'] = 0;
36
  }
37

  
28
  $vocabularies = taxonomy_get_vocabularies();
29
  $options = array();
38 30
  // Loop over each of the configured vocabularies.
39
  foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
40
    $options[$vid] = $vocabulary->name;
31
  foreach ($vocabularies as $vid => $vocab) {
32
    $options[$vocab->machine_name] = $vocab->name;
41 33
  }
42 34

  
43
  $form['settings']['vid'] = array(
35
  _term_depth_convert_config_vid_to_vocabulary_name($conf);
36

  
37
  $form['settings']['vocabulary'] = array(
44 38
    '#title' => t('Vocabulary'),
45 39
    '#type' => 'select',
46 40
    '#options' => $options,
47 41
    '#description' => t('Select the vocabulary for this form. If there exists a parent term in that vocabulary, this access check will succeed.'),
48
    '#id' => 'ctools-select-vid',
49
    '#default_value' => $conf['vid'],
42
    '#id' => 'ctools-select-vocabulary',
43
    '#default_value' => !empty($conf['vocabulary']) ? $conf['vocabulary'] : array(),
50 44
    '#required' => TRUE,
51 45
  );
52 46

  
......
61 55
  return $form;
62 56
}
63 57

  
58
/**
59
 * @param $conf
60
 */
61
function _term_depth_convert_config_vid_to_vocabulary_name(&$conf) {
62
  // Fallback on legacy 'vid', when no vocabularies are available.
63
  if (empty($conf['vocabulary']) && !empty($conf['vid'])) {
64
    $conf['vocabulary'] = reset(_ctools_term_vocabulary_machine_name_convert(array($conf['vid'])));
65
    unset($conf['vid']);
66
  }
67
}
68

  
64 69
/**
65 70
 * Submit function for the access plugins settings.
66 71
 *
67
 * We cast all settings to numbers to ensure they can be safely handled.
68 72
 */
69 73
function term_depth_term_depth_ctools_access_settings_submit($form, $form_state) {
70
  foreach (array('depth', 'vid') as $key) {
71
    $form_state['conf'][$key] = (integer) $form_state['values']['settings'][$key];
72
  }
74
  $form_state['conf']['depth'] = (integer) $form_state['values']['settings']['depth'];
75
  $form_state['conf']['vocabulary'] = array_filter($form_state['conf']['vocabulary']);
73 76
}
74 77

  
75 78
/**
......
82 85
    return FALSE;
83 86
  }
84 87

  
85
  // Get the $vid.
86
  if (!isset($conf['vid'])) {
88
  _term_depth_convert_config_vid_to_vocabulary_name($conf);
89

  
90
  // Get the $vocabulary.
91
  if (!isset($conf['vocabulary'])) {
87 92
    return FALSE;
88 93
  }
94
  $vocab = taxonomy_vocabulary_machine_name_load($conf['vocabulary']);
95
  if ($vocab->vid != $context->data->vid) {
96
    return FALSE;
97
  }
98

  
89 99
  $depth = _term_depth($context->data->tid);
90 100

  
91 101
  return ($depth == $conf['depth']);
......
95 105
 * Provide a summary description based upon the checked terms.
96 106
 */
97 107
function term_depth_term_depth_ctools_access_summary($conf, $context) {
98
  $vocab = taxonomy_vocabulary_load($conf['vid']);
99

  
100
  return t('"@term" has parent in vocabulary "@vocab" at @depth', array(
108
  _term_depth_convert_config_vid_to_vocabulary_name($conf);
109
  $vocab = taxonomy_vocabulary_machine_name_load($conf['vocabulary']);
110
  return t('"@term" is in vocabulary "@vocab" at depth @depth', array(
101 111
    '@term' => $context->identifier,
102 112
    '@vocab' => $vocab->name,
103 113
    '@depth' => $conf['depth'],

Formats disponibles : Unified diff