function views_handler_field::render_text

Same name in other branches
  1. 6.x-3.x handlers/views_handler_field.inc \views_handler_field::render_text()

Perform an advanced text render for the item.

This is separated out as some fields may render lists, and this allows each item to be handled individually.

1 call to views_handler_field::render_text()
views_handler_field::advanced_render in handlers/views_handler_field.inc
Render a field using advanced settings.

File

handlers/views_handler_field.inc, line 1189

Class

views_handler_field
Base field handler that has no options and renders an unformatted field.

Code

public function render_text($alter) {
    $value = $this->last_render;
    if (!empty($alter['alter_text']) && $alter['text'] !== '') {
        $tokens = $this->get_render_tokens($alter);
        $value = $this->render_altered($alter, $tokens);
    }
    if (!is_null($value) && !empty($this->options['alter']['trim_whitespace'])) {
        $value = trim($value);
    }
    // Check if there should be no further rewrite for empty values.
    $no_rewrite_for_empty = $this->options['hide_alter_empty'] && $this->is_value_empty($this->original_value, $this->options['empty_zero']);
    // Check whether the value is empty and return nothing, so the field isn't
    // rendered. First check whether the field should be hidden if the
    // value(hide_alter_empty = TRUE) /the rewrite is empty (hide_alter_empty =
    // FALSE). For numeric values you can specify whether "0"/0 should be empty.
    if (($this->options['hide_empty'] && empty($value) || $alter['phase'] != VIEWS_HANDLER_RENDER_TEXT_PHASE_EMPTY && $no_rewrite_for_empty) && $this->is_value_empty($value, $this->options['empty_zero'], FALSE)) {
        return '';
    }
    // Only in empty phase.
    if ($alter['phase'] == VIEWS_HANDLER_RENDER_TEXT_PHASE_EMPTY && $no_rewrite_for_empty) {
        // If we got here then $alter contains the value of "No results text"
        // and so there is nothing left to do.
        return $value;
    }
    if (!empty($alter['strip_tags'])) {
        $value = strip_tags($value, $alter['preserve_tags']);
    }
    $suffix = '';
    if (!empty($alter['trim']) && !empty($alter['max_length'])) {
        $length = strlen($value);
        $value = $this->render_trim_text($alter, $value);
        if ($this->options['alter']['more_link'] && strlen($value) < $length) {
            $tokens = $this->get_render_tokens($alter);
            $more_link_text = $this->options['alter']['more_link_text'] ? $this->options['alter']['more_link_text'] : t('more');
            $more_link_text = strtr(filter_xss_admin($more_link_text), $tokens);
            $more_link_path = $this->options['alter']['more_link_path'];
            $more_link_path = strip_tags(decode_entities(strtr($more_link_path, $tokens)));
            // Take sure that paths which was runned through url() does work as
            // well.
            $base_path = base_path();
            // Checks whether the path starts with the base_path.
            if (strpos($more_link_path, $base_path) === 0) {
                $more_link_path = drupal_substr($more_link_path, drupal_strlen($base_path));
            }
            $more_link = l($more_link_text, $more_link_path, array(
                'attributes' => array(
                    'class' => array(
                        'views-more-link',
                    ),
                ),
            ));
            $suffix .= " " . $more_link;
        }
    }
    if (!empty($alter['nl2br'])) {
        $value = nl2br($value);
    }
    $this->last_render_text = $value;
    if (!empty($alter['make_link']) && !empty($alter['path'])) {
        if (!isset($tokens)) {
            $tokens = $this->get_render_tokens($alter);
        }
        $value = $this->render_as_link($alter, $value, $tokens);
    }
    return $value . $suffix;
}