A common use for the results handler is to display the number of results returned by the last query. The text used for this should often differ depending on whether the total is singular or plural. Patch to follow.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Darren Oh’s picture

The attached patch enables the admin to choose which token will trigger the plural format. It also lets the admin choose to display the results area when the view is empty, unless no query has been executed.

Darren Oh’s picture

Status: Active » Needs review
dawehner’s picture

Status: Needs review » Needs work
+++ b/handlers/views_handler_area_result.incundefined
@@ -87,8 +124,11 @@ class views_handler_area_result extends views_handler_area {
+    if (!empty($this->options['format_plural']) && $replacements[$this->options['format_plural_count']] != 1) {

There so no way to select no plural token so this check seems a bit redundant.

+++ b/handlers/views_handler_area_result.incundefined
@@ -87,8 +124,11 @@ class views_handler_area_result extends views_handler_area {
+    if (!empty($total) || !empty($this->options['empty']) && !empty($this->view->build_info['count_query'])) {

This change seems to be unrelated ...

Darren Oh’s picture

Status: Needs work » Needs review

1) It is necessary to check both whether the plural form has been enabled and whether the selected token is plural.
2) 0 is a valid plural format. We should distinguish between 0 results returned and the query not being executed. I agree that this also addresses the separate problem that the "Show even if empty" setting is available but not respected. There is no open issue for that problem, and it does not require a separate patch.

acrollet’s picture

Version: 7.x-3.5 » 7.x-3.x-dev
Status: Needs review » Reviewed & tested by the community

Patch in #1 applies cleanly and works well for me.

juahoo’s picture

#1 works for me, thanks.

juahoo’s picture

This is a good and useful feature. I vote that it be added to Views.

mattcoker’s picture

Issue summary: View changes

This is working great for me, recommend merging into Views

sirtet’s picture

Tested on simplytest.me, works great.

Maybe the help-text's could be a bit more clear about the Format plural field being used instead of the default Display Field.
And maybe
Token used to detect the plural format vs.
Token used to select the plural format


See the different Header- text's in the preview-area (darkened by the overlay), singular above, plural below:

dawehner’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/handlers/views_handler_area_result.inc
@@ -87,8 +124,11 @@ class views_handler_area_result extends views_handler_area {
+    if (!empty($this->options['format_plural']) && $replacements[$this->options['format_plural_count']] != 1) {
...
+    if (!empty($total) || !empty($this->options['empty']) && !empty($this->view->build_info['count_query'])) {

We should have at least some documentation of what is going on.

MatthewHager’s picture

Works for me, recommend merge.

joelpittet’s picture

It sounds like D8 has some neat "true" pluralizing for multilingual as other languages have non-binary decisions for the pluralization.

@MatthewHager We can likely get this in D7 if someone documents those lines as @dawehner mentioned in #10 Maybe you want to give it a try?

This likely couldn't be put in D8 in the same way though...

loopduplicate’s picture

Added some comments per #10 and #12

Nixou’s picture

Status: Needs review » Reviewed & tested by the community

Works for me since a year now.

It would be nice to merge this and avoid to reapply patch after each security update.

=> RTBC

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 13: views-area-results-plural-1793500-13.patch, failed testing. View results

SaytO’s picture

Added an updated patch for the new version of views.

DamienMcKenna’s picture

Status: Needs work » Needs review

Thanks @SaytO. Let's see what testbot says.

DamienMcKenna’s picture

This looks pretty good, thank you all for working on it.

My one concern is around this line:

+ && !empty($this->view->build_info['count_query'])

It changes the logic every so slightly and I wonder if it should be handled as a separate request.

PhilY’s picture

Patch #16 by SaytO seems to be working fine on Drupal 7.69 and Views 7.x-3.23
Thanks

julia.klimovsky’s picture

Reroll patch to version 7.x-3.24

PhilY’s picture

Patch #20 works with Views 7.x-3.24, thanks.

Darren Oh’s picture

Status: Needs review » Reviewed & tested by the community
mvc’s picture

Patch #20 works for us too (slightly modified for 7.x-3.20), although I'll note that this doesn't help you if you're inserting multiple tokens, each of which can have a plural or singular form. But that would require far more complexity and this meets the large majority of use cases, so it would be great to have it included.

renatog’s picture

It worked here as well. +1 to it

Thank you so much, everyone.

renatog’s picture

Status: Reviewed & tested by the community » Fixed

Moved to the dev branch

DamienMcKenna’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.