summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEarl Miles2008-01-03 02:50:26 (GMT)
committer Earl Miles2008-01-03 02:50:26 (GMT)
commit2bd5f0a0974510377c02a607f65bd23fb23e75d4 (patch)
tree96aa65ef550fdaa2652e56bb74b20e6ea08097cb
parent0225248a9b982a59808068711f10049f8493e17a (diff)
Teaser & body fields with generic "check markup" handler
-rw-r--r--includes/handlers.inc28
-rw-r--r--includes/view.inc2
-rw-r--r--modules/node.views.inc51
-rw-r--r--theme/theme.inc24
-rw-r--r--views.module2
5 files changed, 85 insertions, 22 deletions
diff --git a/includes/handlers.inc b/includes/handlers.inc
index 679c759a..7a27eca 100644
--- a/includes/handlers.inc
+++ b/includes/handlers.inc
@@ -350,6 +350,34 @@ class views_handler_field_boolean extends views_handler_field {
}
/**
+ * A handler to run a field through check_markup, using a companion
+ * format field.
+ *
+ * Allows for display of true/false, yes/no, on/off.
+ */
+class views_handler_field_markup extends views_handler_field {
+ /**
+ * Constructor; calls to base object constructor.
+ */
+ function construct($format) {
+ $this->format = $format;
+
+ $addl_fields = array();
+ if (!is_numeric($format)) {
+ $addl_fields[] = $format;
+ }
+
+ parent::construct(FALSE, $addl_fields);
+ }
+
+ function render($values) {
+ $value = $values->{$this->field_alias};
+ $format = is_numeric($this->format) ? $this->format : $values->{$this->aliases[$this->format]};
+ return check_markup($value, $format, FALSE);
+ }
+}
+
+/**
* @}
*/
diff --git a/includes/view.inc b/includes/view.inc
index 0ec2a3f..ee868a2 100644
--- a/includes/view.inc
+++ b/includes/view.inc
@@ -300,7 +300,7 @@ class view extends views_db_object {
$array = &$this->$key;
foreach ($array as $id => $data) {
// @todo: we should report an error here if this is not an object.
- if (is_object($array[$id]->handler)) {
+ if (!empty($array[$id]->handler) && is_object($array[$id]->handler)) {
$array[$id]->handler->query();
}
}
diff --git a/modules/node.views.inc b/modules/node.views.inc
index ce61752..f864abf 100644
--- a/modules/node.views.inc
+++ b/modules/node.views.inc
@@ -35,6 +35,7 @@ function node_views_data() {
'arguments' => array('node', 'users', 'uid', 'uid'),
),
'node_revisions' => array(
+ 'handler' => 'views_join', // this is actually optional
'arguments' => array('node', 'node_revisions', 'nid', 'nid'),
),
);
@@ -76,7 +77,7 @@ function node_views_data() {
),
// Information for accepting a nid as an argument
'argument' => array(
- 'handler' => 'views_handler_argument',
+ 'handler' => 'views_handler_argument_nid',
'arguments' => array('title'),
),
// Information for accepting a nid as a filter
@@ -172,20 +173,22 @@ function node_views_data() {
// 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');
+ $data['node_revisions']['table']['group'] = t('Node');
// Advertise this table as a possible base table
- $data['node']['table']['base'] = array(
+ $data['node_revisions']['table']['base'] = array(
'field' => 'vid',
'title' => t('Node revisions'),
);
// For other base tables, explain how we join
- $data['node']['table']['join'] = array(
+ $data['node_revisions']['table']['join'] = array(
'node' => array(
+ 'handler' => 'views_join', // this is actually optional
'arguments' => array('node_revisions', 'node', 'vid', 'vid'),
),
'user' => array(
+ 'handler' => 'views_join', // this is actually optional
'arguments' => array('node_revisions', 'node', 'vid', 'vid'),
),
);
@@ -193,15 +196,25 @@ function node_views_data() {
// 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,
+ '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(
- '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
+ 'arguments' => array('format'), // arguments to the handler
),
);
+
+ // 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',
+ 'arguments' => array('format'), // arguments to the handler
+ ),
+ );
+
return $data;
}
@@ -268,7 +281,6 @@ class views_handler_field_node_type extends views_handler_field_node {
* @ingroup views_argument_handlers
*/
class views_handler_argument_node_type extends views_handler_argument {
- // No constructor is necessary.
function construct() {
parent::construct('type');
}
@@ -299,5 +311,26 @@ class views_handler_argument_node_type extends views_handler_argument {
}
/**
+ * Argument handler to accept a node id.
+ *
+ * @ingroup views_argument_handlers
+ */
+class views_handler_argument_node_nid extends views_handler_argument {
+ // No constructor is necessary.
+
+ /**
+ * Override the behavior of title(). Get the title of the node.
+ */
+ function title() {
+ $title = db_fetch_result(db_query(db_rewrite_sql("SELECT n.title FROM {node} n WHERE n.nid = %d"), $this->argument));
+ if (empty($title)) {
+ return t('No title');
+ }
+
+ return check_plain();
+ }
+}
+
+/**
* @}
*/
diff --git a/theme/theme.inc b/theme/theme.inc
index cb0c694..0eed33a 100644
--- a/theme/theme.inc
+++ b/theme/theme.inc
@@ -38,17 +38,19 @@ function template_preprocess_views_view_row(&$vars) {
// Loop through the fields for this view.
foreach ($view->get_fields($view->current_display) as $field) {
- $themes = array(
- 'views_view_field__' . $view->name . '__' . $field->handler->field_alias,
- 'views_view_field__' . $view->name,
- 'views_view_field__' . $field->handler->field_alias,
- 'views_view_field',
- );
- // Add the field into a variable named after the field. field_alias will be unique.
- $vars[$field->handler->field_alias] = theme($themes, $view, $field, $vars['row']);
- // Create a second variable so we can easily find what fields we have and what the
- // CSS classes should be.
- $vars['fields'][$field->handler->field_alias] = views_css_safe($field->handler->field_alias);
+ if (!empty($field->handler) && is_object($field->handler)) {
+ $themes = array(
+ 'views_view_field__' . $view->name . '__' . $field->handler->field_alias,
+ 'views_view_field__' . $view->name,
+ 'views_view_field__' . $field->handler->field_alias,
+ 'views_view_field',
+ );
+ // Add the field into a variable named after the field. field_alias will be unique.
+ $vars[$field->handler->field_alias] = theme($themes, $view, $field, $vars['row']);
+ // Create a second variable so we can easily find what fields we have and what the
+ // CSS classes should be.
+ $vars['fields'][$field->handler->field_alias] = views_css_safe($field->handler->field_alias);
+ }
}
}
diff --git a/views.module b/views.module
index 49706d1..828b674 100644
--- a/views.module
+++ b/views.module
@@ -341,7 +341,7 @@ function views_get_handler($table, $field, $key) {
return _views_prepare_handler($data[$field][$key], $data, $field);
}
// DEBUG -- identify missing handlers
- dsm("$table $field $key");
+ dsm("Missing handler: $table $field $key");
}
/**