function template_preprocess_views_ui_edit_item

Add information about a section to a display.

File

includes/admin.inc, line 1263

Code

function template_preprocess_views_ui_edit_item(&$vars) {
    $type = $vars['type'];
    $view = $vars['view'];
    $display = $vars['display'];
    $types = views_object_types();
    $vars['overridden'] = FALSE;
    $vars['defaulted'] = FALSE;
    if ($vars['no_fields']) {
        $vars['title'] = $types[$type]['title'];
        $vars['item_help_icon'] = theme('advanced_help_topic', 'views', $type);
        $vars['rearrange'] = NULL;
        $vars['add'] = NULL;
        return;
    }
    // Different types now have different rearrange forms, so we use this switch
    // to get the right one.
    switch ($type) {
        case 'filter':
            $rearrange_url = "admin/build/views/nojs/rearrange-{$type}/{$view->name}/{$display->id}/{$type}";
            break;
        default:
            $rearrange_url = "admin/build/views/nojs/rearrange/{$view->name}/{$display->id}/{$type}";
    }
    $vars['rearrange'] = l('<span>' . t('Rearrange') . '</span>', $rearrange_url, array(
        'attributes' => array(
            'class' => 'views-button-rearrange views-ajax-link',
            'title' => t('Rearrange'),
        ),
        'html' => true,
    ));
    $vars['add'] = l('<span>' . t('Add') . '</span>', "admin/build/views/nojs/add-item/{$view->name}/{$display->id}/{$type}", array(
        'attributes' => array(
            'class' => 'views-button-add views-ajax-link',
            'title' => t('Add'),
        ),
        'html' => true,
    ));
    if (!$display->handler
        ->is_default_display()) {
        if (!$display->handler
            ->is_defaulted($types[$type]['plural'])) {
            $vars['overridden'] = TRUE;
        }
        else {
            $vars['defaulted'] = TRUE;
        }
    }
    if ($display->display_plugin != 'default') {
        $vars['title'] = l($types[$type]['title'], "admin/build/views/nojs/config-type/{$view->name}/{$display->id}/{$type}", array(
            'attributes' => array(
                'class' => 'views-ajax-link',
            ),
        ));
    }
    else {
        $vars['title'] = $types[$type]['title'];
    }
    $fields = array();
    static $relationships = NULL;
    if (!isset($relationships)) {
        // Get relationship labels
        $relationships = array();
        // @todo: get_handlers()
        $handlers = $display->handler
            ->get_option('relationships');
        if ($handlers) {
            foreach ($handlers as $id => $info) {
                $handler = $display->handler
                    ->get_handler('relationship', $id);
                $relationships[$id] = $handler->label();
            }
        }
    }
    // Filters can now be grouped so we do a little bit extra:
    $groups = array();
    $grouping = FALSE;
    if ($type == 'filter') {
        $group_info = $view->display_handler
            ->get_option('filter_groups');
        if (!empty($group_info['groups']) && count($group_info['groups']) > 1) {
            $grouping = TRUE;
            $groups = array(
                0 => array(),
            );
        }
    }
    foreach ($display->handler
        ->get_option($types[$type]['plural']) as $id => $field) {
        $fields[$id] = array();
        $handler = $display->handler
            ->get_handler($type, $id);
        if (empty($handler)) {
            $fields[$id]['class'] = 'broken';
            $field_name = t('Broken/missing handler: @table > @field', array(
                '@table' => $field['table'],
                '@field' => $field['field'],
            ));
            $fields[$id]['title'] = l($field_name, "admin/build/views/nojs/config-item/{$view->name}/{$display->id}/{$type}/{$id}", array(
                'attributes' => array(
                    'class' => 'views-ajax-link',
                ),
                'html' => TRUE,
            ));
            $fields[$id]['info'] = '';
            continue;
        }
        $field_name = $handler->ui_name(TRUE);
        if (!empty($field['relationship']) && !empty($relationships[$field['relationship']])) {
            $field_name = '(' . $relationships[$field['relationship']] . ') ' . $field_name;
        }
        $fields[$id]['title'] = l($field_name, "admin/build/views/nojs/config-item/{$view->name}/{$display->id}/{$type}/{$id}", array(
            'attributes' => array(
                'class' => 'views-ajax-link',
            ),
            'html' => TRUE,
        ));
        $fields[$id]['class'] = views_ui_item_css($display->id . '-' . $type . '-' . $id);
        if (!empty($view->changed_sections[$display->id . '-' . $type . '-' . $id])) {
            $fields[$id]['changed'] = TRUE;
        }
        $fields[$id]['info'] = $handler->admin_summary();
        if ($display->handler
            ->use_group_by() && $handler->use_group_by()) {
            $fields[$id]['links'] = l('<span>' . t('Group settings') . '</span>', "admin/build/views/nojs/config-item-group/{$view->name}/{$display->id}/{$type}/{$id}", array(
                'attributes' => array(
                    'class' => 'views-button-configure views-ajax-link',
                    'title' => t('Group settings'),
                ),
                'html' => true,
            ));
        }
        if ($handler->has_extra_options()) {
            $fields[$id]['links'] = l('<span>' . t('Settings') . '</span>', "admin/build/views/nojs/config-item-extra/{$view->name}/{$display->id}/{$type}/{$id}", array(
                'attributes' => array(
                    'class' => 'views-button-configure views-ajax-link',
                    'title' => t('Settings'),
                ),
                'html' => true,
            ));
        }
        if ($handler->needs_style_plugin()) {
            $style_plugin = views_fetch_plugin_data('style', $handler->options['style_plugin']);
            $style_title = empty($style_plugin['title']) ? t('Missing style plugin') : $style_plugin['title'];
            $pid = $id . '-style-plugin';
            if (!empty($style_plugin['uses options'])) {
                $fields[$pid]['links'] = l('<span>' . t('Change settings for this style') . '</span>', "admin/build/views/nojs/config-style/{$view->name}/{$display->id}/{$type}/{$id}", array(
                    'attributes' => array(
                        'class' => 'views-button-configure views-ajax-link',
                        'title' => t('Settings'),
                    ),
                    'html' => true,
                ));
            }
            $fields[$pid]['title'] = ' ' . t('&nbsp; Style: !style', array(
                '!style' => l($style_title, "admin/build/views/nojs/change-style/{$view->name}/{$display->id}/{$type}/{$id}", array(
                    'attributes' => array(
                        'class' => 'views-ajax-link',
                    ),
                )),
            ));
            $fields[$pid]['class'] = views_ui_item_css($display->id . '-' . $type . '-' . $pid);
            if (!empty($view->changed_sections[$display->id . '-' . $type . '-' . $pid])) {
                $fields[$pid]['changed'] = TRUE;
            }
            $fields[$pid]['info'] = '';
        }
        if ($grouping) {
            $gid = $handler->options['group'];
            // Show in default group if the group does not exist.
            if (empty($group_info['groups'][$gid])) {
                $gid = 0;
            }
            $groups[$gid][] = $id;
        }
    }
    // If using grouping, re-order fields so that they show up properly in the list.
    if ($type == 'filter' && $grouping) {
        $store = $fields;
        $fields = array();
        foreach ($groups as $gid => $contents) {
            if (!empty($fields)) {
                $operator = ') ' . ($group_info['operator'] == 'OR' ? t('OR') : t('AND')) . ' (';
            }
            else {
                $operator = '(';
            }
            $fields[] = array(
                'class' => 'views-group-text',
                'title' => $operator,
                'info' => '',
            );
            $started = FALSE;
            foreach ($contents as $pid) {
                $operator = '&nbsp;&nbsp;';
                if ($started) {
                    $operator .= ($group_info['groups'][$gid] == 'OR' ? t('OR') : t('AND')) . ' ';
                }
                $store[$pid]['title'] = $operator . $store[$pid]['title'];
                $started = TRUE;
                $fields[$pid] = $store[$pid];
            }
        }
        $fields[] = array(
            'class' => 'views-group-text',
            'title' => ')',
            'info' => '',
        );
    }
    $vars['fields'] = $fields;
    $vars['item_help_icon'] = theme('advanced_help_topic', 'views', $type);
}