summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.txt3
-rw-r--r--handlers/views_handler_filter_boolean_operator.inc73
-rw-r--r--includes/admin.inc3
-rw-r--r--modules/comment.views.inc1
-rw-r--r--modules/node.views.inc4
-rw-r--r--modules/poll.views.inc11
-rw-r--r--modules/translation.views.inc1
-rw-r--r--modules/upload.views.inc2
-rw-r--r--modules/user.views.inc3
9 files changed, 80 insertions, 21 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index ccb9bb3..019565a 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -44,4 +44,5 @@ Views 2.2
Other changes:
o Reorganize the analysis code into analyze.inc to make it easier for
people to find the code and use it externally.
- o #298884 (by neclimdul): Requested missing filter to filter for whether a user has a picture or not. \ No newline at end of file
+ o #298884 (by neclimdul): Requested missing filter to filter for whether a user has a picture or not.
+ o #336531 (by dww): Set boolean filter to not use a checkbox which is lesser UI. \ No newline at end of file
diff --git a/handlers/views_handler_filter_boolean_operator.inc b/handlers/views_handler_filter_boolean_operator.inc
index 82ee285..418930a 100644
--- a/handlers/views_handler_filter_boolean_operator.inc
+++ b/handlers/views_handler_filter_boolean_operator.inc
@@ -5,6 +5,10 @@
*
* Definition items:
* - label: (REQUIRED) The label for the checkbox.
+ * - type: For basic 'true false' types, an item can specify the following:
+ * - true-false: True/false (this is the default)
+ * - yes-no: Yes/No
+ * - on-off: On/Off
*/
class views_handler_filter_boolean_operator extends views_handler_filter {
// exposed filter options
@@ -17,9 +21,38 @@ class views_handler_filter_boolean_operator extends views_handler_filter {
if (isset($this->definition['label'])) {
$this->value_value = $this->definition['label'];
}
+ $this->value_options = NULL;
parent::construct();
}
+ /**
+ * Return the possible options for this filter.
+ *
+ * Child classes should override this function to set the possible values
+ * for the filter. Since this is a boolean filter, the array should have
+ * two possible keys: 1 for "True" and 0 for "False", although the labels
+ * can be whatever makes sense for the filter. These values are used for
+ * configuring the filter, when the filter is exposed, and in the admin
+ * summary of the filter. Normally, this should be static data, but if it's
+ * dynamic for some reason, child classes should use a guard to reduce
+ * database hits as much as possible.
+ */
+ function get_value_options() {
+ if (isset($this->definition['type'])) {
+ if ($this->definition['type'] == 'yes-no') {
+ $this->value_options = array(1 => t('Yes'), 0 => t('No'));
+ }
+ if ($this->definition['type'] == 'on-off') {
+ $this->value_options = array(1 => t('On'), 0 => t('Off'));
+ }
+ }
+
+ // Provide a fallback if the above didn't set anything.
+ if (!isset($this->value_options)) {
+ $this->value_options = array(1 => t('True'), 0 => t('False'));
+ }
+ }
+
function option_definition() {
$options = parent::option_definition();
@@ -33,32 +66,44 @@ class views_handler_filter_boolean_operator extends views_handler_filter {
}
function value_form(&$form, &$form_state) {
- if (empty($this->options['exposed'])) {
- $form['value'] = array(
- '#type' => 'checkbox',
- '#title' => $this->value_value,
- '#default_value' => $this->value,
- );
+ if (empty($this->value_options)) {
+ // Initialize the array of possible values for this filter.
+ $this->get_value_options();
+ }
+ if (!empty($form_state['exposed'])) {
+ // Exposed filter: use a select box to save space.
+ $filter_form_type = 'select';
}
else {
- $form['value'] = array(
- '#type' => 'select',
- '#title' => $this->value_value,
- '#options' => array(1 => t('Yes'), 0 => t('No')),
- '#default_value' => $this->value,
- );
+ // Configuring a filter: use radios for clarity.
+ $filter_form_type = 'radios';
+ }
+ $form['value'] = array(
+ '#type' => $filter_form_type,
+ '#title' => $this->value_value,
+ '#options' => $this->value_options,
+ '#default_value' => $this->value,
+ );
+ if (!empty($this->options['exposed'])) {
$identifier = $this->options['expose']['identifier'];
if (!isset($form_state['input'][$identifier])) {
$form_state['input'][$identifier] = $this->value;
}
}
}
+
function admin_summary() {
if (!empty($this->options['exposed'])) {
return t('exposed');
}
-
- return (empty($this->value) ? t("False") : t('True'));
+ if (empty($this->value_options)) {
+ $this->get_value_options();
+ }
+ // Now that we have the valid options for this filter, just return the
+ // human-readable label based on the current value. The value_options
+ // array is keyed with either 0 or 1, so if the current value is not
+ // empty, use the label for 1, and if it's empty, use the label for 0.
+ return $this->value_options[!empty($this->value)];
}
function expose_options() {
diff --git a/includes/admin.inc b/includes/admin.inc
index 10e49e8..a49b155 100644
--- a/includes/admin.inc
+++ b/includes/admin.inc
@@ -700,7 +700,8 @@ function views_ui_export_page(&$form_state, $view) {
'#type' => 'textarea',
'#title' => $view->name,
'#default_value' => $code,
- '#rows' => $lines);
+ '#rows' => $lines,
+ );
return $form;
}
diff --git a/modules/comment.views.inc b/modules/comment.views.inc
index 5237a2c..2d69bff 100644
--- a/modules/comment.views.inc
+++ b/modules/comment.views.inc
@@ -155,6 +155,7 @@ function comment_views_data() {
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Moderated'),
+ 'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
diff --git a/modules/node.views.inc b/modules/node.views.inc
index 63f3e38..e9e476b 100644
--- a/modules/node.views.inc
+++ b/modules/node.views.inc
@@ -165,6 +165,7 @@ function node_views_data() {
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Published'),
+ 'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
@@ -193,6 +194,7 @@ function node_views_data() {
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Promoted to front page'),
+ 'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
@@ -211,6 +213,7 @@ function node_views_data() {
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Moderated'),
+ 'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
@@ -229,6 +232,7 @@ function node_views_data() {
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Sticky'),
+ 'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
diff --git a/modules/poll.views.inc b/modules/poll.views.inc
index f3656f7..a25bdb6 100644
--- a/modules/poll.views.inc
+++ b/modules/poll.views.inc
@@ -41,11 +41,12 @@ function poll_views_data() {
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
- ),
- 'filter' => array(
- 'handler' => 'views_handler_filter_boolean_operator',
- 'label' => t('Active'),
- ),
+ ),
+ 'filter' => array(
+ 'handler' => 'views_handler_filter_boolean_operator',
+ 'label' => t('Active'),
+ 'type' => 'yes-no',
+ ),
'sort' => array(
'handler' => 'views_handler_sort',
),
diff --git a/modules/translation.views.inc b/modules/translation.views.inc
index 69926c0..cbba2c5 100644
--- a/modules/translation.views.inc
+++ b/modules/translation.views.inc
@@ -104,6 +104,7 @@ function translation_views_data_alter(&$data) {
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Published'),
+ 'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
diff --git a/modules/upload.views.inc b/modules/upload.views.inc
index d795620..8eabee7 100644
--- a/modules/upload.views.inc
+++ b/modules/upload.views.inc
@@ -80,6 +80,7 @@ function upload_views_data() {
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Published'),
+ 'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
@@ -119,6 +120,7 @@ function upload_views_data_alter(&$data) {
'filter' => array(
'handler' => 'views_handler_filter_upload_fid',
'title' => t('Has attached files'),
+ 'type' => 'yes-no',
'help' => t('Only display items with attached files. This can cause duplicates if there are multiple attached files.'),
),
'relationship' => array(
diff --git a/modules/user.views.inc b/modules/user.views.inc
index abf6ef4..7f8db96 100644
--- a/modules/user.views.inc
+++ b/modules/user.views.inc
@@ -71,6 +71,7 @@ function user_views_data() {
'help' => t('Filter the view to the currently logged in user.'),
'filter' => array(
'handler' => 'views_handler_filter_user_current',
+ 'type' => 'yes-no',
),
);
@@ -119,6 +120,7 @@ function user_views_data() {
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator_string',
'label' => t('Has Avatar'),
+ 'type' => 'yes-no',
),
);
@@ -182,6 +184,7 @@ function user_views_data() {
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Active'),
+ 'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',