Commit 2bd5f0a0 authored by merlinofchaos's avatar merlinofchaos

Teaser & body fields with generic "check markup" handler

parent 0225248a
......@@ -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);
}
}
/**
* @}
*/
......
......@@ -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();
}
}
......
......@@ -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();
}
}
/**
* @}
*/
......@@ -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);
}
}
}
......
......@@ -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");
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment