diff --git a/template.php b/template.php index ab5da0f..cec1fe5 100644 --- a/template.php +++ b/template.php @@ -210,7 +210,9 @@ function ember_links__ctools_dropbutton($variables) { */ function ember_views_ui_display_tab_alter(&$build, &$view, $display_id) { $display = $view->display[$display_id]; - $type = 'field'; + $first_column =& $build['details']['columns']['first']; + $third_column =& $build['details']['columns']['third']; + $root_url = "admin/structure/views/nojs/config-item/$view->name/$display_id"; // The below is a straight copy-paste from views_ui_edit_form_get_bucket(). static $relationships = NULL; @@ -227,36 +229,64 @@ function ember_views_ui_display_tab_alter(&$build, &$view, $display_id) { } } - // Custom code begins... - // Get the field details. - foreach ($display->handler->get_option('fields') as $id => $field) { - // Skip path fields, as they are special. - if ($id == 'path') { - continue; - } - $handler = $display->handler->get_handler('field', $id); - // Split out the title into its components. - // @see views_handler_field::ui_name() - // Add the new field descriptions to the output, replacing the default. - $new_label = "{$handler->definition['group']}: "; - $new_label .= "{$handler->definition['title']} "; - - if (!empty($field['relationship']) && !empty($relationships[$field['relationship']])) { - $new_label .= "{$relationships[$field['relationship']]}"; + // Custom code begins. + // Set up references to form elements, so we can replace the links. + $types = array(); + $types['field'] =& $first_column['fields']['fields']; + $types['argument'] =& $third_column['collapse']['arguments']['fields']; + $types['relationship'] =& $third_column['collapse']['relationships']['fields']; + + // For each type of field which may have a description, alter the link text. + foreach ($types as $type => $column) { + foreach ($display->handler->get_option("{$type}s") as $id => $field) { + $handler = $display->handler->get_handler($type, $id); + $column[$id]['#link'] = _ember_views_ui_field_link($field, $handler, $relationships, $type, $root_url); } + } - // Reuse some code from the parent function to build up the link again. - $description = filter_xss_admin($handler->admin_summary()); - $link_text = $new_label . (empty($description) ? '' : "($description)"); +} - $link_attributes = array('class' => array('views-ajax-link')); - if (!empty($field['exclude'])) { - $link_attributes['class'][] = 'views-field-excluded'; - } +/** + * Generate a field description and link for the Views UI. + * + * @param object $field + * The field we wish to edit output for. + * @param object $handler + * The field handler (a views API component). + * @param array $relationships + * An array of relationships, in the format field_id=>relationship name. + * @param string $type + * The type of field, either field, argument, or relationship. + * @param string $root_url + * The root url to the Views AJAX interface. This function suffixes it. + * + * @return string + * An a tag with HTML inside which splits the link text into components. + */ +function _ember_views_ui_field_link($field, $handler, array $relationships, $type, $root_url) { + // Split out the title into its components. + // @see views_handler_field::ui_name() + // Add the new field descriptions to the output, replacing the default. + $new_label = "ALTJ {$handler->definition['group']}: "; + $new_label .= "{$handler->definition['title']} "; - $build['details']['columns']['first']['fields']['fields'][$id]['#link'] - = l($link_text, - "admin/structure/views/nojs/config-item/$view->name/$display->id/$type/$id", - array('attributes' => $link_attributes, 'html' => TRUE)); + if (!empty($field['relationship']) && !empty($relationships[$field['relationship']])) { + $new_label .= "{$relationships[$field['relationship']]}"; } + + // Reuse some code from the parent function to build up the link again. + $description = filter_xss_admin($handler->admin_summary()); + $link_text = $new_label . (empty($description) ? '' : "($description)"); + + $link_text = "
{$link_text}
"; + + $link_attributes = array('class' => array('views-ajax-link')); + if (!empty($field['exclude'])) { + $link_attributes['class'][] = 'views-field-excluded'; + } + + return l($link_text, + "$root_url/$type/{$handler->field}", + array('attributes' => $link_attributes, 'html' => TRUE) + ); }