function views_handler_field::add_additional_fields

Add 'additional' fields to the query.

Parameters

array $fields: An array of fields. The key is an identifier used to later find the field alias used. The value is either a string in which case it's assumed to be a field on this handler's table; or it's an array in the form of

array(
    'table' => $tablename,
    'field' => $fieldname,
);
16 calls to views_handler_field::add_additional_fields()
views_handler_field::query in handlers/views_handler_field.inc
Called to add the field to a query.
views_handler_field_comment_link::query in modules/comment/views_handler_field_comment_link.inc
Overriden to add the field for the entity id.
views_handler_field_comment_node_link::query in modules/comment/views_handler_field_comment_node_link.inc
Overriden to add the field for the entity id.
views_handler_field_entity::query in handlers/views_handler_field_entity.inc
Overriden to add the field for the entity id.
views_handler_field_field::query in modules/field/views_handler_field_field.inc
Called to add the field to a query.

... See full list

File

handlers/views_handler_field.inc, line 139

Class

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

Code

public function add_additional_fields($fields = NULL) {
    if (!isset($fields)) {
        // Notice check.
        if (empty($this->additional_fields)) {
            return;
        }
        $fields = $this->additional_fields;
    }
    $group_params = array();
    if ($this->options['group_type'] != 'group') {
        $group_params = array(
            'function' => $this->options['group_type'],
        );
    }
    if (!empty($fields) && is_array($fields)) {
        foreach ($fields as $identifier => $info) {
            if (is_array($info)) {
                if (isset($info['table'])) {
                    $table_alias = $this->query
                        ->ensure_table($info['table'], $this->relationship);
                }
                else {
                    $table_alias = $this->table_alias;
                }
                if (empty($table_alias)) {
                    $t_args = array(
                        '@handler' => $this->definition['handler'],
                        '@identifier' => $identifier,
                        '@table' => $info['table'],
                    );
                    debug(t('Handler @handler tried to add additional field @identifier but @table could not be added.', $t_args));
                    $this->aliases[$identifier] = 'broken';
                    continue;
                }
                $params = array();
                if (!empty($info['params'])) {
                    $params = $info['params'];
                }
                $params += $group_params;
                $this->aliases[$identifier] = $this->query
                    ->add_field($table_alias, $info['field'], NULL, $params);
            }
            else {
                $this->aliases[$info] = $this->query
                    ->add_field($this->table_alias, $info, NULL, $group_params);
            }
        }
    }
}