diff --git a/includes/handlers.inc b/includes/handlers.inc index 05e85feff8cd81b7428bce2b63dcea671afeea54..679c759ae7471e88340c65a75c688f2a454ce3a6 100644 --- a/includes/handlers.inc +++ b/includes/handlers.inc @@ -297,6 +297,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 */ @@ -505,6 +558,16 @@ class views_handler_argument extends views_handler { return url("$url/$value"); } + /** + * 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 1e6849a2495095c88d6631039950ebb56403a402..0ec2a3ff195db41dc593777d19bc1fd4c420039d 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 e9d83e375ccb2832e86ec3c92ddc29b57ee7ca14..ce61752a189664b20dd946a7a6beeb6dc302b6c0 100644 --- a/modules/node.views.inc +++ b/modules/node.views.inc @@ -1,85 +1,207 @@ 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 e4c9cf947be48e54c0b7c9c270e160a01713a167..cb0c69487b06844136df5eabcd510b21c47103fa 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 2c1d50925227864b31ed6f46073d78426d1f4f8b..4932faf0252be44262110550ed2ab138c13f7d30 100644 --- a/theme/views-view-row-summary.tpl.php +++ b/theme/views-view-row-summary.tpl.php @@ -1,8 +1,10 @@ () diff --git a/theme/views-view-row.tpl.php b/theme/views-view-row.tpl.php index 17a992f24e5e4b0b4b932954bff032a3b0142fce..ea641ce3ba6dbbaffbc6118e57370f3e6a4b3be3 100644 --- a/theme/views-view-row.tpl.php +++ b/theme/views-view-row.tpl.php @@ -1,8 +1,10 @@ - $css): ?> diff --git a/theme/views-view-rows.tpl.php b/theme/views-view-rows.tpl.php index 8932e11d42208635a499a154d72e5e37fe09f06b..18f303cfcd1b5c3b2518fad554ccec253d64d692 100644 --- a/theme/views-view-rows.tpl.php +++ b/theme/views-view-rows.tpl.php @@ -1,8 +1,10 @@ - \ No newline at end of file diff --git a/theme/views-view-summary.tpl.php b/theme/views-view-summary.tpl.php index af59bf76da3eec4d398ddd36189d4e2b27705265..ed7e6f84447d9c7f6ebfbc73be11f32a8f018ea2 100644 --- a/theme/views-view-summary.tpl.php +++ b/theme/views-view-summary.tpl.php @@ -1,8 +1,10 @@
diff --git a/theme/views-view.tpl.php b/theme/views-view.tpl.php index a7eaa1bc7ee39120cc1ef7944532e1e9aac6963c..dc6079689297254b581d7b0ee44e58af75102a74 100644 --- a/theme/views-view.tpl.php +++ b/theme/views-view.tpl.php @@ -1,9 +1,19 @@ -
diff --git a/views.module b/views.module index b3171675a81fb5124c3c76001910644179ccc216..49706d1a95156d6b989837ffdb6c7c468b3ada77 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(); } }