vid.inc 1.1 KB

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