Needs work
Project:
Drupal core
Version:
main
Component:
views.module
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
22 Jun 2017 at 04:54 UTC
Updated:
27 Mar 2026 at 13:48 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #3
tamarpe commentedBased on
https://www.drupal.org/node/1793500
With the patch you be able to adjust it in the view settings as admin.
Comment #4
tamarpe commentedComment #5
fcastand commentedComment #6
fcastand commentedHello team,
I needed to have plural on my results count in Views for 8.3.7 version of Drupal.
I had an error when applying the patch for 8.4 version , so I adapted it for 8.3.7.
Comment #7
fcastand commentedComment #8
julbo commentedHi !
With the patch in https://www.drupal.org/node/2888320#comment-12303083 when there is 0 result it is in plural whereas it has to be singular IMO.
So here a new patch for Drupal 8.3.x with an interdiff.
We have the same issue with the patch in https://www.drupal.org/node/2888320#comment-12226674 so I'll update it sooner.
Comment #9
julbo commentedThe is the new patch with the fix (https://www.drupal.org/node/2888320#comment-12340067) in 8.4.x version with the interdiff.
Thanks
Comment #10
scuba_fly+1 RTBC Works for me.
Also 0 gives the plural 'results'
Comment #11
lendudeSeems like a feature request more then a task. New features go into the development branch, 8.5.x at the moment.
Some feedback on the current patch:
all arrays need to be updated to the short [] notation
Would be nice to have some #states on these fields and only show them when 'format_plural' is checked
This comment is not very helpful
We'd need test coverage for this and an upgrade path for the new settings.
Comment #13
stephenrodrigo@yahoo.com commentedFixed the following feedback given by @Lendude.
1 - Fixed all the arrays with short [] notation.
2 - Added drupal #states and only show relevant field when 'format_plural' is checked.
3 - Update the comment.
Comment #14
stephenrodrigo@yahoo.com commentedComment #15
dakwamineDoes the patch support translation? I couldn't find any field to configure the plural translation.
Comment #16
dakwamineI have added to views.area.schema.yml the plural field in order to get this same field translatable.
I removed a value (
translatable => TRUE) from the defineOptions method which does not have any impact on the translatability of the field. If I am wrong, you can restore this line (check the interdiff for details).I added a line break to a comment to respect code standard (phpcs).
Comment #18
lfilipov commentedWe had a project where we had to show different messages for plural forms but we also had to cover the case where there are *0 results*. This patch did the trick for me.
Comment #19
andypostShould be
$this->t()Comment #20
andypostNeeds work for tests, upgrade path & naming
Bad naming, suggestion is "format_plural_text"
This options also needs config schema
Comment #21
mattdanger commentedThis patch worked great for me. I've attached a slightly updated version with feedback from andypost.
Comment #22
jim.m commentedAttaching an updated patch of the one posted in #21 by MattDanger.
Every language has a different pluralization formula. It's not enough to just check if the number is more than 1 to decide which variant to show. Even for English this approach fails for zero results. In order to use the formulas, the updated patch uses
PluralTranslatableMarkup::createFromTranslatedString(), as the view gets translated with the config translation.Comment #23
davidferlay commentedHeader UI in view
Single/plural string translation
Comment #24
davidferlay commentedComment #25
alexpott@davidferlay thanks for the manual tests but we also need automated test coverage of new features. For more information about writing tests in Drupal 8 see the following links:
Also as per @Lendude we need an upgrade path.
Comment #27
dorian.dirusso commentedHello,
Here is a patch to provide automated tests. I have been helped by https://www.drupal.org/u/grimreaper.
But I don't find any existing test to guide me to test that the plugin is translatable.
I will try to search for an upgrade path.
Thanks for any help on the upgrade path and the translation tests.
Comment #29
dorian.dirusso commentedHello,
We tried to fix problems with test and we found a solution for an upgrade path
I put this in this new patch.
Thanks for the review.
Comment #31
dorian.dirusso commentedSorry,
I forgot to insert the original modifications. I re-upload the patch with all the changes.
Comment #32
blake.thompson commentedI've tested the patch in #31 and it appears to work for plural formatting, but there doesn't seem to be any support for non result summary tokens. The issue title seems to imply that there was a desire to support other tokens but maybe I'm misunderstanding. Is there any reason this views area shouldn't be extending TokenizeAreaPluginBase instead and calling tokenizeValue() on the output?
Comment #33
blake.thompson commentedAdding patch with token support in case it's useful.
Comment #35
dorian.dirusso commentedHello,
I have test your code and its works, but you have forgotten the views test. I add it. The test works now.
Thanks for the review.
Comment #36
dorian.dirusso commentedComment #39
grimreaperComment #40
grimreaperHello,
Here is an updated patch from comment 35.
I found that it was missing "tokenize" key in the config has now the Result plugin extends TokenizeAreaPluginBase.
Comment #42
grimreaperComment #43
grimreaperFixing schema.yml
Comment #45
grimreaperComment #46
grimreaperFixed Unit tests.
Comment #47
grimreaperTests are green \o/!!! Finally...
Comment #48
lendudeI think 'special handling' is too vague, can we get a clearer description of what this does?
This could be clearer too, reading this it's not immediately obvious to me how to use this.
Can we make this a post_update function and use ConfigEntityUpdater? See \views_post_update_limit_operator_defaults
Also this still needs an update test.
Comment #49
grimreaperComment #50
grimreaperComment 48 taken into account.
Unfortunately I have the update test failing locally, the new update hook is not detected. I will see with testbot if it comes from my setup.
Also catched that the tokenize key was not inited with the previous update hook.
Comment #51
grimreaperRebasing patch.
Conflict in the views.post_update.php file.
Comment #53
grimreaperComment #55
grimreaperAnd here is a new patch.
Not putting an interdiff because of the new strategy decided with Lendude => Creating a new dedicated plugin.
So it is a completely new patch.
Maybe the issue title should be changed.
Comment #56
lendudeJust to explain the reasoning behind the new plugin approach:
- way less disruptive
- no update paths needed
- Much much much clearer UI (the modal for the previous patches was pretty hard to read)
Will try to do a proper review soon
Comment #57
grimreaperComment #58
rachel_norfolkretagging
Comment #59
lendudeThis looks great. Some nits:
This needs to explain what it does not why it exists :)
Both test methods have the same doc bloc, maybe specify which part they are testing
Can we give a better explanation here then just (Plural handled)?
"Shows result summary, for example the items per page, with support for having singular and plural text depending on the number of results."
I don't know, something like that? Just to make it clearer what the difference is between the two plugins.
Also, can we get some fresh screenshot of the new plugin, the ones in #23 are no longer relevant but they provide a nice arguments for the new plugin when combined with the new screenshots I feel.
Comment #60
grimreaperHello,
Thanks @Lendude for the review :)
1: Done, hope it is ok.
2: Done
3: Done, your sentence is better, I just didn't know that it was ok to have long sentence.
And screenshots attached.
Comment #61
idebr commentedIt would be nice if the default value for the plural actually used a different text to showcase the difference with the current plugin.
Suggestion singular form:
Displaying 1 result.Suggestion plural form:
Displaying @count results.Comment #62
grimreaperThanks @idebr for the review.
Marking as RTBC to get feedback from maintainer before implementing your suggestion.
Comment #64
swatichouhan012 commentedRe-roll patch #60
Comment #66
Clauce commentedThanks for this great work. I have been using this patch for a long time now.
But sadly, it's not working anymore since 8.8.4 Drupal core, neither with 8.9.x.
Comment #67
ridhimaabrol24 commentedFixing failed tests.
Comment #69
snehalgaikwad commentedComment #71
grimreaperHello,
Why making this change? (comment 67)
Comment #72
grimreaperHello,
Ok I got it.
PluralTranslatableMarkup::DELIMITERwas deprecated.As there is no interdiff in comment 64, I tried to apply patch from comment 60 on 9.2.x which still applies, so I don't understand the comment from patch 64.
And I confirm that I obtain the same code as patch from comment 59. after updating the deprecated code.
So back to RTBC to have maintainers feedbacks.
Comment #73
alexpottThis is super tricky but this is not how we should be doing this. The problem is that this needs to be translatable so we need to be mindful of multiple plural forms for different languages. See \Drupal\views\Plugin\views\field\NumericField::buildOptionsForm() for an example of the work we need to do here to support multiple plural forms.
Comment #75
philyWith no opinion on the cleanliness of the code, patch #69 seems to be working on a Drupal 9.2.2 website using English & French languages (translated plural field follows language as expected).
Comment #77
matroskeenAttaching a re-roll of #69 for 9.3.x. Still needs work for #73
Comment #78
matroskeenAha! The use of
Drupal\views\Plugin\views\area\Xsswas removed in #2569381: Drupal\views\Plugin\views\area\Result does an unnecessary XSS::adminFilter() . Now we have to restore it here.Uploading a new patch for 9.3.x.
Comment #80
chop commentedHave been using this patch at #78 for a while.
Would like to see addition of one more token that will number format the "total" token with a thousands separator.
Could be something like: @format_total
with a replacement like:
Would that be okay to add within this issue and proposed patch?
Comment #82
chop commentedThe merge request at #81 applies patch #78 with the following additions
Comment #83
chop commentedtest failures picked up problems with the naming of the new token and the formatting call.
Fixed those now, rebased and queued for testing again.
Comment #84
chop commentedSome thoughts:
Comment #85
philyedited wrong post
Comment #86
jelle_sRE #78: it was removed for a reason, so it shouldn't be restored I think, but removed from this patch/MR as well?
Comment #89
henry tran commentedWe are still using the patch, so I re-rolled the patch to Drupal 10.1
Comment #90
henry tran commentedComment #91
philyPatch #90 works for me using Drupal 10.1.5
Comment #92
jelle_sReroll for 10.3.x
Comment #93
dark05 commentedHello, I'm upgrade my project with Drupal 10.3 but patchs (#78 and #90) are not compatible with them.
Can I fix the problem? Thanks
Comment #94
dark05 commentedPatch #92 works for me with Drupal 10.3
Comment #95
philyPatch #92 works for me with Drupal 10.3
Comment #96
philyPatch #92 works for me with Drupal 10.4.0 as well ;-)
Comment #97
ckaotikI've updated #92 to the new object oriented hook implementations in Drupal 11.1.
Comment #98
philyPatch #97 works for me using Drupal 11.1.2 😋
Comment #100
philyPatch #97 still works for me using Drupal 11.1.7 😋 while MR!2422 doesn't apply (patching using cweagans/composer-patches).
Comment #104
prudloff commentedI created a new MR based on the latest patch.
Comment #105
joachim commentedWhat's the point of having a second ResultPlural class parallel to the existing one? I can't figure out what's different about it from reading the plugin docs anyway. Why not put all the functionality in the existing one?
Also, changing the issue title, as the IS and the MR don't do anything to add tokens.
Comment #106
prudloff commentedThis is explained in #56.
Comment #107
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #108
prudloff commentedI merged the latest 11.x.
Comment #109
smustgrave commentedLeft comments on the MR.
Comment #110
waropd commentedUpdated patch for D11.3
Comment #111
idebr commented11.x-dev is the correct target version. You can open a 11.3.x branch for a version-specific MR if necessary
Comment #112
philyPatch #110 working for me using Drupal 11.3.2
Comment #114
prudloff commentedThe new @format_total token feels out of scope. Should it be separated into its own issue?
Comment #115
jonasanne commentedUploading MR diff as patch (applies to 11.3.5)
Comment #116
prudloff commentedI created a separate issue for the @format_total token: #3581884: Add new @format_total token to Views Global result summary plugin
And removed it from this MR.