Short version: Any interest in adding a filter_node_content_views hook to Views_Attach? If so, I will create patch from the code below.

Details:

I need to have a way to choose between node content views based on a CCK field in the node being displayed. E.g., there is a single "course materials" type that displays related "material" type nodes. A "course materials" node could have a display_type CCK field set to "prework" or "session". If the display_type is set to "prework", the materials are listed by due date and title. If the display_type is set to "session", the materials will be sorted by time slot, presenter, and material (e.g. PPT deck, handouts, and the like).

I could do this with duplicate material types and different nodes, but I want to simplify things for my users.

To solve this, I am planning on doing the following:

Create two different views with node content displays and associate them with the "course materials" type.

Modify the views_attach_nodeapi function to call a "filter_node_content_views" hook with the $node and $&views arguments after the views_attach_get_node_views call is made. This hook can be used by another module to remove views before they are added to the node display.

This will solve my problem and I IMHO add a nice bit of flexibility to this wonderful module. But given the state of it's maintenance, I don't want to do a lot of extra work if no one else is interested.

CommentFileSizeAuthor
#1 views_attach-1132122-1.patch1.77 KBcgmonroe
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cgmonroe’s picture

Assigned: Unassigned » cgmonroe
Status: Active » Needs review
FileSize
1.77 KB

Well, I thought this would take longer and I'd get some feedback before I got finished... but it was fairly trivial. If anyone wants it, the patch is attached below.

Here's a sample hook implementation from my module. This let users select the node content view type to use by setting a CCK field value.

/**
 *  Implement the new views_attach filter_node_content_views hook.
 */
function YourModNameHere_filter_node_content_views( $node, $views ) {

  // Map CCK display field choices to view names.  Each view is has a Node Content display
  // that is attached to the same node type.
  static $formatToView = array (
     'File Listing' => 'Materials_Summary',
     'Presenter Listing' => 'Materials_Presenter_Summary',
     'Day Listing' => 'Materials_Day_Listing',
  );

  // Only care about this type
  if ( $node->type == "material_summary") {

    //field_display_format is CCK field in node
    $format = $node->field_display_format[0]['value'];
    $viewName = $formatToView[$format];

    //Create the exclude views array
    $excludes = array();
    foreach( $views as $v ) {
      if ( $v['name'] != $viewName ) {
        $excludes[$v['name']] = $v['name'];
      }
    }
  }
  return $excludes;
}