? 915622.views_header_nodes.view-machine-name-base.patch
Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views_header_nodes/Attic/README.txt,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 README.txt
--- README.txt	24 Jul 2010 07:08:18 -0000	1.1.2.1
+++ README.txt	18 Sep 2010 14:42:29 -0000
@@ -1,10 +1,24 @@
 // $Id: README.txt,v 1.1.2.1 2010/07/24 07:08:18 joachim Exp $
 
 Installation and usage
+======================
 
 1. Install the module as usual.
 2. Add a display to your view of type 'Header node'.
 3. Under "Attachment settings" set the header node display to attach to whichever displays you want the header node to appear on.
-3. Create the node at [view path]/header. You may change the 'header' path suffix in the attachment options.
+3. Create the node at [view path]/header.
 
 If you have Prepopulate module installed, you will see a link in the header to create the node with the path automatically set.
+
+Options
+=======
+
+You can set how to determine both the base and the suffix of the path of a header node in the attachment options.
+
+There are two options for the base path:
+
+- View name: This takes the machine name of the view, eg 'frontpage'. Use this if you want the same header node for all your view's displays.
+- Display path: This takes the actual path of the current page display of the view, including arguments given in the URL.
+
+You may change the 'header' path suffix to any string.
+
Index: views_header_nodes_plugin_attachment_header_node.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views_header_nodes/views_header_nodes_plugin_attachment_header_node.inc,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 views_header_nodes_plugin_attachment_header_node.inc
--- views_header_nodes_plugin_attachment_header_node.inc	24 Jul 2010 07:03:00 -0000	1.1.2.2
+++ views_header_nodes_plugin_attachment_header_node.inc	18 Sep 2010 14:42:30 -0000
@@ -28,6 +28,19 @@ class views_header_nodes_plugin_attachme
     // It is very important to call the parent function here:
     parent::options_summary($categories, $options);
 
+    switch ($this->get_option('path_base_type')) {
+      case 'display_path':
+        $base_path_summary = t('Display path');
+        break;
+      case 'view_name':
+        $base_path_summary = t('View name');
+        break;
+    }
+    $options['path_base_type'] = array(
+      'category' => 'attachment',
+      'title' => t('Path base'),
+      'value' => $base_path_summary,
+    );
     $options['path_suffix'] = array(
       'category' => 'attachment',
       'title' => t('Path suffix'),
@@ -38,6 +51,7 @@ class views_header_nodes_plugin_attachme
   function option_definition () {
     $options = parent::option_definition();
 
+    $options['path_base_type'] = array('default' => 'display_path');
     $options['path_suffix'] = array('default' => 'header');
 
     return $options;
@@ -51,11 +65,22 @@ class views_header_nodes_plugin_attachme
     parent::options_form($form, $form_state);
 
     switch ($form_state['section']) {
+      case 'path_base_type':
+        $form['#title'] .= t('Path base');
+        $form['path_base_type'] = array(
+          '#type' => 'radios',
+          '#description' => t('The base to use to form the node path.'),
+          '#default_value' => $this->get_option('path_base_type'),
+          '#options' => array(
+            'display_path'  => t('Display: The path of each display'),
+            'view_name'     => t('View: The machine name of the view'),
+            ),
+        );
+        break;
       case 'path_suffix':
-        $form['#title'] .= t('path_suffix');
+        $form['#title'] .= t('Path suffix');
         $form['path_suffix'] = array(
           '#type' => 'textfield',
-          '#title' => t('Path suffix'),
           '#description' => t('The suffix to add to the view path to form the node path.'),
           '#default_value' => $this->get_option('path_suffix'),
         );
@@ -71,6 +96,9 @@ class views_header_nodes_plugin_attachme
     // It is very important to call the parent function here:
     parent::options_submit($form, $form_state);
     switch ($form_state['section']) {
+      case 'path_base_type':
+        $this->set_option($form_state['section'], $form_state['values'][$form_state['section']]);
+        break;
       case 'path_suffix':
         $this->set_option($form_state['section'], $form_state['values'][$form_state['section']]);
         break;
@@ -96,27 +124,28 @@ class views_header_nodes_plugin_attachme
         break;
     }
   }  
-  
+
   /**
-   * Get the content to show as this view's header.
+   * Helper function to get the path of the required node.
    */
-  function get_header_content() {
-    // We want not the user-entered path, as that may have %
-    // and not the actual URL, as that may have arguments we don't care about
-    // What we want is the base URL, that is, the part of the path that
-    // is compulsory.
-    // In other words, we want the user-entered path with the % pieces replaced
-    // with current arguments.
-        
-    // Get the user-entered path.
-    $view_path = $this->get_path();
-    // Get the URL of the curent view, including arguments.
-    $view_url = $this->view->get_url();
-    
-    // Temporary hack: we actually DO want the arguments.
-    //dsm($view_url);
-    $node_path = $view_url . '/' . $this->get_option('path_suffix');
-    //dsm($node_path);
+  function build_node_path() {
+    //dsm($this->view);
+    switch ($this->get_option('path_base_type')) {
+      case 'display_path':
+        // Get the URL of the curent view, including arguments.
+        $base_path = $this->view->get_url();
+        break;
+      case 'view_name':
+        $base_path = $this->view->name;
+        break;
+    }
+    //dsm($base_path);
+
+    $node_path = $base_path . '/' . $this->get_option('path_suffix');
+    
+    return $node_path;
+    
+    // deletia... may have future use.
     
     // Pass just the base path of the view, not the complete current path with arguments.
     /*
@@ -139,6 +168,14 @@ class views_header_nodes_plugin_attachme
     }
     dsm($argument_value_pieces);
     */    
+  } 
+  
+  /**
+   * Get the content to show as this view's header.
+   */
+  function get_header_content() {
+    // Construct the path for the required node.
+    $node_path = $this->build_node_path();
         
     // Retrieve the system path for whatever is at the constructed path.
     $path = drupal_get_normal_path($node_path);
