Problem/Motivation

My Webform has a "number of tickets" entry and I want to sum them to see how many were sold. It is an integer number

Steps to reproduce

I made a view with a table with aggregation. But when I view it, I get php errors:
Error TypeError: Argument 3 passed to
Drupal\views_aggregator\Plugin\views\style\Table::ren
derNewWebformValue() must be of the type array, float
given, called in /home/orcmaorg/public_html/web/m
563121 27/Mar 17:03 php Notice Notice: A non well formed numeric value encountered
in __TwigTemplate_a3a50bb5f1daf37aa981f1e2492ba954800060
3bd312153597618706fa350ce2->doDisplay() (line 44 of

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

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

tjtj created an issue. See original summary.

jordik’s picture

Status: Active » Postponed (maintainer needs more info)

Are using twig to rewrite the field output?
Please post the complete error message here and also your views configuration (the exported yml file).

tsmorisawa’s picture

Version: 8.x-1.0-beta2 » 2.0.x-dev
Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new1.1 KB

I was able to reproduce this issue in version 2.0.1 with the following steps:

  1. Create a simple webform with a "textfield" field and a "number" field.
  2. Create a view using the "Table with aggregation options" style.
  3. Using Webform Views, add the webform submission data fields to the view.
  4. In the style options, set the textfield to "Group and compress" and the number field to "Sum" for group aggregation.
  5. Create at least two submissions in the webform with the same value for the textfield.

It appears that function renderNewWebformValue is incorrectly set to only accept array parameters for $new_values. The function is already set to convert non-array values to arrays, so I believe the type hinting should be removed.

tsmorisawa’s picture

Apologies, I actually had a secondary issue after fixing the type hinting. Following the same steps to reproduce as in #3 after applying the patch, the view itself no longer throws an error, but number field appears blank in the view with the following notice in the log:
Notice: Undefined index: number in Drupal\views_aggregator\Plugin\views\style\Table->renderNewWebformValue() (line 1067 of /var/www/html/web/modules/contrib/views_aggregator/src/Plugin/views/style/Table.php)
where "number" is the key of the number field webform component.

jordik’s picture

Why did you remove the checks for the rendered values?

tsmorisawa’s picture

It looks as though none of those checks will ever return TRUE, as they are all contained within if blocks for elements within the $rendered array. That is, the only case where $rendered can ever be empty is in the else.

tr’s picture

I personally don't think that the magic method __toString() should ever be called directly. IMO if you want to coerce something to be a string you should use a cast.

tsmorisawa’s picture

StatusFileSize
new2.6 KB

Replaced __toString() calls with string casts per #7.

sl27257’s picture

+1 for patch #8

tr’s picture

Version: 2.0.x-dev » 2.1.x-dev

tr’s picture

Title: Type Error » Type Error when using Webform fields
Status: Needs review » Needs work
Issue tags: +Needs tests

I moved this to the current branch of this module, and I re-rolled the patch from #8 and put it into a MR so that it can be tested on GitLab CI.

None of the Wbform-specific code in this module is currently being tested at all. It is not maintainable. If we are going to make exceptions for Webform fields then we really really really need test cases for those exceptions. Can you write a simple test for this, hopefully without requiring the test to have a full install of Webform?

sl27257’s picture

Hi,
I am sorry, I used this in an event-site which now is removed. So unfortunately I have no easy way to write test code (and check that it behaves correctly for this case.)

/Thomas

sense-design’s picture

For there is still a bug, because of this error message
> Drupal\views_aggregator\Plugin\views\style\Table::renderNewWebformValue(): Argument #2 ($row_num) must be of type int, null given

changing this

protected function renderNewWebformValue(FieldHandlerInterface $field_handler, int $row_num, mixed $new_values, string $separator)

to this fixes it

protected function renderNewWebformValue(FieldHandlerInterface $field_handler, int|null $row_num, mixed $new_values, string $separator)

I added a comment to your merge request.

tr’s picture

@sense-design: The problem you stated in #14 is not the same as this issue.
Your problem is #3495283: TypeError: Drupal\views_aggregator\Plugin\views\style\Table::setCell(): Argument #2 ($row_num) must be of type int, null given, and you should read the discussion there and contribute to a solution in that issue.

sense-design’s picture

Oh sorry, missed that one. 👍