ctools_context_create_terms

  1. drupal
    1. 6 terms.inc function
    2. 7 terms.inc function
Drupal 7 ctools_context_create_terms($empty, $data = NULL, $conf = FALSE)

It's important to remember that $conf is optional here, because contexts are not always created from the UI.

File

sites/all/modules/ctools/plugins/contexts/terms.inc, line 37
Plugin to provide a terms context

Code

function ctools_context_create_terms($empty, $data = NULL, $conf = FALSE) {
  // The input is expected to be an object as created by ctools_break_phrase
  // which contains a group of terms.

  $context = new ctools_context(array('terms', 'entity:taxonomy_term'));
  $context->plugin = 'terms';

  if ($empty) {
    return $context;
  }

  if (!empty($data) && is_object($data)) {
    $context->operator = $data->operator;
    $context->tids     = $data->value;
    if (!isset($data->term)) {
      // load the first term:
      reset($context->tids);
      $data->term = taxonomy_term_load(current($context->tids));
    }
    $context->data     = $data->term;
    $context->title    = $data->term->name;
    $context->argument = implode($context->operator == 'or' ? '+' : ',', array_unique($context->tids));
    return $context;
  }
}