Commit cebf0f07 authored by damiankloip's avatar damiankloip Committed by tim.plunkett
Browse files

Issue #1548948 by damiankloip: Added ability for field handlers to declare...

Issue #1548948 by damiankloip: Added ability for field handlers to declare whether they can be 'grouped by' or not.
parent 51acc29b
......@@ -378,6 +378,17 @@ function get_value($values, $field = NULL) {
}
}
/**
* Determines if this field will be available as an option to group the result
* by in the style settings.
*
* @return bool
* TRUE if this field handler is groupable, otherwise FALSE.
*/
function use_string_group_by() {
return TRUE;
}
function option_definition() {
$options = parent::option_definition();
......
......@@ -975,9 +975,18 @@ function get_handlers($type) {
/**
* Retrieve a list of fields for the current display with the
* relationship associated if it exists.
* relationship associated if it exists.
*
* @param $groupable_only
* Return only an array of field labels from handler that return TRUE
* from use_string_group_by method.
*/
function get_field_labels() {
// Use func_get_arg so the function signature isn't amended
// but we can still pass TRUE into the function to filter
// by groupable handlers.
$groupable_only = func_get_arg(0);
$options = array();
foreach ($this->get_handlers('relationship') as $relationship => $handler) {
if ($label = $handler->label()) {
......@@ -989,6 +998,10 @@ function get_field_labels() {
}
foreach ($this->get_handlers('field') as $id => $handler) {
if ($groupable_only && !$handler->use_string_group_by()) {
// Continue to next handler if it's not groupable.
continue;
}
if ($label = $handler->label()) {
$options[$id] = $label;
}
......
......@@ -187,9 +187,8 @@ function options_form(&$form, &$form_state) {
// @TODO: Document "uses grouping" in docs.php when docs.php is written.
if ($this->uses_fields() && $this->definition['uses grouping']) {
$options = array('' => t('- None -'));
$field_labels = $this->display->handler->get_field_labels();
$field_labels = $this->display->handler->get_field_labels(TRUE);
$options += $field_labels;
// If there are no fields, we can't group on them.
if (count($options) > 1) {
// This is for backward compability, when there was just a single select form.
......
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