Newer
Older
// $Id$
Earl Miles
committed
/**
* @file
* Provide views data and handlers for node.module
*/
/**
* @defgroup views_node_module node.module handlers
*
* Includes the tables 'node', 'node_revisions' and 'history'.
* @{
*/
/**
* Implementation of hook_views_data()
Earl Miles
committed
*/
Earl Miles
committed
// ----------------------------------------------------------------
// node table -- basic table information.
// Define the base group of this table. Fields that don't
// have a group defined will go into this field by default.
$data['node']['table']['group'] = t('Node');
// Advertise this table as a possible base table
$data['node']['table']['base'] = array(
'field' => 'nid',
'title' => t('Node'),
'help' => t("Nodes are a Drupal site's primary content."),
Earl Miles
committed
'weight' => -10,
);
// For other base tables, explain how we join
$data['node']['table']['join'] = array(
Earl Miles
committed
// this explains how the 'node' table (named in the line above)
// links toward the node_revisions table.
'node_revisions' => array(
'handler' => 'views_join', // this is actually optional
'left_table' => 'node_revisions', // Because this is a direct link it could be left out.
'left_field' => 'nid',
'field' => 'nid',
Earl Miles
committed
// also supported:
// 'type' => 'INNER',
Earl Miles
committed
// 'extra' => array(array('field' => 'fieldname', 'value' => 'value', 'operator' => '='))
// Unfortunately, you can't specify other tables here, but you can construct
// alternative joins in the handlers that can do that.
Earl Miles
committed
// 'table' => 'the actual name of this table in the database',
),
);
// ----------------------------------------------------------------
Earl Miles
committed
// node table -- fields
Earl Miles
committed
// nid
$data['node']['nid'] = array(
'title' => t('Nid'),
'help' => t('The node ID of the node.'), // The help that appears on the UI,
// Information for displaying the nid
'field' => array(
'handler' => 'views_handler_field_node',
Earl Miles
committed
'click sortable' => TRUE,
// Information for accepting a nid as an argument
'handler' => 'views_handler_argument_node_nid',
Earl Miles
committed
'parent' => 'views_handler_argument_numeric', // make sure parent is included
'name field' => 'title', // the field to display in the summary.
Earl Miles
committed
'numeric' => TRUE,
'validate type' => 'nid',
// Information for accepting a nid as a filter
Earl Miles
committed
'handler' => 'views_handler_filter_numeric',
// Information for sorting on a nid.
'sort' => array(
'handler' => 'views_handler_sort',
),
Earl Miles
committed
// title
// This definition has more items in it than it needs to as an example.
$data['node']['title'] = array(
'title' => t('Title'), // The item it appears as on the UI,
'help' => t('The title of the node.'), // The help that appears on the UI,
// Information for displaying a title as a field
'field' => array(
'field' => 'title', // the real field. This could be left out since it is the same.
'group' => t('Node'), // The group it appears in on the UI. Could be left out.
'handler' => 'views_handler_field_node',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
// Information for accepting a title as a filter
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
$data['node']['created'] = array(
'title' => t('Post date'), // The item it appears as on the UI,
'help' => t('The date the node was posted.'), // The help that appears on the UI,
'field' => array(
'handler' => 'views_handler_field_date',
Earl Miles
committed
'click sortable' => TRUE,
),
'sort' => array(
Earl Miles
committed
'filter' => array(
'handler' => 'views_handler_filter_date',
),
$data['node']['changed'] = array(
'title' => t('Updated date'), // The item it appears as on the UI,
'help' => t('The date the node was last updated.'), // The help that appears on the UI,
'field' => array(
'handler' => 'views_handler_field_date',
Earl Miles
committed
'click sortable' => TRUE,
Earl Miles
committed
'sort' => array(
Earl Miles
committed
),
Earl Miles
committed
'filter' => array(
'handler' => 'views_handler_filter_date',
),
// Node type
$data['node']['type'] = array(
'title' => t('Type'), // The item it appears as on the UI,
'help' => t('The type of a node (for example, "blog entry", "forum post", "story", etc).'), // The help that appears on the UI,
'field' => array(
'handler' => 'views_handler_field_node_type',
Earl Miles
committed
'click sortable' => TRUE,
'sort' => array(
'handler' => 'views_handler_sort',
),
Earl Miles
committed
'filter' => array(
'handler' => 'views_handler_filter_node_type',
'argument' => array(
'handler' => 'views_handler_argument_node_type',
),
);
// published status
$data['node']['status'] = array(
'title' => t('Published'),
'help' => t('The published status of the node.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
Earl Miles
committed
'click sortable' => TRUE,
Earl Miles
committed
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Published'),
),
'sort' => array(
'handler' => 'views_handler_sort',
),
// published status + extra
$data['node']['status_extra'] = array(
'title' => t('Published or admin'),
'help' => t('Filters out unpublished nodes if the current user cannot view them.'),
'filter' => array(
'field' => 'status',
'handler' => 'views_handler_filter_node_status',
'label' => t('Published'),
),
);
// promote status
$data['node']['promote'] = array(
'title' => t('Promoted to front page'),
'help' => t('The front page of the node.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
Earl Miles
committed
'click sortable' => TRUE,
Earl Miles
committed
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Promoted to front page'),
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// moderate
$data['node']['moderate'] = array(
'title' => t('Moderated'), // The item it appears as on the UI,
'help' => t('Whether or not the node is moderated.'), // The help that appears on the UI,
// Information for displaying a title as a field
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Moderated'),
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// sticky
$data['node']['sticky'] = array(
'title' => t('Sticky'), // The item it appears as on the UI,
'help' => t('Whether or not the node is sticky.'), // The help that appears on the UI,
// Information for displaying a title as a field
'field' => array(
'handler' => 'views_handler_field_boolean',
Earl Miles
committed
'click sortable' => TRUE,
Earl Miles
committed
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Sticky'),
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
Earl Miles
committed
// links to operate on the node
$data['node']['view_node'] = array(
'field' => array(
'help' => t('Provide a simple link to the node.'),
'handler' => 'views_handler_field_node_link',
),
);
$data['node']['edit_node'] = array(
'field' => array(
'title' => t('Edit link'),
'help' => t('Provide a simple link to edit the node.'),
'handler' => 'views_handler_field_node_link_edit',
),
);
$data['node']['delete_node'] = array(
'field' => array(
'title' => t('Delete link'),
'help' => t('Provide a simple link to delete the node.'),
'handler' => 'views_handler_field_node_link_delete',
),
);
$data['node']['created_fulldate'] = array(
'title' => t('Created date'),
'help' => t('In the form of CCYYMMDD.'),
'argument' => array(
'field' => 'created',
'handler' => 'views_handler_argument_node_created_fulldate',
),
);
$data['node']['created_year_month'] = array(
'title' => t('Created year + month'),
'help' => t('In the form of YYYYMM.'),
Earl Miles
committed
'handler' => 'views_handler_argument_node_created_year_month',
),
);
$data['node']['created_year'] = array(
'title' => t('Created year'),
'help' => t('In the form of YYYY.'),
Earl Miles
committed
'handler' => 'views_handler_argument_node_created_year',
),
);
$data['node']['created_month'] = array(
'title' => t('Created month'),
'help' => t('In the form of MM (01 - 12).'),
Earl Miles
committed
'handler' => 'views_handler_argument_node_created_month',
$data['node']['created_day'] = array(
'title' => t('Created day'),
'help' => t('In the form of DD (01 - 31).'),
'argument' => array(
'field' => 'created',
'handler' => 'views_handler_argument_node_created_day',
),
);
$data['node']['created_week'] = array(
'title' => t('Created week'),
'help' => t('In the form of WW (01 - 53).'),
'argument' => array(
'field' => 'created',
'handler' => 'views_handler_argument_node_created_week',
),
);
// ----------------------------------------------------------------------
// Node revisions table
// Define the base group of this table. Fields that don't
// have a group defined will go into this field by default.
$data['node_revisions']['table']['group'] = t('Node revision');
// Advertise this table as a possible base table
$data['node_revisions']['table']['base'] = array(
'field' => 'vid',
Earl Miles
committed
'title' => t('Node revision'),
'help' => t('Node revisions are a history of changes to nodes.'),
);
// For other base tables, explain how we join
$data['node_revisions']['table']['join'] = array(
Earl Miles
committed
// Directly links to node table.
'node' => array(
Earl Miles
committed
'left_field' => 'vid',
'field' => 'vid',
),
);
// uid field
$data['node_revisions']['uid'] = array(
'title' => t('User'),
'help' => t('Relate a node revision to the user who created the revision.'),
'relationship' => array(
'handler' => 'views_handler_relationship',
'base' => 'users',
'field' => 'uid',
'label' => t('user'),
Earl Miles
committed
),
);
// Body field
$data['node_revisions']['body'] = array(
'title' => t('Body'), // The item it appears as on the UI,
'help' => t('The actual, full data in the body field; this may not be valid data on all node types.'), // The help that appears on the UI,
// Information for displaying a title as a field
'field' => array(
'handler' => 'views_handler_field_markup',
Earl Miles
committed
'format' => 'format', // The name of the format field
Earl Miles
committed
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
// Teaser field
$data['node_revisions']['teaser'] = array(
'title' => t('Teaser'), // The item it appears as on the UI,
'help' => t('The stored teaser field. This may not be valid or useful data on all node types.'), // The help that appears on the UI,
// Information for displaying a title as a field
'field' => array(
'handler' => 'views_handler_field_markup',
Earl Miles
committed
'format' => 'format', // The name of the format field
Earl Miles
committed
'filter' => array(
'handler' => 'views_handler_filter_string',
),
Earl Miles
committed
// nid
$data['node_revisions']['vid'] = array(
'title' => t('Vid'),
'help' => t('The revision ID of the node revision.'), // The help that appears on the UI,
// Information for displaying the nid
'field' => array(
// 'handler' => 'views_handler_field',
Earl Miles
committed
'click sortable' => TRUE,
),
// Information for accepting a nid as an argument
'argument' => array(
'handler' => 'views_handler_argument_node_vid',
Earl Miles
committed
'parent' => 'views_handler_argument_numeric', // make sure parent is included
Earl Miles
committed
'click sortable' => TRUE,
Earl Miles
committed
'numeric' => TRUE,
Earl Miles
committed
),
// Information for accepting a nid as a filter
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
// Information for sorting on a nid.
'sort' => array(
'handler' => 'views_handler_sort',
),
);
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
// title
$data['node_revisions']['title'] = array(
'title' => t('Title'), // The item it appears as on the UI,
'help' => t('The title of the node.'), // The help that appears on the UI,
// Information for displaying a title as a field
'field' => array(
'field' => 'title', // the real field
'handler' => 'views_handler_field_node',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// log field
$data['node_revisions']['log'] = array(
'title' => t('Log message'), // The item it appears as on the UI,
'help' => t('The log message entered when the revision was created.'), // The help that appears on the UI,
// Information for displaying a title as a field
'field' => array(
'handler' => 'views_handler_field_xss',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
Earl Miles
committed
// revision timestamp
Earl Miles
committed
$data['node_revisions']['timestamp'] = array(
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
'title' => t('Created date'), // The item it appears as on the UI,
'help' => t('The date the node revision was created.'), // The help that appears on the UI,
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
$data['node_revisions']['revert_revision'] = array(
'field' => array(
'title' => t('Revert link'),
'help' => t('Provide a simple link to revert to the revision.'),
'handler' => 'views_handler_field_node_revision_link_revert',
),
);
$data['node_revisions']['delete_revision'] = array(
'field' => array(
'title' => t('Delete link'),
'help' => t('Provide a simple link to delete the node revision.'),
'handler' => 'views_handler_field_node_revision_link_delete',
),
);
Earl Miles
committed
// ----------------------------------------------------------------------
// History table
Earl Miles
committed
// We're actually defining a specific instance of the table, so let's
// alias it so that we can later add the real table for other purposes if we
// need it.
Earl Miles
committed
$data['history_user']['table']['group'] = t('Node');
// Explain how this table joins to others.
$data['history_user']['table']['join'] = array(
// Directly links to node table.
'node' => array(
'table' => 'history',
'left_field' => 'nid',
'field' => 'nid',
'extra' => array(
Earl Miles
committed
array('field' => 'uid', 'value' => '***CURRENT_USER***', 'numeric' => TRUE),
Earl Miles
committed
),
),
);
$data['history_user']['timestamp'] = array(
Earl Miles
committed
'title' => t('Has new content'),
'field' => array(
'handler' => 'views_handler_field_history_user_timestamp',
'help' => t('Show a marker if the node has new or updated content.'),
),
Earl Miles
committed
'filter' => array(
'help' => t('Show only nodes that have new content.'),
'handler' => 'views_handler_filter_history_user_timestamp',
),
);
return $data;
}
Earl Miles
committed
* Implementation of hook_views_handlers() to register all of the basic handlers
* views uses.
Earl Miles
committed
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
function node_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'views') . '/modules/node',
),
'handlers' => array(
// field handlers
'views_handler_field_node' => array(
'parent' => 'views_handler_field',
),
'views_handler_field_node_type' => array(
'parent' => 'views_handler_field_node',
),
'views_handler_field_node_link' => array(
'parent' => 'views_handler_field',
),
'views_handler_field_node_type' => array(
'parent' => 'views_handler_field_node',
),
'views_handler_field_node_link_edit' => array(
'parent' => 'views_handler_field_node_link',
),
'views_handler_field_node_link_delete' => array(
'parent' => 'views_handler_field_node_link',
),
'views_handler_field_node_revision_link_revert' => array(
'parent' => 'views_handler_field_node_link',
),
'views_handler_field_node_revision_link_delete' => array(
'parent' => 'views_handler_field_node_link',
),
'views_handler_field_history_user_timestamp' => array(
'parent' => 'views_handler_field_node',
),
Earl Miles
committed
Earl Miles
committed
// argument handlers
'views_handler_argument_node_type' => array(
'parent' => 'views_handler_argument',
),
'views_handler_argument_node_nid' => array(
'parent' => 'views_handler_argument_numeric',
),
'views_handler_argument_node_vid' => array(
'parent' => 'views_handler_argument_numeric',
),
'views_handler_argument_node_created_fulldate' => array(
// put several handlers in the same file
'file' => 'views_handler_argument_dates_various.inc',
'parent' => 'views_handler_argument_date',
Earl Miles
committed
),
'views_handler_argument_node_created_year' => array(
// put several handlers in the same file
'file' => 'views_handler_argument_dates_various.inc',
'parent' => 'views_handler_argument_date',
Earl Miles
committed
),
'views_handler_argument_node_created_year_month' => array(
// put several handlers in the same file
'file' => 'views_handler_argument_dates_various.inc',
'parent' => 'views_handler_argument_date',
Earl Miles
committed
),
'views_handler_argument_node_created_month' => array(
// put several handlers in the same file
'file' => 'views_handler_argument_dates_various.inc',
'parent' => 'views_handler_argument_date',
Earl Miles
committed
),
'views_handler_argument_node_created_day' => array(
// put several handlers in the same file
'file' => 'views_handler_argument_dates_various.inc',
'parent' => 'views_handler_argument_date',
Earl Miles
committed
),
'views_handler_argument_node_created_week' => array(
// put several handlers in the same file
'file' => 'views_handler_argument_dates_various.inc',
'parent' => 'views_handler_argument_date',
Earl Miles
committed
),
Earl Miles
committed
Earl Miles
committed
// filters
'views_handler_filter_node_type' => array(
'parent' => 'views_handler_filter_in_operator',
),
'views_handler_filter_history_user_timestamp' => array(
'parent' => 'views_handler_filter',
),
'views_handler_filter_node_status' => array(
'parent' => 'views_handler_filter',
),
Earl Miles
committed
Earl Miles
committed
),
);
Earl Miles
committed
}
/**
* Implementation of hook_views_plugins
*/
function node_views_plugins() {
return array(
'module' => 'views', // This just tells our themes are elsewhere.
'row' => array(
'node' => array(
'title' => t('Node'),
'help' => t('Display the node with standard node view.'),
'handler' => 'views_plugin_row_node_view',
Earl Miles
committed
'path' => drupal_get_path('module', 'views') . '/modules/node', // not necessary for most modules
'theme' => 'views_view_row_node',
'base' => array('node'), // only works with 'node' as base.
Earl Miles
committed
'uses options' => TRUE,
'help topic' => 'style-node',
),
'node_rss' => array(
'title' => t('Node'),
'help' => t('Display the node with standard node view.'),
'handler' => 'views_plugin_row_node_rss',
Earl Miles
committed
'path' => drupal_get_path('module', 'views') . '/modules/node', // not necessary for most modules
'base' => array('node'), // only works with 'node' as base.
'uses options' => TRUE,
'type' => 'feed',
'help topic' => 'style-node-rss',
Earl Miles
committed
'argument validator' => array(
'node' => array(
'title' => t('Node'),
'handler' => 'views_plugin_argument_validate_node',
Earl Miles
committed
'path' => drupal_get_path('module', 'views') . '/modules/node', // not necessary for most modules
Earl Miles
committed
),
),
'argument default' => array(
'node' => array(
'title' => t('Node ID from URL'),
'handler' => 'views_plugin_argument_default_node',
Earl Miles
committed
'path' => drupal_get_path('module', 'views') . '/modules/node', // not necessary for most modules
'parent' => 'fixed', // so that the parent class is included
),
),
);
}
/**
* Template helper for theme_views_view_row_node
*/
function template_preprocess_views_view_row_node(&$vars) {
$vars['node'] = ''; // make sure var is defined.
$nid = $vars['row']->nid;
if (!is_numeric($nid)) {
return;
}
$node = node_load($nid);
if (empty($node)) {
return;
}
$vars['node'] = node_view($node, $options['teaser'], FALSE, $options['links']);
$vars['comments'] = NULL;
Earl Miles
committed
if (!empty($options['comments']) && function_exists('comment_render')) {
$vars['comments'] = comment_render($node);
/**
* Implementation of hook_views_query_substitutions().
*/
function node_views_query_substitutions() {
Earl Miles
committed
global $language;
return array(
'***ADMINISTER_NODES***' => intval(user_access('administer nodes')),
);
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
}
/**
* Implementation of hook_views_analyze().
*/
function node_views_analyze($view) {
$ret = array();
// Check for something other than the default display:
if ($view->base_table == 'node') {
foreach ($view->display as $id => $display) {
if (!$display->handler->is_defaulted('access') || !$display->handler->is_defaulted('filters')) {
// check for no access control
$access = $display->handler->get_option('access');
if (empty($access['type']) || $access['type'] == 'none') {
$filters = $display->handler->get_option('filters');
foreach ($filters as $filter) {
if ($filter['table'] == 'node' && ($filter['field'] == 'status' || $filter['field'] == 'status_extra')) {
continue 2;
}
}
$ret[] = views_ui_analysis(t('Display %display has no access control but does not contain a filter for published nodes.', array('%display' => $display->display_title)), 'warning');
}
}
}
}
return $ret;
}
/**
* @}
*/