1. In context.plugins.inc un-comment lines for "context_condition_node_taxonomy.inc" plugin.

2. Source of context_condition_node_taxonomy.inc. It's harcoded for term reference field "field_product_type".

/**
 * Expose node taxonomy terms as a context condition.
 */
class context_condition_node_taxonomy extends context_condition_node {
  function condition_values() {
    $values = array();
    if (module_exists('taxonomy')) {
      foreach (taxonomy_get_vocabularies() as $vocab) {
        if (empty($vocab->tags)) {
          foreach (taxonomy_get_tree($vocab->vid) as $term) {
            $values[$term->tid] = check_plain($term->name);
          }
        }
      }
    }
    return $values;
  }

  function condition_form($context) {
    $form = parent::condition_form($context);
    $form['#type'] = 'select';
    $form['#size'] = 12;
    $form['#multiple'] = TRUE;
    $form['#values'] = taxonomy_get_vocabularies(); //taxonomy_form_all();
    return $form;
  }

  function execute($node, $op) {
    if ($this->condition_used() && !empty($node->field_product_type)) {
      foreach ($node->field_product_type[$node->language] as $term) {
        foreach ($this->get_contexts($term['tid']) as $context) {
          // Check the node form option.
          if ($op === 'form') {
            $options = $this->fetch_from_context($context, 'options');
            if (!empty($options['node_form'])) {
              $this->condition_met($context, $term['tid']);
            }
          }
          else {
            $this->condition_met($context, $term['tid']);
          }
        }
      }
    }
  }
}

Will try to make more usable UI and to remove harcoded tearm reference.

Comments

fjcalzado@gmail.com’s picture

Would be nice a more user-friendly implementation of this feature.
Thanks for your work

markovucinicbg’s picture

Great idea!

tekante’s picture

Attached is a patch that should check any taxonomy term reference field attached to a node. Also, I was receiving an error when attempting to use taxonomy_get_vocabularies() in the condition form so I implemented the term selection form used in the 6.x-3 version.

tekante’s picture

Status: Active » Needs review
febbraro’s picture

Status: Needs review » Needs work

Initial patch committed. http://drupal.org/cvs?commit=502712

Still needs a reworked unit test.

febbraro’s picture

The test is now in CVS. It is not passing, but how it creates nodes/taxonomy etc are all in place. The condition seems to work when testing on a real site, but the test is not working.

dstol’s picture

sub

febbraro’s picture

Status: Needs work » Closed (fixed)

Taxonomy Node Test is fixed.

Yuri’s picture

disregard this comment - i confirm it works in latest version