This is a patch that adds a field Title so users can add an optional title to each view.


--- viewfield.module-orig	2009-07-17 14:35:01.000000000 +0100
+++ viewfield.module	2009-07-17 15:09:44.000000000 +0100
@@ -67,6 +67,7 @@
       return array(
         'vname' => array('type' => 'varchar', 'not null' => FALSE, 'length' => 32),
         'vargs' => array('type' => 'varchar', 'not null' => FALSE, 'length' => 255),
+        'vtitle' => array('type' => 'varchar', 'not null' => FALSE, 'length' => 255),
       );
   }
 }
@@ -79,7 +80,7 @@
     case 'presave':
       foreach ($items as $delta => $item) {
         if ($field['super_default'] && empty($item['override_default']) || $field['widget']['force_default']) {
-          $items[$delta] = array('vname' => NULL, 'vargs' => NULL);
+          $items[$delta] = array('vname' => NULL, 'vargs' => NULL, 'vtitle' => NULL);
         }
         elseif (empty($item['vname'])) {
           unset($items[$delta]);
@@ -183,7 +184,7 @@
   return array(
     'viewfield_select' => array(
       '#input' => TRUE,
-      '#columns' => array('vname', 'vargs'),
+      '#columns' => array('vname', 'vargs', 'vtitle'),
       '#delta' => 0,
       '#process' => array('viewfield_select_process'),
     ),
@@ -211,6 +212,10 @@
       '#type' => 'value',
       '#value' => $element['#default_value']['vargs'], // All views share args (for now).
     );
+    $element['vtitle'] = array(
+      '#type' => 'value',
+      '#value' => $element['#default_value']['vtitle'], // All views share args (for now).
+    );
   }
   else {
     // Display the form to let the user pick a view.
@@ -269,6 +274,17 @@
     if ($token_enabled && ($field_settings || !$field['multiple'])) {
       $element['token_help'] = _viewfield_get_token_help();
     }
+    $element['vtitle'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Title'),
+      '#default_value' => $element['#default_value']['vtitle'],
+      '#required' => FALSE,
+      '#description' => t('Title to display.'),
+      '#field_name' => $element['#field_name'] .' '. t('title'),
+      '#type_name' => 'text',
+      '#delta' => $element['#delta'],
+      '#columns' => $element['#columns'],
+    );
   }
   return $element;
 }
@@ -347,7 +363,7 @@
  * If the super defaults are enabled return them, otherwise return blank values
  */
 function _viewfield_get_super_defaults($field) {
-  return $field['super_default'] ? $field['super_default_widget'] : array('vname' => NULL, 'vargs' => NULL);
+  return $field['super_default'] ? $field['super_default_widget'] : array('vname' => NULL, 'vargs' => NULL, 'vtitle' => NULL);
 }

 /**


second part

--- viewfield.theme.inc-orig	2009-07-17 14:53:18.000000000 +0100
+++ viewfield.theme.inc	2009-07-17 15:13:55.000000000 +0100
@@ -11,7 +11,6 @@
  */
 function theme_viewfield_formatter_default($element) {
   global $_viewfield_stack;
-
   // For safety's sake, we can only display 2 levels of viewfields.
   if (count($_viewfield_stack) <= 2) {
     list($view_name, $display) = explode('|', $element['#item']['vname'], 2);
@@ -28,10 +27,10 @@
     if ($node->nid) {
       _viewfield_nodestack_pop();
     }
-    return $output;
+    return ($element['#item']['vtitle'] ? "<h2 class=\"viewfield-vtitle\">"
+      . $element['#item']['vtitle'] . "</h2>" : "") . $output;
   }
 }
-
 /**
  * Perform argument replacement
  */

Comments

sun’s picture

Status: Patch (to be ported) » Needs review
sun’s picture

Status: Needs review » Needs work

Thanks! Could you provide a proper patch?

keithm’s picture

Status: Needs work » Closed (duplicate)