Skip to content
Snippets Groups Projects
Commit cebf0f07 authored by Damian Lee's avatar Damian Lee 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
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -378,6 +378,17 @@ function get_value($values, $field = NULL) { ...@@ -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() { function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
......
...@@ -976,8 +976,17 @@ function get_handlers($type) { ...@@ -976,8 +976,17 @@ function get_handlers($type) {
/** /**
* Retrieve a list of fields for the current display with the * 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() { 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(); $options = array();
foreach ($this->get_handlers('relationship') as $relationship => $handler) { foreach ($this->get_handlers('relationship') as $relationship => $handler) {
if ($label = $handler->label()) { if ($label = $handler->label()) {
...@@ -989,6 +998,10 @@ function get_field_labels() { ...@@ -989,6 +998,10 @@ function get_field_labels() {
} }
foreach ($this->get_handlers('field') as $id => $handler) { 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()) { if ($label = $handler->label()) {
$options[$id] = $label; $options[$id] = $label;
} }
......
...@@ -187,9 +187,8 @@ function options_form(&$form, &$form_state) { ...@@ -187,9 +187,8 @@ function options_form(&$form, &$form_state) {
// @TODO: Document "uses grouping" in docs.php when docs.php is written. // @TODO: Document "uses grouping" in docs.php when docs.php is written.
if ($this->uses_fields() && $this->definition['uses grouping']) { if ($this->uses_fields() && $this->definition['uses grouping']) {
$options = array('' => t('- None -')); $options = array('' => t('- None -'));
$field_labels = $this->display->handler->get_field_labels(); $field_labels = $this->display->handler->get_field_labels(TRUE);
$options += $field_labels; $options += $field_labels;
// If there are no fields, we can't group on them. // If there are no fields, we can't group on them.
if (count($options) > 1) { if (count($options) > 1) {
// This is for backward compability, when there was just a single select form. // This is for backward compability, when there was just a single select form.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment