diff --git a/includes/handlers.inc b/includes/handlers.inc index 679c759ae7471e88340c65a75c688f2a454ce3a6..7a27eca055a2ed41706bbb62158d1217e958e7b7 100644 --- a/includes/handlers.inc +++ b/includes/handlers.inc @@ -349,6 +349,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 0ec2a3ff195db41dc593777d19bc1fd4c420039d..ee868a2d3e08e1f022af862be0a95aaeeab96ad2 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 ce61752a189664b20dd946a7a6beeb6dc302b6c0..f864abf1da80162845b7cf5cfbeadf2cf9dc8a10 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'); } @@ -298,6 +310,27 @@ 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 cb0c69487b06844136df5eabcd510b21c47103fa..0eed33a947ed80df709d2ef6d51f15256f616487 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 49706d1a95156d6b989837ffdb6c7c468b3ada77..828b674ad24d8edced1fb65ad3ecfa1ce3a0f5c2 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"); } /**