I'm trying to modify the views include file in order to create a view that will list all notes for all nodes that belong to a particular group. Below is the code I created, but it still doesn't seem to be working. Any suggestions?

/**
 * @file
 * Annotate Views support. Declares all the main tables to Views
 * @author Frans Kuipers http://drupal.org/user/103267
 **/

/**
 * Implementation of hook_views_data().
 *
 * @see _annotate_get_visibility_list()
 */
function annotate_views_data() {
  $tables['annotate'] = array(
    'table' => array(
      'group' => t('Annotations'),
      'join' => array(
        'users' => array(
          'table' => 'annotate',
          'left_field' => 'uid',
          'field' => 'uid'
         ),
         'node' => array(
           'table' => 'annotate',
           'left_field' => 'nid',
           'field' => 'nid'
         ),
/**
* I added 'book' here.
*/
         'book' => array(
           'table' => 'annotate',
           'left_field' => 'nid',
           'field' => 'nid'
         ),
        ),
      'base' => array(
        'field' => 'note',
        'title' => t('Annotation'),
        'help' => t('Notes added as annotations to node content.'),
      ),
    ),
    // Fields definitions
    'note' => array(
      'title' => t('Note'),
      'help' => t('The note text for this node'),
      // Information for displaying the note
      'field' => array(
        'handler' => 'annotate_handler_field_note',
        'format' => 'note_format',
      ),
      'extra' => array(
        array('field' => 'uid', 'value' => '***CURRENT_USER***', 'numeric' => TRUE),
      ),

    ),
    'timestamp' => array(
      'title' => t('Post date'),
      'help' => t('Date and time of when the comment was posted.'),
      'field' => array(
        'handler' => 'views_handler_field_date',
        'click sortable' => TRUE,
      ),
      'sort' => array(
        'handler' => 'views_handler_sort_date',
      ),
      'filter' => array(
        'handler' => 'views_handler_filter_date',
      ),
    ),
    'visibility' => array(
      'title' => t('Visibility'),
      'help' => t('Visibility of the note, 0=private, 1=editor, 2=other, 3=collaborators.'),
      'field' => array(
        'handler' => 'annotate_handler_field_visibility',
        'click sortable' => TRUE,
      ),
      'filter' => array(
        'handler' => 'views_handler_filter_in_operator',
        'options callback' => '_annotate_get_visibility_list',
      ),
    ),
/**
* I added 'bid' here.
*/
    'bid' => array(
      'title' => t('Book'),
      'help' => t('The book the note is annotated to.'),
      'relationship' => array(
        'base' => 'book',
        'base field' => 'bid',
        'handler' => 'views_handler_relationship',
        'label' => t('Book'),
      ),
    ),
    'nid' => array(
      'title' => t('Node'),
      'help' => t('The node the note is annotated to.'),
      'relationship' => array(
        'base' => 'node',
        'base field' => 'nid',
        'handler' => 'views_handler_relationship',
        'label' => t('Node'),
      ),
    ),
    'uid' => array(
      'title' => t('User'),
      'help' => t("The User ID of the note's author."),
      'relationship' => array(
        'base' => 'users',
        'base field' => 'uid',
        'handler' => 'views_handler_relationship',
        'label' => t('User'),
      ),
    ),
    'delete_note' => array(
      'real field' => 'uid',
      'title' => t('Delete annotation'),
      'help' => t('Link to delete an annotation.'),
      'field' => array(
        'handler' => 'annotate_handler_field_note_link_delete',
      ),
    ),
    'edit_note' => array(
      'real field' => 'uid',
      'title' => t('Edit annotation'),
      'help' => t('Link to edit an annotation.'),
      'field' => array(
        'handler' => 'annotate_handler_field_note_link_edit',
      ),
    ),
    // uid alias to filter on current user
    'uid_current' => array(
      'real field' => 'uid',
      'title' => t('Current'),
      'help' => t('Filter the view to the currently logged in user.'),
      'filter' => array(
        'handler' => 'views_handler_filter_user_current',
        'type' => 'yes-no',
      ),
    ),
  );

  return $tables;
}

/**
 *  Implementation of hook_views_handlers().
 */
function annotate_views_handlers() {
  return array(
    'info' => array(
      'path' => drupal_get_path('module', 'annotate') . '/views',
    ),
    'handlers' => array(
      // field handler
      'annotate_handler_field_note' => array(
        'parent' => 'views_handler_field'
      ),
      'annotate_handler_field_visibility' => array(
        'parent' => 'views_handler_field'
      ),
      'annotate_handler_field_note_link_delete' => array(
        'parent' => 'views_handler_field'
      ),
      'annotate_handler_field_note_link_edit' => array(
        'parent' => 'views_handler_field'
      ),
    ),
  );
}

Comments

couturier’s picture

Just a quick comment that Views in Drupal 7 is really improved over D6. You might think about trying to upgrade to D7 and working from there to take advantage of all the new features. You might find it easier to succeed with what you're trying to do by taking advantage of all the work that has gone into Views in D7.

clemens.tolboom’s picture

Why modify the views include file? Why not just create a view?

select all notes linked to nodes which belong in group?

somebodysysop’s picture

There does not seem to be a views relationship defined for annotations to get get all notes for all nodes that belong to a specific book.

clemens.tolboom’s picture

Assigned: Unassigned » clemens.tolboom
Category: support » bug

Then that is a bug.

somebodysysop’s picture

Any suggestions for modification of annotate views include file I posted above?

clemens.tolboom’s picture

Component: Code » Miscellaneous
Category: bug » support
Status: Active » Fixed
StatusFileSize
new2.31 KB
new17.64 KB

This is not a bug ... this is about how to define relations with views.

You must think of note - node - book

Edit view all_notes_for_book | Site-Install.png

See attached view export.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.