context_condition_taxonomy_term.inc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Expose term views/term forms by vocabulary as a context condition.
  4. */
  5. class context_condition_taxonomy_term extends context_condition {
  6. function condition_values() {
  7. $values = array();
  8. foreach (taxonomy_get_vocabularies() as $vocab) {
  9. $values[$vocab->machine_name] = check_plain($vocab->name);
  10. }
  11. return $values;
  12. }
  13. function options_form($context) {
  14. $defaults = $this->fetch_from_context($context, 'options');
  15. return array(
  16. 'term_form' => array(
  17. '#title' => t('Set on term form'),
  18. '#type' => 'select',
  19. '#options' => array(
  20. 0 => t('No'),
  21. 1 => t('Yes'),
  22. 2 => t('Only on term form')
  23. ),
  24. '#description' => t('Set this context on term forms'),
  25. '#default_value' => isset($defaults['term_form']) ? $defaults['term_form'] : TRUE,
  26. ),
  27. );
  28. }
  29. function execute($term, $op) {
  30. foreach ($this->get_contexts($term->vocabulary_machine_name) as $context) {
  31. // Check the node form option.
  32. $options = $this->fetch_from_context($context, 'options');
  33. if ($op === 'form') {
  34. $options = $this->fetch_from_context($context, 'options');
  35. if (!empty($options['term_form']) && in_array($options['term_form'], array(1, 2))) {
  36. $this->condition_met($context, $term->vocabulary_machine_name);
  37. }
  38. }
  39. elseif (empty($options['term_form']) || $options['term_form'] != 2) {
  40. $this->condition_met($context, $term->vocabulary_machine_name);
  41. }
  42. }
  43. }
  44. }