From 127b23584c18e689c581357f3f7c5ae33bee8587 Mon Sep 17 00:00:00 2001
From: Cameron Tod <cameron.tod@gmail.com>
Date: Sat, 21 Feb 2015 00:46:52 +0000
Subject: [PATCH] Added wrappers to different elements of field descriptions in
 the Views UI.

---
 template.php | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/template.php b/template.php
index 3bcf61d..711dfc5 100644
--- a/template.php
+++ b/template.php
@@ -199,3 +199,77 @@ function ember_links__ctools_dropbutton($variables) {
     return '';
   }
 }
+
+/**
+ * Implements hook_views_ui_display_tab_alter().
+ *
+ * This is used to wrap span tags around title components in the Fields section
+ * of the Views Admin UI.
+ *
+ * @see views_ui_edit_form_get_bucket()
+ */
+function ember_views_ui_display_tab_alter(&$build, &$view, $display_id) {
+  $display = $view->display[$display_id];
+  $type = 'field';
+
+  // The below is a straight copy-paste from views_ui_edit_form_get_bucket().
+  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();
+      }
+    }
+  }
+
+  // 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()
+    $entity = $handler->definition['group'];
+    $title = $handler->definition['title'];
+    $relationship = '';
+    if (!empty($field['relationship']) && !empty($relationships[$field['relationship']])) {
+      $relationship = $relationships[$field['relationship']];
+    }
+
+    $field_names[$id] = array(
+      'entity' => $entity,
+      'title' => $title,
+      'relationship' => $relationship,
+    );
+  }
+
+  // Now add the new field descriptions to the output, replacing the default.
+  foreach ($field_names as $id => $labels) {
+    $new_label = "<span class='views-field-entity-type'>{$labels['entity']}:</span> ";
+    $new_label .= "<span class='views-field-title'>{$labels['title']}</span> ";
+    $new_label .= "<span class='views-field-relationship'>{$labels['relationship']}</span>";
+
+    // 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) ? '' : "<span class='views-field-label'>($description)</span>");
+
+    $link_attributes = array('class' => array('views-ajax-link'));
+    if (!empty($field['exclude'])) {
+      $link_attributes['class'][] = 'views-field-excluded';
+    }
+
+    $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));
+  }
+}
-- 
2.3.0

