When rendering a aggregated view, some times this error occurs
TypeError: Drupal\views_aggregator\Plugin\views\style\Table::setCell(): Argument #2 ($row_num) must be of type int, null given, called in /var/www/site/releases/32/web/modules/contrib/views_aggregator/src/Plugin/views/style/Table.php on line 1191 in Drupal\views_aggregator\Plugin\views\style\Table->setCell() (line 780 of /var/www/site/releases/32/web/modules/contrib/views_aggregator/src/Plugin/views/style/Table.php).
In the views_aggregator/src/Plugin/views/style/Table.php line 1191, the setCell function is called with NULL as second parameter, and the definition of the function typecasts the parameter as INT, and therefore an exception is thrown.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | argument-2-must-be-af-type-int-3495283-10.patch | 619 bytes | ramlev |
Issue fork views_aggregator-3495283
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
tr commentedYes, the code appears to be wrong - adding the type case simply revealed the error. Can you post an export of a simple view that demonstrates the problem?
Comment #5
niharika.s commentedI have applied the changes according to the issue in Table.php file please review it.
Comment #6
tr commentedNo, that doesn't fix the problem, it just avoids an error message.
We already have
And $row_num is allowed to be NULL. So if it needs to be used in the else clause, that's where the change should be made. Setting $row_num to 0 is a huge assumption.
But more importantly, we have to first identify why this is a problem. Is it only when the table has no content so there are no rows? That's why I asked for an export of a simple view that demonstrates this problem. That way we can have a test that shows the problem, proves that the fix works, and prevents the problem from happening again in the future.
Comment #7
shamilto2000 commentedI was also having this error, but I was able to fix it by changing a setting in my view.
The format of the view is Table with Aggregation Options. Previously under Group aggregation options, I had checked "no aggregation, results will be shown after each group (like subtotals)." I have changed this to "results will be aggregated with one row per group."
This is not ideal, as I would like to see the subtotals. Perhaps this can help you locate the source of the problem.
Comment #8
krys15 commentedI also had this error.
I was applying 2 aggregations the first to 'group and compress', the second 'maximum'. I removed the maximum aggregation, and my page is working again. I suspect the second aggregation is not performing any useful function, but I've not yet tested fully.
Comment #9
ramlev commentedThe patch does not resolve the issue.
The problem arises because the
$row_numparameter in thesetCellmethod is typecast as an integer. However, in several instances within the code, it is called with a NULL value. Additionally, the methodsrenderNewValueandrenderNewWebformValueboth accept$row_numas a parameter, but one method typecasts it while the other does not.I believe the solution is to either remove the typecasting altogether, or it appears that the issue can be resolved by modifying the
setCell()method as follows:From:
public function setCell(FieldHandlerInterface $field_handler, int$row_num, $new_values, string $separator) {To:
public function setCell(FieldHandlerInterface $field_handler, int|null $row_num, $new_values, string $separator) {Comment #10
ramlev commentedAttached a patch that solves the issue
Comment #11
butch.coolidgeWe were having the same error, Patch #10 works.
Thanks very much.