You are here

function panels_term_context in Panels 5.2

Same name and namespace in other branches
  1. 6.2 arguments/term.inc \panels_term_context()

Discover if this argument gives us the term we crave.

1 string reference to 'panels_term_context'
panels_term_panels_arguments in arguments/term.inc
@file arguments/term.inc

File

arguments/term.inc, line 28
arguments/term.inc

Code

function panels_term_context($arg = NULL, $conf = NULL, $empty = FALSE) {

  // If unset it wants a generic, unfilled context.
  if ($empty) {
    return panels_context_create_empty('term');
  }
  switch ($conf['input_form']) {
    case 'tid':
    default:
      if (!is_numeric($arg)) {
        return FALSE;
      }
      $term = taxonomy_get_term($arg);
      break;
    case 'term':
      $terms = taxonomy_get_term_by_name($arg);
      if (count($terms) != 1) {
        foreach ($terms as $potential) {
          foreach ($conf['vids'] as $vid => $active) {
            if ($active == 1 && $potential->vid == $vid) {
              $term = $potential;

              // break out of the foreaches AND the case
              break 3;
            }
          }
        }
      }
      $term = array_shift($terms);
      break;
  }
  if (empty($term)) {
    return FALSE;
  }
  if (!empty($conf['vids']) && array_filter($conf['vids']) && empty($conf['vids'][$term->vid])) {
    return FALSE;
  }
  return panels_context_create('term', $term);
}