Commit 725bd2c9 authored by merlinofchaos's avatar merlinofchaos

Fix a couple of small theming bugs, plus some new handlers from adrian. These...

Fix a couple of small theming bugs, plus some new handlers from adrian. These need some adjustments still but I wanted to get them in as a start.
parent a4b4d7ab
......@@ -11,9 +11,13 @@
function _views_create_handler($definition) {
// dpr('Instantiating handler ' . $definition['handler']);
$handler = new $definition['handler'];
// let the handler have something like a constructor.
if (isset($definition['arguments'])) {
call_user_func_array(array($handler, 'construct'), $definition['arguments']);
}
else {
$handler->construct();
}
$handler->set_definition($definition);
return $handler;
......@@ -139,6 +143,14 @@ class views_join {
*
*/
class views_handler extends views_object {
/**
* A constructor for the handler base object
*
* This should be overridden to provide for a consistent constructor
* mechanism.
*/
function construct() { }
/**
* init the handler with necessary data.
* @param $view
......@@ -264,9 +276,13 @@ class views_handler_field extends views_handler {
/**
* Construct a new field handler.
*/
// function construct($click_sortable = FALSE, $additional_fields = array()) {
function construct($click_sortable = FALSE, $additional_fields = array()) {
$this->click_sortable = $click_sortable;
$this->additional_fields = $additional_fields;
$this->click_sortable = !empty($this->definition['click sortable']);
$this->additional_fields = array();
if (!empty($this->definition['additional fields'])) {
$this->additional_fields = $this->definition['additional fields'];
}
}
/**
......@@ -309,12 +325,8 @@ class views_handler_field extends views_handler {
*/
class views_handler_field_date extends views_handler_field {
/**
* Constructor; calls to base object constructor.
* Fill in default options.
*/
function construct($click_sortable = FALSE, $additional_fields = array()) {
parent::construct($click_sortable, $additional_fields);
}
function options(&$item) {
$item->date_format = 'small';
$item->custom_date_format = '';
......@@ -365,13 +377,6 @@ class views_handler_field_date extends views_handler_field {
* 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(&$item) {
$item->type = 'yes-no';
$item->not = FALSE;
......@@ -417,22 +422,18 @@ 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;
function construct() {
$this->format = $this->definition['format'];
$addl_fields = array();
if (!is_numeric($format)) {
$addl_fields[] = $format;
$this->additional_fields = array();
if (!is_numeric($this->format)) {
$this->additional_fields[] = $this->format;
}
parent::construct(FALSE, $addl_fields);
}
function render($values) {
......@@ -513,11 +514,13 @@ class views_handler_sort_formula extends views_handler_sort {
* The formula used to sort. If an array, may be keyed by database type. If
* used, 'default' MUST be defined.
*/
function construct($formula) {
$this->formula = $formula;
if (is_array($formula) && !isset($formula['default'])) {
$this->error = t('views_handler_sort_formula missing default: @formula', array('@formula' => var_export($formula, TRUE)));
// function construct($formula) {
function construct() {
$this->formula = $this->definition['formula'];
if (is_array($this->formula) && !isset($this->formula['default'])) {
$this->error = t('views_handler_sort_formula missing default: @formula', array('@formula' => var_export($this->formula, TRUE)));
}
parent::construct();
}
/**
* Called to add the sort to a query.
......@@ -667,6 +670,9 @@ class views_handler_filter_equality extends views_handler_filter {
);
}
/**
* Provide a simple textfield for equality
*/
function value_form(&$form, &$form_state) {
$form['value'] = array(
'#type' => 'textfield',
......@@ -677,6 +683,98 @@ class views_handler_filter_equality extends views_handler_filter {
}
}
/**
* Simple filter to handle matching of boolean values
*/
class views_handler_filter_boolean_operator extends views_handler_filter {
function construct($value) {
$this->value_value = t('True');
if (isset($this->definition['label'])) {
$this->value_value = $this->definition['label'];
}
parent::construct();
}
function operator_form(&$form, &$form_state) {
$form['operator'] = array(
'#type' => 'radios',
'#default_value' => ($this->data->operator['operator']) ? $this->data->operator['operator'] : '=',
'#options' => array(
'=' => t('Is'),
'<>' => t('Is not'),
),
);
}
function value_form(&$form, &$form_state) {
$form['value'] = array(
'#type' => 'textfield',
'#disabled' => TRUE,
'#value' => $this->value_value,
);
}
function admin_summary() {
return check_plain($this->data->operator['operator']) . ' ' . check_plain($this->value_value);
}
function query() {
$this->query->add_where($this->data->group, "$this->table_alias.$this->real_field " . $this->data->operator['operator'] . " 1");
}
}
/**
* Simple filter to handle matching of multiple options selectable via checkboxes
*/
class views_handler_filter_in_operator extends views_handler_filter {
function construct() {
parent::construct();
$this->value_title = t('Options');
$this->value_options = array(t('Yes'), t('No'));
}
/**
* Provide inclusive/exclusive matching
*/
function operator_form(&$form, &$form_state) {
$form['operator'] = array(
'#type' => 'radios',
'#title' => t('Operator'),
'#default_value' => ($this->data->operator['operator']) ? $this->data->operator['operator'] : 'in',
'#options' => array(
'in' => t('Is one of'),
'not in' => t('Is not one of'),
),
);
}
function value_form(&$form, &$form_state) {
$form['value'] = array(
'#type' => 'checkboxes',
'#required' => TRUE,
'#title' => $this->value_title,
'#options' => $this->value_options,
'#default_value' => (array) $this->data->value['value'],
);
}
function value_submit($form, &$form_state) {
// This is so deeply deeply deeply nested due to the way the form is layered.
$form_state['values']['options']['value']['value'] = array_filter($form_state['values']['options']['value']['value']);
}
function admin_summary() {
return check_plain($this->data->operator['operator']) . ' ' . check_plain(implode(', ', $this->data->value['value']));
}
function query() {
$this->ensure_my_table();
$replace = array_fill(0, sizeof($this->data->value['value']), "'%s'");
$in = ' (' . implode(", ", $replace) . ')';
$this->query->add_where($this->data->group, "$this->table_alias.$this->real_field " . $this->data->operator['operator'] . $in, $this->data->value['value']);
}
}
/**
* @}
*/
......@@ -695,8 +793,10 @@ class views_handler_argument extends views_handler {
/**
* Constructor
*/
function construct($name_field = NULL) {
$this->name_field = $name_field;
function construct() {
if (!empty($this->definition['name field'])) {
$this->name_field = $this->definition['name field'];
}
}
/**
......@@ -998,11 +1098,14 @@ class views_handler_argument extends views_handler {
* Child classes of this object should implement summary_link, at least.
*/
class views_handler_argument_formula extends views_handler_argument {
var $formula = NULL;
/**
* Constructor
*/
function construct($formula) {
$this->formula = $formula;
function construct() {
if (!empty($this->definition['formula'])) {
$this->formula = $this->definition['formula'];
}
}
/**
......
......@@ -202,7 +202,7 @@ class views_display_plugin extends views_object {
* saved to the database. It provides appropriate defaults for the
* display, if necessary.
*/
function construct(&$display) {
function options(&$display) {
// Set the following options to use the default display, forcing
// them to pass through unless we override.
$display->display_options['defaults'] = array(
......@@ -652,7 +652,7 @@ class views_display_plugin extends views_object {
if ($this->get_option($section) != $form_state['values'][$section]) {
$this->set_option($section, $form_state['values'][$section]);
$plugin = views_get_plugin('row', $form_state['values'][$section]);
$this->set_option('row_options', $plugin->construct($this->display));
$this->set_option('row_options', $plugin->options($this->display));
}
break;
case 'style_plugin':
......@@ -661,7 +661,7 @@ class views_display_plugin extends views_object {
if ($this->get_option($section) != $form_state['values'][$section]) {
$this->set_option($section, $form_state['values'][$section]);
$plugin = views_get_plugin('style', $form_state['values'][$section]);
$this->set_option('style_options', $plugin->construct($this->display));
$this->set_option('style_options', $plugin->options($this->display));
}
break;
case 'style_options':
......@@ -843,7 +843,7 @@ class views_display_plugin_default extends views_display_plugin {
*/
function is_default_display() { return TRUE; }
function construct(&$display) {
function options(&$display) {
// Make sure the default display has a style plugin to start with.
$display->display_options['style_plugin'] = 'default';
$display->display_options['style_options'] = array();
......@@ -1256,7 +1256,7 @@ class views_style_plugin_list extends views_style_plugin {
/**
* Set default options
*/
function construct($display) {
function options($display) {
return array(
'type' => 'ul',
);
......@@ -1297,7 +1297,7 @@ class views_style_plugin_table extends views_style_plugin {
/**
* Set default options
*/
function construct($display) {
function options($display) {
return array(
);
}
......
......@@ -921,7 +921,7 @@ class views_db_object {
// Create the new display object
$display = new views_display;
$display->construct($type, $id, $title);
$display->options($type, $id, $title);
// Add the new display object to the view.
$this->display[$id] = $display;
......@@ -1041,6 +1041,7 @@ class views_sort extends views_sub_object {
* A filter in a view.
*/
class views_filter extends views_sub_object {
var $group = 0;
}
/**
......@@ -1058,14 +1059,14 @@ class views_display extends views_db_object {
parent::init($init);
}
function construct($type, $id, $title) {
function options($type, $id, $title) {
$this->display_plugin = $type;
$this->id = $id;
$this->display_title = $title;
// Create a handler to fill in default values.
$handler = views_get_plugin('display', $type);
$handler->construct($this);
$handler->options($this);
}
}
......
......@@ -54,7 +54,7 @@ function node_views_data() {
'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
'click sortable' => TRUE,
),
);
......@@ -65,12 +65,12 @@ function node_views_data() {
// Information for displaying the nid
'field' => array(
'handler' => 'views_handler_field_node',
'arguments' => array(TRUE),
'click sortable' => TRUE,
),
// Information for accepting a nid as an argument
'argument' => array(
'handler' => 'views_handler_argument_node_nid',
'arguments' => array('title'),
'click sortable' => TRUE,
),
// Information for accepting a nid as a filter
'filter' => array(
......@@ -88,7 +88,7 @@ function node_views_data() {
'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),
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
......@@ -101,7 +101,7 @@ function node_views_data() {
'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),
'click sortable' => TRUE,
),
);
......@@ -111,8 +111,12 @@ function node_views_data() {
'help' => t('The type of a node (for example, "blog entry", "forum post", "story", etc)'), // The help that appears on the UI,
'field' => array(
'handler' => 'views_handler_field_node_type',
'arguments' => array(TRUE),
'click sortable' => TRUE,
),
// Information for accepting a nid as a filter
'filter' => array(
'handler' => 'views_handler_filter_node_type',
),
'argument' => array(
'handler' => 'views_handler_argument_node_type',
),
......@@ -125,8 +129,12 @@ function node_views_data() {
// Information for displaying a title as a field
'field' => array(
'handler' => 'views_handler_field_boolean',
'arguments' => array(TRUE), // arguments to the handler
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Published'),
),
'sort' => array(
'handler' => 'views_handler_sort',
),
......@@ -139,8 +147,12 @@ function node_views_data() {
// Information for displaying a title as a field
'field' => array(
'handler' => 'views_handler_field_boolean',
'arguments' => array(TRUE), // arguments to the handler
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Promoted to front page'),
),
'sort' => array(
'handler' => 'views_handler_sort',
),
......@@ -153,8 +165,12 @@ function node_views_data() {
// Information for displaying a title as a field
'field' => array(
'handler' => 'views_handler_field_boolean',
'arguments' => array(TRUE), // arguments to the handler
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Sticky'),
),
'sort' => array(
'handler' => 'views_handler_sort',
),
......@@ -167,7 +183,6 @@ function node_views_data() {
'help' => t('In the form of YYYYMM'),
'argument' => array(
'handler' => 'views_handler_argument_node_created_year_month',
'arguments' => array(), // this is required to make sure construct is called.
),
);
......@@ -176,7 +191,6 @@ function node_views_data() {
'help' => t('In the form of YYYY'),
'argument' => array(
'handler' => 'views_handler_argument_node_created_year',
'arguments' => array(), // this is required to make sure construct is called.
),
);
......@@ -185,7 +199,6 @@ function node_views_data() {
'help' => t('In the form of MM 01 - 12'),
'argument' => array(
'handler' => 'views_handler_argument_node_created_month',
'arguments' => array(), // this is required to make sure construct is called.
),
);
......@@ -222,7 +235,7 @@ function node_views_data() {
// Information for displaying a title as a field
'field' => array(
'handler' => 'views_handler_field_markup',
'arguments' => array('format'), // arguments to the handler
'format' => 'format', // The name of the format field
),
);
......@@ -233,7 +246,7 @@ function node_views_data() {
// Information for displaying a title as a field
'field' => array(
'handler' => 'views_handler_field_markup',
'arguments' => array('format'), // arguments to the handler
'format' => 'format', // The name of the format field
),
);
......@@ -437,6 +450,22 @@ class views_handler_argument_node_created_month extends views_handler_argument_f
}
}
/**
I Filter by node type
*/
class views_handler_filter_node_type extends views_handler_filter_in_operator {
function construct() {
parent::construct();
$this->value_title = t('Node type');
$types = node_get_types();
foreach ($types as $type => $info) {
$options[$type] = $info->name;
}
$this->value_options = $options;
}
}
/**
* Implementation of hook_views_plugins
*/
......@@ -462,7 +491,7 @@ function node_views_plugins() {
* @ingroup views_row_plugins
*/
class views_row_plugin_node_view extends views_row_plugin {
function construct($display) {
function options($display) {
return array(
'teaser' => TRUE,
);
......
......@@ -40,7 +40,7 @@ function user_views_data() {
'field' => 'name', // the real field
'group' => t('User'), // The group it appears in on the UI,
'handler' => 'views_handler_field_user_name',
'arguments' => array(TRUE), // arguments to the handler
'click sortable' => TRUE,
),
);
// uid
......@@ -50,12 +50,11 @@ function user_views_data() {
// Information for displaying the uid
'field' => array(
'handler' => 'views_handler_field_user',
'arguments' => array(TRUE),
'click sortable' => TRUE,
),
// Information for accepting a uid as an argument
'argument' => array(
'handler' => 'views_handler_argument_uid', //TODO
'arguments' => array('title'),
'handler' => 'views_handler_argument_uid',
),
// Information for accepting a uid as a filter
'filter' => array(
......
......@@ -8,9 +8,9 @@
?>
<?php print $rearrange; ?>
<?php print $add; ?>
<div class="views-category-title" <?php if ($overridden) { print ' class="overridden"'; }?>>
<div class="views-category-title<?php if ($overridden) { print ' overridden'; }?>">
<?php print $title; ?>
</div>
</div>
<?php if (empty($fields)): ?>
<div><?php print t('None defined'); ?></div>
......
......@@ -22,35 +22,35 @@
<?php // left section ?>
<div class="left tab-section">
<div class="inside">
<?php // If this is the default display, add some basic stuff here. ?>
<?php if ($default): ?>
<div class="views-category">
<div class="views-category-title"><?php print t('View settings'); ?></div>
<div class="<?php $details_class; ?>">
<?php print $details ?>
</div>
</div>
<?php endif; ?>
<?php // If this is the default display, add some basic stuff here. ?>
<?php if ($default): ?>
<div class="views-category">
<div class="views-category-title"><?php print t('View settings'); ?></div>
<div class="<?php $details_class; ?>">
<?php print $details ?>
</div>
</div>
<?php endif; ?>
<?php foreach ($categories as $category_id => $category): ?>
<div class="views-category">
<div class="views-category-title views-category-<?php print $category_id; ?>">
<?php print $category['title']; ?>
</div>
<?php foreach ($category['data'] as $data): ?>
<div class="<?php print $data['class']; if (!empty($data['overridden'])) { print ' overridden'; }?>">
<?php print $data['links'] . $data['content'] ?>
</div>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
</div>
<?php foreach ($categories as $category_id => $category): ?>
<div class="views-category">
<div class="views-category-title views-category-<?php print $category_id; ?>">
<?php print $category['title']; ?>
</div>
<?php foreach ($category['data'] as $data): ?>
<div class="<?php print $data['class']; if (!empty($data['overridden'])) { print ' overridden'; }?>">
<?php print $data['links'] . $data['content'] ?>
</div>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
</div>
</div>
<?php // middle section ?>
<div class="middle tab-section">
<div class="inside">
<div class="views-category">
<div class="views-category">
<?php print $relationships; ?>
</div>
<div class="views-category">
......
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