context_condition_node.inc

  1. cis7 sites/all/modules/ulmus/context/plugins/context_condition_node.inc
  2. cle7 sites/all/modules/ulmus/context/plugins/context_condition_node.inc
  3. ecd7 sites/all/modules/ulmus/context/plugins/context_condition_node.inc
  4. elmsmedia7 sites/all/modules/ulmus/context/plugins/context_condition_node.inc
  5. harmony7 sites/all/modules/ulmus/context/plugins/context_condition_node.inc
  6. icor7 sites/all/modules/ulmus/context/plugins/context_condition_node.inc
  7. meedjum_blog7 sites/all/modules/ulmus/context/plugins/context_condition_node.inc
  8. mooc7 sites/all/modules/ulmus/context/plugins/context_condition_node.inc

Constants

Namesort descending Description
CONTEXT_NODE_FORM Trigger context on node view and node form.
CONTEXT_NODE_FORM_ONLY Trigger context on node form only.
CONTEXT_NODE_VIEW Trigger context on node view only.

Classes

Namesort descending Description
context_condition_node Expose node views/node forms of specific node types as a context condition.

File

sites/all/modules/ulmus/context/plugins/context_condition_node.inc
View source
  1. <?php
  2. /**
  3. * Trigger context on node view only.
  4. */
  5. define('CONTEXT_NODE_VIEW', 0);
  6. /**
  7. * Trigger context on node view and node form.
  8. */
  9. define('CONTEXT_NODE_FORM', 1);
  10. /**
  11. * Trigger context on node form only.
  12. */
  13. define('CONTEXT_NODE_FORM_ONLY', 2);
  14. /**
  15. * Expose node views/node forms of specific node types as a context condition.
  16. */
  17. class context_condition_node extends context_condition {
  18. function condition_values() {
  19. $values = array();
  20. foreach (node_type_get_types() as $type) {
  21. $values[$type->type] = check_plain($type->name);
  22. }
  23. return $values;
  24. }
  25. function options_form($context) {
  26. $defaults = $this->fetch_from_context($context, 'options');
  27. return array(
  28. 'node_form' => array(
  29. '#title' => t('Set on node form'),
  30. '#type' => 'select',
  31. '#options' => array(
  32. CONTEXT_NODE_VIEW => t('No'),
  33. CONTEXT_NODE_FORM => t('Yes'),
  34. CONTEXT_NODE_FORM_ONLY => t('Only on node form')
  35. ),
  36. '#description' => t('Set this context on node forms'),
  37. '#default_value' => isset($defaults['node_form']) ? $defaults['node_form'] : TRUE,
  38. ),
  39. );
  40. }
  41. function execute($node, $op) {
  42. foreach ($this->get_contexts($node->type) as $context) {
  43. // Check the node form option.
  44. $options = $this->fetch_from_context($context, 'options');
  45. if ($op === 'form') {
  46. $options = $this->fetch_from_context($context, 'options');
  47. if (!empty($options['node_form']) && in_array($options['node_form'], array(CONTEXT_NODE_FORM, CONTEXT_NODE_FORM_ONLY))) {
  48. $this->condition_met($context, $node->type);
  49. }
  50. }
  51. elseif (empty($options['node_form']) || $options['node_form'] != CONTEXT_NODE_FORM_ONLY) {
  52. $this->condition_met($context, $node->type);
  53. }
  54. }
  55. }
  56. }