vocabulary.inc 1.8 KB

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