Problem/Motivation

The "Result summary" view area does not provide a way to have a different text for singular and plural.
For example: 1 result vs. 2 results

Currently we have to use text like "42 result(s)" which can be confusing for users.

Steps to reproduce

Edit a view display, try to add a "Result summary" area to the header of the view: you don't have a way to set a different text for singular or plural.

Proposed resolution

The MR adds a new result_plural view area that handles different texts for singular and plural.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#115 drupal-views-plural-support-2888320-115.patch18.88 KBjonasanne
#110 drupal-views-plural-support-2888320-110.patch19.57 KBwaropd
#107 2888320-nr-bot_y7u9tktz.txt91 bytesneeds-review-queue-bot
#97 2888320-97.patch19.56 KBckaotik
#90 2888320-90.patch19.41 KBhenry tran
#89 2888320-89.patch9.59 KBhenry tran
#82 interdiff-78-81.txt10.13 KBchop
#78 2888320-interdiff-77_78.txt500 bytesmatroskeen
#78 2888320-78.patch14.47 KBmatroskeen
#77 2888320-77.patch14.25 KBmatroskeen
#69 interdiff_67-69.txt536 bytessnehalgaikwad
#69 2888320-69.patch14.33 KBsnehalgaikwad
#67 interdiff_64-67.txt972 bytesridhimaabrol24
#67 2888320-67.patch14.27 KBridhimaabrol24
#64 2888320-64.patch14.31 KBswatichouhan012
#60 Capture d’écran de 2019-11-12 11-07-36.png134.19 KBgrimreaper
#60 Capture d’écran de 2019-11-12 11-07-27.png191.4 KBgrimreaper
#60 interdiff-2888320-55-60.txt2.01 KBgrimreaper
#60 drupal-views-plural-support-2888320-60.patch15.4 KBgrimreaper
#55 drupal-views-plural-support-2888320-55.patch15.34 KBgrimreaper
#53 interdiff-2888320-50-53.txt10.03 KBgrimreaper
#53 drupal-views-plural-support-2888320-53.patch26.51 KBgrimreaper
#51 drupal-views-plural-support-2888320-51.patch25.06 KBgrimreaper
#50 interdiff-2888320-46-50.txt11.41 KBgrimreaper
#50 drupal-views-plural-support-2888320-50.patch25.07 KBgrimreaper
#46 interdiff-2888320-43-46.txt1.4 KBgrimreaper
#46 drupal-views-plural-support-2888320-46.patch17.5 KBgrimreaper
#43 interdiff-2888320-40-43.txt586 bytesgrimreaper
#43 drupal-views-plural-support-2888320-43.patch16.04 KBgrimreaper
#40 interdiff-2888320-35-40.txt3.9 KBgrimreaper
#40 drupal-views-plural-support-2888320-40.patch15.94 KBgrimreaper
#35 views-plural-support-2888320-34.patch15.66 KBdorian.dirusso
#33 views-plural-support-with-tokens-2888320-33.patch11.61 KBblake.thompson
#31 views-plural-support-2888320-31.patch15.34 KBdorian.dirusso
#29 views-plural-support-2888320-29.patch10.79 KBdorian.dirusso
#27 views-plural-support-2888320-27.patch5.85 KBdorian.dirusso
#23 Screenshot (3).png97.27 KBdavidferlay
#23 Screenshot (2).png171.35 KBdavidferlay
#22 views-plural-support-2888320-22.patch4.79 KBjim.m
#21 views-support-plural-2888320-21.patch3.97 KBmattdanger
#16 interdiff-10-16.txt1.75 KBdakwamine
#16 views-support-plural-2888320-16.patch3.8 KBdakwamine
#13 views-support-plural-2888320-10.patch3.3 KBstephenrodrigo@yahoo.com
#9 interdiff-2888320-3-9.txt807 bytesjulbo
#9 views-support-plural-2888320-9.patch3 KBjulbo
#8 interdiff-2888320-5-8.txt807 bytesjulbo
#8 do-not-test-d8.3-views-support-plural-2888320-8.patch2.98 KBjulbo
#5 views-support-plural-2888320.patch2.98 KBfcastand
#3 views-support-plural-2888320.patch3.01 KBtamarpe

Issue fork drupal-2888320

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

vaibhavjain created an issue. See original summary.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tamarpe’s picture

StatusFileSize
new3.01 KB

Based on
https://www.drupal.org/node/1793500

With the patch you be able to adjust it in the view settings as admin.

tamarpe’s picture

Status: Active » Needs review
fcastand’s picture

Version: 8.4.x-dev » 8.3.7
Category: Feature request » Task
Issue summary: View changes
StatusFileSize
new2.98 KB
fcastand’s picture

Issue summary: View changes

Hello 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.

fcastand’s picture

julbo’s picture

Hi !

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.

julbo’s picture

The is the new patch with the fix (https://www.drupal.org/node/2888320#comment-12340067) in 8.4.x version with the interdiff.

Thanks

scuba_fly’s picture

+1 RTBC Works for me.
Also 0 gives the plural 'results'

lendude’s picture

Version: 8.3.7 » 8.5.x-dev
Category: Task » Feature request
Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs upgrade path

Seems 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:

  1. +++ b/core/modules/views/src/Plugin/views/area/Result.php
    @@ -25,6 +25,12 @@ protected function defineOptions() {
    +    $options['format_plural'] = array('default' => FALSE, 'bool' => TRUE);
    +    $options['format_plural_count'] = array('default' => '@total');
    +    $options['format_plural_plural'] = array(
    
    @@ -47,6 +53,16 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    +    $format_plural_count_options = array(
    

    all arrays need to be updated to the short [] notation

  2. +++ b/core/modules/views/src/Plugin/views/area/Result.php
    @@ -55,6 +71,26 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    +    $form['format_plural_count'] = [
    ...
    +    $form['format_plural_plural'] = [
    

    Would be nice to have some #states on these fields and only show them when 'format_plural' is checked

  3. +++ b/core/modules/views/src/Plugin/views/area/Result.php
    @@ -112,6 +148,10 @@ public function render($empty = FALSE) {
    +    // If the format_plural option is selected.
    

    This comment is not very helpful

We'd need test coverage for this and an upgrade path for the new settings.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

stephenrodrigo@yahoo.com’s picture

StatusFileSize
new3.3 KB

Fixed 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.

stephenrodrigo@yahoo.com’s picture

Status: Needs work » Needs review
dakwamine’s picture

Does the patch support translation? I couldn't find any field to configure the plural translation.

dakwamine’s picture

StatusFileSize
new3.8 KB
new1.75 KB

I 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).

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

lfilipov’s picture

We 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.

andypost’s picture

+++ b/core/modules/views/src/Plugin/views/area/Result.php
@@ -55,6 +68,36 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
+      '#title' => t('Format plural'),
+      '#description' => t('If checked, special handling will be used for plurality.'),
...
+      '#title' => t('Count token'),
+      '#description' => t('Token used to select plural format.'),
...
+      '#description' => t('Text to use for the plural form.'),

Should be $this->t()

andypost’s picture

Status: Needs review » Needs work

Needs work for tests, upgrade path & naming

  1. +++ b/core/modules/views/config/schema/views.area.schema.yml
    @@ -50,6 +50,9 @@ views.area.result:
    +    format_plural_plural:
    
    +++ b/core/modules/views/src/Plugin/views/area/Result.php
    @@ -25,6 +25,9 @@ protected function defineOptions() {
    +    $options['format_plural_plural'] = ['default' => ''];
    
    @@ -55,6 +68,36 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    +    $form['format_plural_plural'] = [
    +      '#title' => t('Plural form'),
    ...
    +      '#description' => t('Text to use for the plural form.'),
    

    Bad naming, suggestion is "format_plural_text"

  2. +++ b/core/modules/views/src/Plugin/views/area/Result.php
    @@ -25,6 +25,9 @@ protected function defineOptions() {
    +    $options['format_plural'] = ['default' => FALSE, 'bool' => TRUE];
    +    $options['format_plural_count'] = ['default' => '@total'];
    

    This options also needs config schema

mattdanger’s picture

StatusFileSize
new3.97 KB

This patch worked great for me. I've attached a slightly updated version with feedback from andypost.

jim.m’s picture

StatusFileSize
new4.79 KB

Attaching 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.

davidferlay’s picture

StatusFileSize
new171.35 KB
new97.27 KB
  • We tested latest patch from comment above and it works great : 
    • Tested with a multi langual website (EN default lang + multiples translations)
    • String displayed as expected accordingly to result count and active lang

 

Header UI in view

view config ui

Single/plural string translation

view config translation ui

davidferlay’s picture

Status: Needs work » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Needs work

@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:

  1. https://www.drupal.org/docs/8/testing
  2. https://api.drupal.org/api/drupal/core%21core.api.php/group/testing/8.7.x

Also as per @Lendude we need an upgrade path.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dorian.dirusso’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new5.85 KB

Hello,

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.

Status: Needs review » Needs work

The last submitted patch, 27: views-plural-support-2888320-27.patch, failed testing. View results

dorian.dirusso’s picture

Status: Needs work » Needs review
Issue tags: -Needs upgrade path
StatusFileSize
new10.79 KB

Hello,

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.

Status: Needs review » Needs work

The last submitted patch, 29: views-plural-support-2888320-29.patch, failed testing. View results

dorian.dirusso’s picture

Status: Needs work » Needs review
StatusFileSize
new15.34 KB

Sorry,

I forgot to insert the original modifications. I re-upload the patch with all the changes.

blake.thompson’s picture

I'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?

return [
  '#markup' => $this->tokenizeValue($output),
];
blake.thompson’s picture

Adding patch with token support in case it's useful.

Status: Needs review » Needs work

The last submitted patch, 33: views-plural-support-with-tokens-2888320-33.patch, failed testing. View results

dorian.dirusso’s picture

Status: Needs work » Needs review
StatusFileSize
new15.66 KB

Hello,

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.

dorian.dirusso’s picture

Status: Needs review » Needs work

The last submitted patch, 35: views-plural-support-2888320-34.patch, failed testing. View results

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

grimreaper’s picture

Assigned: Unassigned » grimreaper
grimreaper’s picture

Assigned: grimreaper » Unassigned
Status: Needs work » Needs review
StatusFileSize
new15.94 KB
new3.9 KB

Hello,

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.

Status: Needs review » Needs work

The last submitted patch, 40: drupal-views-plural-support-2888320-40.patch, failed testing. View results

grimreaper’s picture

Assigned: Unassigned » grimreaper
grimreaper’s picture

Assigned: grimreaper » Unassigned
Status: Needs work » Needs review
StatusFileSize
new16.04 KB
new586 bytes

Fixing schema.yml

Status: Needs review » Needs work

The last submitted patch, 43: drupal-views-plural-support-2888320-43.patch, failed testing. View results

grimreaper’s picture

Assigned: Unassigned » grimreaper
grimreaper’s picture

Assigned: grimreaper » Unassigned
Status: Needs work » Needs review
StatusFileSize
new17.5 KB
new1.4 KB

Fixed Unit tests.

grimreaper’s picture

Tests are green \o/!!! Finally...

lendude’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/views/src/Plugin/views/area/Result.php
    @@ -55,6 +69,36 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    +      '#description' => $this->t('If checked, special handling will be used for plurality.'),
    

    I think 'special handling' is too vague, can we get a clearer description of what this does?

  2. +++ b/core/modules/views/src/Plugin/views/area/Result.php
    @@ -55,6 +69,36 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    +      '#description' => $this->t('Token used to select plural format.'),
    

    This could be clearer too, reading this it's not immediately obvious to me how to use this.

  3. +++ b/core/modules/views/views.install
    @@ -532,3 +532,44 @@ function views_update_8500() {
    +function views_update_8800() {
    +  $config_factory = \Drupal::configFactory();
    +
    +  foreach ($config_factory->listAll('views.view.') as $view_config_name) {
    

    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.

grimreaper’s picture

Assigned: Unassigned » grimreaper
grimreaper’s picture

Status: Needs work » Needs review
StatusFileSize
new25.07 KB
new11.41 KB

Comment 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.

grimreaper’s picture

Rebasing patch.

Conflict in the views.post_update.php file.

Status: Needs review » Needs work

The last submitted patch, 51: drupal-views-plural-support-2888320-51.patch, failed testing. View results

grimreaper’s picture

Status: Needs work » Needs review
StatusFileSize
new26.51 KB
new10.03 KB

Status: Needs review » Needs work

The last submitted patch, 53: drupal-views-plural-support-2888320-53.patch, failed testing. View results

grimreaper’s picture

Status: Needs work » Needs review
Issue tags: +DrupalCon Amsterdam 2019
StatusFileSize
new15.34 KB

And 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.

lendude’s picture

Just 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

grimreaper’s picture

Assigned: grimreaper » Unassigned
rachel_norfolk’s picture

Issue tags: -DrupalCon Amsterdam 2019 +Amsterdam2019

retagging

lendude’s picture

Status: Needs review » Needs work
Issue tags: +Needs screenshots

This looks great. Some nits:

  1. +++ b/core/modules/views/src/Plugin/views/area/Result.php
    @@ -75,53 +89,60 @@ public function render($empty = FALSE) {
    +   * Helper function for easier reusable code.
    

    This needs to explain what it does not why it exists :)

  2. +++ b/core/modules/views/tests/src/Kernel/Handler/AreaResultPluralTest.php
    @@ -0,0 +1,77 @@
    +  /**
    +   * Tests the results plural area handler.
    +   */
    +  public function testResult() {
    ...
    +  /**
    +   * Tests the results plural area handler.
    +   */
    +  public function testResultEmpty() {
    

    Both test methods have the same doc bloc, maybe specify which part they are testing

  3. +++ b/core/modules/views/views.views.inc
    @@ -97,6 +97,14 @@ function views_views_data() {
    +    'help' => t('Shows result summary, for example the items per page (Plural handled).'),
    

    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.

grimreaper’s picture

Hello,

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.

idebr’s picture

It 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.

grimreaper’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @idebr for the review.

Marking as RTBC to get feedback from maintainer before implementing your suggestion.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 60: drupal-views-plural-support-2888320-60.patch, failed testing. View results

swatichouhan012’s picture

Status: Needs work » Needs review
StatusFileSize
new14.31 KB

Re-roll patch #60

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Clauce’s picture

Thanks 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.

ridhimaabrol24’s picture

StatusFileSize
new14.27 KB
new972 bytes

Fixing failed tests.

Status: Needs review » Needs work

The last submitted patch, 67: 2888320-67.patch, failed testing. View results

snehalgaikwad’s picture

Status: Needs work » Needs review
StatusFileSize
new14.33 KB
new536 bytes

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

grimreaper’s picture

Issue tags: +Europe2020

Hello,

+++ b/core/modules/views/src/Plugin/views/area/ResultPlural.php
@@ -82,7 +82,7 @@ public function render($empty = FALSE) {
+        PoItem::DELIMITER,

Why making this change? (comment 67)

grimreaper’s picture

Status: Needs review » Reviewed & tested by the community

Hello,

Ok I got it. PluralTranslatableMarkup::DELIMITER was 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.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/views/src/Plugin/views/area/ResultPlural.php
@@ -0,0 +1,106 @@
+    $form['content_plural'] = [
+      '#type' => 'textarea',
+      '#title' => $this->t('Plural form'),
+      '#description' => $description,
+      '#default_value' => $this->options['content_plural'],
+      '#weight' => 10,
+      '#rows' => 3,
+    ];

This 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.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

phily’s picture

With 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).

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

matroskeen’s picture

Attaching a re-roll of #69 for 9.3.x. Still needs work for #73

matroskeen’s picture

StatusFileSize
new14.47 KB
new500 bytes

Aha! The use of Drupal\views\Plugin\views\area\Xss was 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.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

chop’s picture

Have 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:

number_format($total, '.', ',')

Would that be okay to add within this issue and proposed patch?

chop’s picture

StatusFileSize
new10.13 KB

The merge request at #81 applies patch #78 with the following additions

  • Fix plural count token option for @label (was @name)
  • Add new token @total_format -- the total records in the set (number formatted)
  • Update all tests
chop’s picture

test failures picked up problems with the naming of the new token and the formatting call.
Fixed those now, rebased and queued for testing again.

chop’s picture

Some thoughts:

  • Using the view label/name as a count token for plural seems odd. Maybe it shouldn't be an available option.
  • Would like to add token variations for @format_start @format_end to go with @format_total if okay
phily’s picture

edited wrong post

jelle_s’s picture

RE #78: it was removed for a reason, so it shouldn't be restored I think, but removed from this patch/MR as well?

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

henry tran’s picture

StatusFileSize
new9.59 KB

We are still using the patch, so I re-rolled the patch to Drupal 10.1

henry tran’s picture

StatusFileSize
new19.41 KB
phily’s picture

Patch #90 works for me using Drupal 10.1.5

jelle_s’s picture

StatusFileSize
new19.48 KB

Reroll for 10.3.x

dark05’s picture

Hello, 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

dark05’s picture

Patch #92 works for me with Drupal 10.3

phily’s picture

Patch #92 works for me with Drupal 10.3

phily’s picture

Patch #92 works for me with Drupal 10.4.0 as well ;-)

ckaotik’s picture

StatusFileSize
new19.56 KB

I've updated #92 to the new object oriented hook implementations in Drupal 11.1.

phily’s picture

Patch #97 works for me using Drupal 11.1.2 😋

prudloff made their first commit to this issue’s fork.

phily’s picture

Patch #97 still works for me using Drupal 11.1.7 😋 while MR!2422 doesn't apply (patching using cweagans/composer-patches).

prudloff changed the visibility of the branch 11.x to hidden.

prudloff changed the visibility of the branch 2888320-views-results-summary-plural to hidden.

prudloff’s picture

Issue summary: View changes
Status: Needs work » Needs review

I created a new MR based on the latest patch.

joachim’s picture

Title: Add support for Token and plural in Views Global result summary plugin » Add support for plural in Views Global result summary plugin

What'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.

prudloff’s picture

What's the point of having a second ResultPlural class parallel to the existing one?

This is explained in #56.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The 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.

prudloff’s picture

Status: Needs work » Needs review

I merged the latest 11.x.

smustgrave’s picture

Status: Needs review » Needs work

Left comments on the MR.

waropd’s picture

Version: 11.x-dev » 11.3.x-dev
StatusFileSize
new19.57 KB

Updated patch for D11.3

idebr’s picture

Version: 11.3.x-dev » 11.x-dev

11.x-dev is the correct target version. You can open a 11.3.x branch for a version-specific MR if necessary

phily’s picture

Patch #110 working for me using Drupal 11.3.2

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

prudloff’s picture

The new @format_total token feels out of scope. Should it be separated into its own issue?

jonasanne’s picture

Uploading MR diff as patch (applies to 11.3.5)

prudloff’s picture

I 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.