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
| Comment | File | Size | Author |
|---|
Issue fork views_aggregator-3206144
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
Comment #2
jordik commentedAre using twig to rewrite the field output?
Please post the complete error message here and also your views configuration (the exported yml file).
Comment #3
tsmorisawa commentedI was able to reproduce this issue in version 2.0.1 with the following steps:
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.
Comment #4
tsmorisawa commentedApologies, 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.
Comment #5
jordik commentedWhy did you remove the checks for the rendered values?
Comment #6
tsmorisawa commentedIt 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.
Comment #7
tr commentedI 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.
Comment #8
tsmorisawa commentedReplaced __toString() calls with string casts per #7.
Comment #9
sl27257+1 for patch #8
Comment #10
tr commentedComment #12
tr commentedI 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?
Comment #13
sl27257Hi,
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
Comment #14
sense-designFor 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.
Comment #15
tr commented@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.
Comment #16
sense-designOh sorry, missed that one. 👍