function views_handler_field::advanced_render

Render a field using advanced settings.

This renders a field normally, then decides if render-as-link and text-replacement rendering is necessary.

File

handlers/views_handler_field.inc, line 1085

Class

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

Code

public function advanced_render($values) {
    // Clean up values from previous render calls.
    if ($this->last_render_index != $this->view->row_index) {
        $this->last_render_text = '';
    }
    if ($this->allow_advanced_render() && method_exists($this, 'render_item')) {
        $raw_items = $this->get_items($values);
        // If there are no items, set the original value to NULL.
        if (empty($raw_items)) {
            $this->original_value = NULL;
        }
    }
    else {
        $value = $this->render($values);
        if (is_array($value)) {
            $value = drupal_render($value);
        }
        $this->last_render = $value;
        $this->original_value = $value;
    }
    if ($this->allow_advanced_render()) {
        if (method_exists($this, 'render_item')) {
            $items = array();
            foreach ($raw_items as $count => $item) {
                $value = $this->render_item($count, $item);
                if (is_array($value)) {
                    $value = drupal_render($value);
                }
                $this->last_render = $value;
                $this->original_value = $this->last_render;
                $alter = $item + $this->options['alter'];
                $alter['phase'] = VIEWS_HANDLER_RENDER_TEXT_PHASE_SINGLE_ITEM;
                $items[] = $this->render_text($alter);
            }
            $value = $this->render_items($items);
        }
        else {
            $alter = array(
                'phase' => VIEWS_HANDLER_RENDER_TEXT_PHASE_COMPLETELY,
            ) + $this->options['alter'];
            $value = $this->render_text($alter);
        }
        if (is_array($value)) {
            $value = drupal_render($value);
        }
        // This happens here so that render_as_link can get the unaltered value of
        // this field as a token rather than the altered value.
        $this->last_render = $value;
    }
    if (empty($this->last_render)) {
        if ($this->is_value_empty($this->last_render, $this->options['empty_zero'], FALSE)) {
            $alter = $this->options['alter'];
            $alter['alter_text'] = 1;
            $alter['text'] = $this->options['empty'];
            $alter['phase'] = VIEWS_HANDLER_RENDER_TEXT_PHASE_EMPTY;
            $this->last_render = $this->render_text($alter);
        }
    }
    // If we rendered something, update the last render index.
    if ((string) $this->last_render !== '') {
        $this->last_render_index = $this->view->row_index;
    }
    return $this->last_render;
}