vocabulary.inc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @file
  4. *
  5. * Plugin to provide a vocabulary context
  6. */
  7. /**
  8. * Plugins are described by creating a $plugin array which will be used
  9. * by the system that includes this file.
  10. */
  11. $plugin = array(
  12. 'title' => t("Taxonomy vocabulary"),
  13. 'description' => t('A single taxonomy vocabulary object.'),
  14. 'context' => 'ctools_context_create_vocabulary',
  15. 'edit form' => 'ctools_context_vocabulary_settings_form',
  16. 'defaults' => array('vid' => ''),
  17. 'keyword' => 'vocabulary',
  18. 'context name' => 'vocabulary',
  19. // This context is deprecated and should not be usable in the UI.
  20. 'no ui' => TRUE,
  21. 'no required context ui' => TRUE,
  22. 'superceded by' => 'entity:taxonomy_vocabulary',
  23. );
  24. /**
  25. * It's important to remember that $conf is optional here, because contexts
  26. * are not always created from the UI.
  27. */
  28. function ctools_context_create_vocabulary($empty, $data = NULL, $conf = FALSE) {
  29. $context = new ctools_context('vocabulary');
  30. $context->plugin = 'vocabulary';
  31. if ($empty) {
  32. return $context;
  33. }
  34. if ($conf && isset($data['vid'])) {
  35. $data = taxonomy_vocabulary_load($data['vid']);
  36. }
  37. if (!empty($data)) {
  38. $context->data = $data;
  39. $context->title = $data->name;
  40. $context->argument = $data->vid;
  41. return $context;
  42. }
  43. }
  44. function ctools_context_vocabulary_settings_form($form, &$form_state) {
  45. $conf = $form_state['conf'];
  46. $options = array();
  47. foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
  48. $options[$vid] = $vocabulary->name;
  49. }
  50. $form['vid'] = array(
  51. '#title' => t('Vocabulary'),
  52. '#type' => 'select',
  53. '#options' => $options,
  54. '#default_value' => $conf['vid'],
  55. '#description' => t('Select the vocabulary for this form.'),
  56. );
  57. return $form;
  58. }
  59. function ctools_context_vocabulary_settings_form_submit($form, &$form_state) {
  60. $form_state['conf']['vid'] = $form_state['values']['vid'];
  61. }