I have a node display with a "content statistics: total views" field. It's set for "thousand marker = comma" and "format plural: 1 view, @count views".
If the number is over a thousand it will show "1 view" instead of "1280 views" for example.
When I set the "thousand marker = none" it will show "1280 views" correctly. Same issue with "space" or "apostrophe". "Decimal" however works correctly ...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rich.3po’s picture

Also getting this problem. It also seems that if the node views go over 1999 the problem goes away

mikeskull’s picture

Guys, after some debugging it seems the problem is in core or at least with what the views numeric handler is passing to core (format_plural)

At the top of format_plural is:

function format_plural($count, $singular, $plural, array $args = array(), array $options = array()) {
  $args['@count'] = $count;
  if ($count == 1) {
    return t($singular, $args, $options);
  }

if you print $count when you have a comma seperator itll return 1,001 this is ==1 but is not === 1 so either core has to change to check on type and value or view handler has to passs an actual number.

Problem is on line 125 of views_handler_field_numeric.inc.

mradcliffe’s picture

Version: 7.x-3.3 » 7.x-3.x-dev

I don't think there is a good way to solve this issue without rewriting the entire render function, or doing an API breaking hack that simply concatenates the value and the format plural string (without the value). I don't see any way of making this change that won't break people's views who may be using plural formatting.

The summary of the bug is that the separator configuration is incompatible with precision or plural formatting.

This also applies to Drupal 8, which is a core issue now.

mradcliffe’s picture

On second thought, I think this is probably a bug in Drupal core with format_plural(). Especially if it supports 10,000, but not 1,001.

Jan van Diepen’s picture

Came across the issue and I need it fixed or I need a patch which I can access for an installation profile.

Here's a quick fix that won't break any existing views.

This patch was sponsored by NDITech, the technical department of the National Democratic Insitute.

Jan van Diepen’s picture

Sorry, I put a wrong patch.

Here's the correct patch.

Jan van Diepen’s picture

Status: Active » Needs review
saurabh.dhariwal’s picture

#6 Patch is working fine with 7.x-3.13 but for 7.x-3.14 patch is not working. Changes would not be reflected without applying patch.

saurabh.dhariwal’s picture

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

Status: Reviewed & tested by the community » Needs review

If there is an issue with the patch in #6 when applying to "7.x-3.x" branch, then the issue should be changed to "Needs work". The "Reviewed & tested by the community" status should be used when a patch is ready to be committed. It does not seem from your comment that the patch is ready to be committed.

If the patch applies to 7.x-3.x and fixes the issue, maybe change the issue to RTBC. If not, then the issue should be in Needs Work.

silvi.addweb’s picture

Chris Matthews’s picture

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

The 2 year old patch in #11 to views_handler_field_numeric.inc does not apply to the latest views 7.x-3.x-dev and if still relevant needs to be rerolled.

format_plural_cuts_of-1515834-11.patch:16: trailing whitespace.
	
Checking patch handlers/views_handler_field_numeric.inc...
error: while searching for:

  function render($values) {
    $value = $this->get_value($values);

    // Hiding should happen before rounding or adding prefix/suffix.
    if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) {
      return '';
    }

    if (!empty($this->options['set_precision'])) {
      $value = number_format($value, $this->options['precision'], $this->options['decimal'], $this->options['separator']);
    }

error: patch failed: handlers/views_handler_field_numeric.inc:107
error: handlers/views_handler_field_numeric.inc: patch does not apply
ciss’s picture

@Chris2 What you're doing here may actually cause harm. In the above case you've indiscrimenately hidden all files from #11, making #6 the most recent patch at the top of the issue.

Please go through all issues that you've updated over the past several days (weeks?) and unhide any files that were hidden by your script.

Chris Matthews’s picture

Understood, I was doing this manually but I can go back and edit.

ciss’s picture

Understood, I was doing this manually but I can go back and edit.

Thank you. If you need to review your comments, I've created a small online helper.

Andrew Answer’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
2.03 KB

Patch rerolled.

Andrew Answer’s picture

Wrong patch attached previously, this is right (from #6).