You are here

public static function EntityFieldHandlerHelper::render_list in Entity API 7

Render a list of values.

Parameters

$handler: The field handler whose field is rendered.

$list: The list of values to render.

$values: The values for the current row retrieved from the Views query, as an object.

Return value

string The rendered value for the given list.

1 call to EntityFieldHandlerHelper::render_list()
EntityFieldHandlerHelper::render in views/handlers/entity_views_field_handler_helper.inc
Render the field.

File

views/handlers/entity_views_field_handler_helper.inc, line 427
Contains the EntityFieldHandlerHelper class.

Class

EntityFieldHandlerHelper
Helper class containing static implementations of common field handler methods.

Code

public static function render_list($handler, $list, $values) {

  // Allow easy overriding of this behaviour in the specific field handler.
  if (method_exists($handler, 'render_list')) {
    return $handler
      ->render_list($list, $values);
  }
  $mode = isset($handler->options['list']['mode']) ? $handler->options['list']['mode'] : NULL;
  switch ($mode) {
    case 'first':
      $list = count($list) ? array_shift($list) : NULL;
      if (is_array($list)) {
        return self::render_list($handler, $list, $values);
      }
      elseif (isset($list)) {
        return self::render_entity_link($handler, $list, $values);
      }
      return NULL;
    case 'count':
      return count($list);

    // Handles both collapse and list output. Fallback is to collapse.
    default:
      $inner_values = array();
      foreach ($list as $value) {
        $value = is_array($value) ? self::render_list($handler, $value, $values) : self::render_entity_link($handler, $value, $values);
        if ($value) {
          $inner_values[] = $value;
        }
      }

      // Format output as list.
      if ($mode == 'list') {
        $type = isset($handler->options['list']['type']) ? $handler->options['list']['type'] : 'ul';
        return theme('item_list', array(
          'items' => $inner_values,
          'type' => $type,
        ));
      }
      $separator = isset($handler->options['list']['separator']) ? $handler->options['list']['separator'] : ', ';
      return implode($separator, $inner_values);
  }
}