summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEarl Miles2008-01-03 01:36:12 (GMT)
committer Earl Miles2008-01-03 01:36:12 (GMT)
commit0225248a9b982a59808068711f10049f8493e17a (patch)
treee55189b6bd17f3b5cf414c54188943359d7535e7
parent86ed07d8625f7fcc6548e9b661a16ff9bae7b6d0 (diff)
More handlers for the node table, plus a bit more documentation stuffs
-rw-r--r--includes/handlers.inc63
-rw-r--r--includes/view.inc4
-rw-r--r--modules/node.views.inc234
-rw-r--r--theme/theme.inc5
-rw-r--r--theme/views-view-row-summary.tpl.php4
-rw-r--r--theme/views-view-row.tpl.php4
-rw-r--r--theme/views-view-rows.tpl.php4
-rw-r--r--theme/views-view-summary.tpl.php4
-rw-r--r--theme/views-view.tpl.php12
-rw-r--r--views.module2
10 files changed, 292 insertions, 44 deletions
diff --git a/includes/handlers.inc b/includes/handlers.inc
index 05e85fe..679c759a 100644
--- a/includes/handlers.inc
+++ b/includes/handlers.inc
@@ -298,6 +298,58 @@ class views_handler_field_date extends views_handler_field {
}
/**
+ * A handler to provide proper displays for dates.
+ *
+ * Allows for display of true/false, yes/no, on/off.
+ */
+class views_handler_field_boolean extends views_handler_field {
+ /**
+ * Constructor; calls to base object constructor.
+ */
+ function construct($click_sortable = FALSE, $additional_fields = array()) {
+ parent::construct($click_sortable, $additional_fields);
+ }
+
+ function options_form(&$form) {
+ $form['type'] = array(
+ '#type' => 'select',
+ '#title' => t('Date format'),
+ '#options' => array(
+ 'yes-no' => t('Yes/No'),
+ 'true-false' => t('True/False'),
+ 'on-off' => t('On/Off'),
+ ),
+ '#default_value' => isset($this->options['type']) ? $this->options['type'] : 'yes-no',
+ );
+ $form['not'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Reverse'),
+ '#description' => t('If checked, true will be displayed as false.'),
+ '#default_value' => !empty($this->options['not']),
+ );
+ }
+
+ function render($values) {
+ $value = $values->{$this->field_alias};
+ if (!empty($this->options['not'])) {
+ $value = !$value;
+ }
+
+ $format = isset($this->options['type']) ? $this->options['type'] : 'yes';
+
+ switch ($format) {
+ case 'yes-no':
+ default:
+ return $value ? t('Yes') : t('No');
+ case 'true-false':
+ return $value ? t('True') : t('False');
+ case 'yes-no':
+ return $value ? t('On') : t('Off');
+ }
+ }
+}
+
+/**
* @}
*/
@@ -428,6 +480,7 @@ class views_handler_filter extends views_handler {
* The basic argument works for very simple arguments such as nid and uid
*/
class views_handler_argument extends views_handler {
+ var $name_field = NULL;
/**
* Constructor
*/
@@ -506,6 +559,16 @@ class views_handler_argument extends views_handler {
}
/**
+ * Provides the name to use for the summary. By default this is just
+ * the name field.
+ *
+ * @param $data
+ * The query results for the row.
+ */
+ function summary_name($data) {
+ return check_plain($data->{$this->name_alias});
+ }
+ /**
* Provide a list of default behaviors for this argument if the argument
* is not present.
*
diff --git a/includes/view.inc b/includes/view.inc
index 1e6849a..0ec2a3f 100644
--- a/includes/view.inc
+++ b/includes/view.inc
@@ -451,7 +451,9 @@ class view extends views_db_object {
*
* @todo: Implement this.
*/
- function get_url($args = NULL) { }
+ function get_url($args = NULL) {
+ return $_GET['q'];
+ }
/**
* Is this view cacheable?
diff --git a/modules/node.views.inc b/modules/node.views.inc
index e9d83e3..ce61752 100644
--- a/modules/node.views.inc
+++ b/modules/node.views.inc
@@ -1,85 +1,207 @@
<?php
+// $Id$
/**
* @file
- * Provides views data and handlers for node.module
+ * 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()
*/
function node_views_data() {
// Basic table information.
- $data['node']['table'] = array(
- 'group' => t('Node'), // Fields will default to this group
- // Advertise this table as a possible base table
- 'base' => array(
- 'field' => 'nid',
- 'title' => t('Node'),
- ),
- // For other base tables, explain how we join
- 'join' => array(
- 'users' => array(
- 'handler' => 'views_join', // this is actually optional
- 'arguments' => array('node', 'users', 'uid', 'uid'),
- ),
- ),
- // Provide output plugins specifically for this base type.
- 'plugins' => array(
+
+ // 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'),
+ );
+
+ // For other base tables, explain how we join
+ $data['node']['table']['join'] = array(
+ 'users' => array(
+ 'handler' => 'views_join', // this is actually optional
+ 'arguments' => array('node', 'users', 'uid', 'uid'),
+ ),
+ 'node_revisions' => array(
+ 'arguments' => array('node', 'node_revisions', 'nid', 'nid'),
+ ),
+ );
+ // Provide output plugins specifically for this base type.
+ $data['node']['table']['plugins'] = array(
+ 'row' => array(
'node' => array(
'title' => t('Node'),
'help' => t('Display the node with standard node view.'),
- 'handler' => 'views_record_plugin_node_view',
+ 'handler' => 'views_row_plugin_node_view',
),
),
);
+ // ----------------------------------------------------------------
// Fields
// title
- $data['node']['title']['field'] = array(
- 'field' => 'title', // the real field
- 'group' => t('Node'), // The group it appears in on the UI,
+ $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,
- 'handler' => 'views_handler_field_node',
- 'arguments' => array(TRUE),
+ '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
+ 'group' => t('Node'), // The group it appears in on the UI,
+ 'handler' => 'views_handler_field_node',
+ 'arguments' => array(TRUE), // arguments to the handler
+ ),
);
// 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',
'arguments' => array(TRUE),
),
+ // Information for accepting a nid as an argument
'argument' => array(
'handler' => 'views_handler_argument',
'arguments' => array('title'),
),
+ // Information for accepting a nid as a filter
'filter' => array(
'handler' => 'views_handler_filter',
),
+ // Information for sorting on a nid.
+ 'sort' => array(
+ 'handler' => 'views_handler_sort',
+ ),
);
// created field
- $data['node']['created']['title'] = t('Post date'); // The item it appears as on the UI,
- $data['node']['created']['help'] = t('The date the node was posted'); // The help that appears on the UI,
- $data['node']['created']['field']['handler'] = 'views_handler_field_date';
- $data['node']['created']['field']['arguments'] = array(TRUE);
- $data['node']['created']['sort']['handler'] = 'views_handler_sort';
+ $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',
+ 'arguments' => array(TRUE),
+ ),
+ 'sort' => array(
+ 'handler' => 'views_handler_sort',
+ ),
+ );
// changed field
- $data['node']['changed']['field'] = array(
+ $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,
- 'handler' => 'views_handler_field_date',
- 'arguments' => array(TRUE),
+ 'help' => t('The date the node was last updated.'), // The help that appears on the UI,
+ 'field' => array(
+ 'handler' => 'views_handler_field_date',
+ 'arguments' => array(TRUE),
+ ),
);
- $data['node']['type']['field'] = array(
+
+ // 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,
- 'handler' => 'views_handler_field_node_type',
- 'arguments' => array(TRUE),
+ 'field' => array(
+ 'handler' => 'views_handler_field_node_type',
+ 'arguments' => array(TRUE),
+ ),
+ 'argument' => array(
+ 'handler' => 'views_handler_argument_node_type',
+ ),
+ );
+
+ // published status
+ $data['node']['status'] = array(
+ 'title' => t('Published'), // The item it appears as on the UI,
+ 'help' => t('The published status of the node.'), // The help that appears on the UI,
+ // Information for displaying a title as a field
+ 'field' => array(
+ 'handler' => 'views_handler_field_boolean',
+ 'arguments' => array(TRUE), // arguments to the handler
+ ),
+ 'sort' => array(
+ 'handler' => 'views_handler_sort',
+ ),
);
+ // promote status
+ $data['node']['promote'] = array(
+ 'title' => t('Promoted to front page'), // The item it appears as on the UI,
+ 'help' => t('The front page of the node.'), // The help that appears on the UI,
+ // Information for displaying a title as a field
+ 'field' => array(
+ 'handler' => 'views_handler_field_boolean',
+ 'arguments' => array(TRUE), // arguments to the handler
+ ),
+ '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',
+ 'arguments' => array(TRUE), // arguments to the handler
+ ),
+ 'sort' => array(
+ 'handler' => 'views_handler_sort',
+ ),
+ );
+
+ // ----------------------------------------------------------------------
+ // 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']['table']['group'] = t('Node');
+ // Advertise this table as a possible base table
+ $data['node']['table']['base'] = array(
+ 'field' => 'vid',
+ 'title' => t('Node revisions'),
+ );
+
+ // For other base tables, explain how we join
+ $data['node']['table']['join'] = array(
+ 'node' => array(
+ 'arguments' => array('node_revisions', 'node', 'vid', 'vid'),
+ ),
+ 'user' => array(
+ 'arguments' => array('node_revisions', 'node', 'vid', 'vid'),
+ ),
+ );
+
+ // 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.'), // The help that appears on the UI,
+ // Information for displaying a title as a field
+ 'field' => array(
+ 'field' => 'body', // the real field
+ 'group' => t('Node'), // The group it appears in on the UI,
+ 'handler' => 'views_handler_field_markup',
+ 'arguments' => array(FALSE, 'format'), // arguments to the handler
+ ),
+ );
return $data;
}
@@ -139,3 +261,43 @@ class views_handler_field_node_type extends views_handler_field_node {
return $this->render_link(check_plain($value), $values);
}
}
+
+/**
+ * Argument handler to accept a node type.
+ *
+ * @ingroup views_argument_handlers
+ */
+class views_handler_argument_node_type extends views_handler_argument {
+ // No constructor is necessary.
+ function construct() {
+ parent::construct('type');
+ }
+
+ /**
+ * Override the behavior of summary_name(). Get the user friendly version
+ * of the node type.
+ */
+ function summary_name($data) {
+ return $this->node_type($data->{$this->name_alias});
+ }
+
+ /**
+ * Override the behavior of title(). Get the user friendly version of the
+ * node type.
+ */
+ function title() {
+ return $this->node_type($this->argument);
+ }
+
+ function node_type($type) {
+ $output = node_get_types('name', $type);
+ if (empty($output)) {
+ $output = t('Unknown node type');
+ }
+ return check_plain($output);
+ }
+}
+
+/**
+ * @}
+ */
diff --git a/theme/theme.inc b/theme/theme.inc
index e4c9cf9..cb0c694 100644
--- a/theme/theme.inc
+++ b/theme/theme.inc
@@ -71,8 +71,11 @@ function template_preprocess_views_view_row_summary(&$vars) {
$row = $vars['row'];
$argument = $view->argument[$view->build_info['summary_level']]->handler;
- $vars['link'] = check_plain($row->{$argument->name_alias});
+ $vars['link'] = $argument->summary_name($row);
$vars['url'] = $argument->summary_link($row, $view->get_url());
$vars['count'] = intval($row->{$argument->count_alias});
}
+/**
+ * @defgroup views_templates Views' template files
+ */
diff --git a/theme/views-view-row-summary.tpl.php b/theme/views-view-row-summary.tpl.php
index 2c1d509..4932faf 100644
--- a/theme/views-view-row-summary.tpl.php
+++ b/theme/views-view-row-summary.tpl.php
@@ -1,8 +1,10 @@
<?php
// $Id$
/**
- * @file views-view-row.tpl.php
+ * @file views-view-row-summary.tpl.php
* Default simple view template to display a list of rows.
+ *
+ * @ingroup views_templates
*/
?>
<a href="<?php print $url; ?>"><?php print $link; ?></a> (<?php print $count?>)
diff --git a/theme/views-view-row.tpl.php b/theme/views-view-row.tpl.php
index 17a992f..ea641ce 100644
--- a/theme/views-view-row.tpl.php
+++ b/theme/views-view-row.tpl.php
@@ -1,8 +1,10 @@
-<?php
+<?php
// $Id$
/**
* @file views-view-row.tpl.php
* Default simple view template to display a list of rows.
+ *
+ * @ingroup views_templates
*/
?>
<?php foreach ($fields as $name => $css): ?>
diff --git a/theme/views-view-rows.tpl.php b/theme/views-view-rows.tpl.php
index 8932e11..18f303c 100644
--- a/theme/views-view-rows.tpl.php
+++ b/theme/views-view-rows.tpl.php
@@ -1,8 +1,10 @@
-<?php
+<?php
// $Id$
/**
* @file views-view-rows.tpl.php
* Default simple view template to display a list of rows.
+ *
+ * @ingroup views_templates
*/
?>
<?php print $rows ?> \ No newline at end of file
diff --git a/theme/views-view-summary.tpl.php b/theme/views-view-summary.tpl.php
index af59bf7..ed7e6f8 100644
--- a/theme/views-view-summary.tpl.php
+++ b/theme/views-view-summary.tpl.php
@@ -1,8 +1,10 @@
<?php
// $Id$
/**
- * @file views-view-rows.tpl.php
+ * @file views-view-summary.tpl.php
* Default simple view template to display a list of summary lines
+ *
+ * @ingroup views_templates
*/
?>
<div class="item-list">
diff --git a/theme/views-view.tpl.php b/theme/views-view.tpl.php
index a7eaa1b..dc60796 100644
--- a/theme/views-view.tpl.php
+++ b/theme/views-view.tpl.php
@@ -1,9 +1,19 @@
-<?php
+<?php
// $Id$
/**
* @file views-view.tpl.php
* Main view template
*
+ * Variables available:
+ * - $header: The view header
+ * - $footer: The view footer
+ * - $rows: The results of the view query, if any
+ * - $empty: The empty text to display if the view is empty
+ * - $pager: The pager next/prev links to display, if any
+ * - $filters: Exposed filter form/info to display
+ * - $feed_icon: Feed icon to display, if any
+ *
+ * @ingroup views_templates
*/
?>
<div class="view view-<?php print $css_name; ?>">
diff --git a/views.module b/views.module
index b317167..49706d1 100644
--- a/views.module
+++ b/views.module
@@ -505,7 +505,7 @@ function &views_get_default_view($view_name) {
else {
// We may as well rebuild the cache while we're at it, since we need to pull all
// of the data anyway. We pick out the one we want along the way.
- $cache = discover_default_views();
+ $cache = views_discover_default_views();
}
}