You are here

function ctools_context_create_terms in Chaos Tool Suite (ctools) 6

Same name and namespace in other branches
  1. 7 plugins/contexts/terms.inc \ctools_context_create_terms()

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

1 string reference to 'ctools_context_create_terms'
terms.inc in plugins/contexts/terms.inc
Plugin to provide a terms context

File

plugins/contexts/terms.inc, line 38
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',
    '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_get_term(current($context->tids));
    }
    $context->data = $data->term;
    $context->title = $data->term->name;
    $context->argument = implode($context->operator == 'or' ? '+' : ',', array_unique($context->tids));
    return $context;
  }
}