vid.inc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * @file
  4. *
  5. * Plugin to provide an argument handler for a vocabulary id
  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("Vocabulary: ID"),
  13. // keyword to use for %substitution
  14. 'keyword' => 'vocabulary',
  15. 'description' => t('Creates a vocabulary context from a vocabulary ID argument.'),
  16. 'context' => 'ctools_vid_context',
  17. 'placeholder form' => array(
  18. '#type' => 'textfield',
  19. '#description' => t('Enter the vocabulary ID for this argument'),
  20. ),
  21. 'no ui' => TRUE,
  22. );
  23. /**
  24. * Discover if this argument gives us the vocabulary we crave.
  25. */
  26. function ctools_vid_context($arg = NULL, $conf = NULL, $empty = FALSE) {
  27. // If unset it wants a generic, unfilled context.
  28. if ($empty) {
  29. return ctools_context_create_empty('entity:taxonomy_vocabulary');
  30. }
  31. if (!is_numeric($arg)) {
  32. return NULL;
  33. }
  34. $vocabulary = taxonomy_vocabulary_load($arg);
  35. if (!$vocabulary) {
  36. return NULL;
  37. }
  38. return ctools_context_create('vocabulary', $vocabulary);
  39. }