You are here

function views_filterfield::render in Views Filter Field 7

Implements views_handler_field#render().

Overrides views_handler_field::render

File

handlers/views_filterfield.inc, line 89

Class

views_filterfield
Views area form input field handler.

Code

function render($values) {
  $output = array(
    'all',
  );
  $filter = $this
    ->get_filter($this->options['views_filterfield_field']);
  if (!empty($this->view->exposed_input[$filter['expose']['identifier']])) {
    if (is_array($this->view->exposed_input[$filter['expose']['identifier']])) {
      $output = $this->view->exposed_input[$filter['expose']['identifier']];
    }
    else {

      // Turn a single value into an array, so the transform array_walk
      // function works.
      $output = array(
        $this->view->exposed_input[$filter['expose']['identifier']],
      );
    }
  }

  // Lots of create_function() calls next, as array_walk does not generally
  // play nice with internal functions, as it passes too many args. These
  // will simply throw a warning and not work.
  // @see http://php.net/manual/en/function.array-walk.php
  // Transform spaces to dashes.
  if (!empty($options['views_filterfield_transform_dash'])) {
    array_walk($output, create_function('&$val', '$val = strtr($val, array(" " => "-"));'));
  }

  // Transform case as needed by walking the array of values.
  switch ($this->options['views_filterfield_case']) {
    case 1:

      // Lower case.
      array_walk($output, create_function('&$val', '$val = drupal_strtolower($val);'));
      break;
    case 2:

      // Title case.
      array_walk($output, create_function('&$val', '$val = ucwords($val);'));
      break;
    case 3:

      // Upper case.
      array_walk($output, create_function('&$val', '$val = drupal_strtoupper($val);'));
      break;
    case 4:

      // Sentence case.
      array_walk($output, create_function('&$val', '$val = drupal_ucfirst($val);'));
      break;
  }

  // Turn the transformed array values into a delimited string.
  $separator = $this->options['views_filterfield_separator'];
  $output = implode($separator, $output);

  // Do some basic sanity checking. We don't want crazy values, do we?
  return filter_xss($output);
}