Projet

Général

Profil

Paste
Télécharger (1,85 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / plugins / contexts / vocabulary.inc @ e4c061ad

1
<?php
2

    
3
/**
4
 * @file
5
 *
6
 * Plugin to provide a vocabulary context
7
 */
8

    
9
/**
10
 * Plugins are described by creating a $plugin array which will be used
11
 * by the system that includes this file.
12
 */
13
$plugin = array(
14
  'title' => t("Taxonomy vocabulary"),
15
  'description' => t('A single taxonomy vocabulary object.'),
16
  'context' => 'ctools_context_create_vocabulary',
17
  'edit form' => 'ctools_context_vocabulary_settings_form',
18
  'defaults' => array('vid' => ''),
19
  'keyword' => 'vocabulary',
20
  'context name' => 'vocabulary',
21
  // This context is deprecated and should not be usable in the UI.
22
  'no ui' => TRUE,
23
  'no required context ui' => TRUE,
24
  'superceded by' => 'entity:taxonomy_vocabulary',
25
);
26

    
27
/**
28
 * It's important to remember that $conf is optional here, because contexts
29
 * are not always created from the UI.
30
 */
31
function ctools_context_create_vocabulary($empty, $data = NULL, $conf = FALSE) {
32
  $context = new ctools_context('vocabulary');
33
  $context->plugin = 'vocabulary';
34

    
35
  if ($empty) {
36
    return $context;
37
  }
38

    
39
  if ($conf && isset($data['vid'])) {
40
    $data = taxonomy_vocabulary_load($data['vid']);
41
  }
42

    
43
  if (!empty($data)) {
44
    $context->data     = $data;
45
    $context->title    = $data->name;
46
    $context->argument = $data->vid;
47
    return $context;
48
  }
49
}
50

    
51
function ctools_context_vocabulary_settings_form($form, &$form_state) {
52
  $conf = $form_state['conf'];
53

    
54
  $options = array();
55
  foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
56
    $options[$vid] = $vocabulary->name;
57
  }
58

    
59
  $form['vid'] = array(
60
    '#title' => t('Vocabulary'),
61
    '#type' => 'select',
62
    '#options' => $options,
63
    '#default_value' => $conf['vid'],
64
    '#description' => t('Select the vocabulary for this form.'),
65
  );
66

    
67
  return $form;
68
}
69

    
70
function ctools_context_vocabulary_settings_form_submit($form, &$form_state) {
71
  $form_state['conf']['vid'] = $form_state['values']['vid'];
72
}