When we try to use this with Pager Serializer we get the following errors in the logs:
Error: Cannot use object of type stdClass as array in Drupal\rest_export_nested\Plugin\views\display\RestExportNested->render() (line 45 of modules/contrib/rest_export_nested/src/Plugin/views/display/RestExportNested.php)
Code reference snippet:
// Loop through results and fields.
foreach ($results as $key => $result) {
foreach ($result as $property => $value) {
// Check if the field can be decoded using PHP's json_decode().
if (is_string($value)) {
if (json_decode($value) !== NULL) {
// If so, use Guzzle to decode the JSON and add it to the results.
$results[$key]->$property = \GuzzleHttp\json_decode($value);
}
elseif (json_decode(Html::decodeEntities($value)) !== NULL){
$results[$key]->$property = \GuzzleHttp\json_decode(Html::decodeEntities($value));
}
}
// Special null handling.
if (is_string($value) && $value === 'null') {
$results[$key]->$property = NULL;
}
}
}
As soon as we switch back to Drupal core pager it works as it should.
Any help would be greatly appreciated.
Comments
Comment #2
bluegeek9 commentedThe Core Serializer returns an array of data. The Pager Serializer returns an object, and one of the properties is the same array as the Core Serializer.
I made a patch to handle the Pager Serializer.
Comment #3
glynster commented@bluegeek9 thanks again for being so fast!
I applied the patch and now we get the following error:
A small tweak?
Comment #4
bluegeek9 commented@glynster Do you get the same error when using the Core Searializer with this patch?
I am having trouble reproducing the error. Can you provide me with the output (json) using Pager Serializer and the Core Rest Export? I can use this for testing.
Comment #5
glynster commentedHi @bluegeek9 yes indeed we were getting the same error when using the Core Serializer, funny you should ask that. It actually made all the nested views break and generated that Guzzle error. A lot of those views are only using Core Serializer.
Json output Pager Serializer with Nested just gives a white page of death.
Json with core enabled produces this:
Let me know what else I can provide.
Comment #6
imclean commentedComment #7
imclean commented@bluegeek9 would you be interested in becoming a maintainer?
Comment #8
glynster commented@bluegeek9 checking in with you to see if you need anymore info from me for this patch?
Comment #9
bluegeek9 commented@glynster I was able to reproduce the bug, but I had trouble fixing it. Which module are you using for the "nested" view.
Comment #10
glynster commented@bluegeek9 only Pager Serializer. However there is a small patch for core, when I tried this I got the exact same result as I do with your module: https://www.drupal.org/project/drupal/issues/2982729. Not sure if this helps but perhaps it might spark an idea?
Comment #11
imclean commentedWe shouldn't be checking for the existence of a specific contrib module or class.
It might be worth looking at how Drupal core handles the situation if it works OK with Page Serializer. We need to find a more generic method of handling different return types.
Comment #12
krzysztof domański1/ We can check the
$resultstype.2/ As a follow-up we should allow rows name property to be customizable. However, this is not required now.
Comment #13
irous commentedI'm testing the patch, Pager Serializer is now working with REST Export Nested for me!
Comment #14
bbu23Patch #13 works for me with REST Export Nested.
Comment #15
sachbearbeiter commented#13 works ...
Maintainers: pls. commit ...
@krzysztof-doma%C5%84ski Thanks!
Comment #16
sachbearbeiter commentedIs there something evil in #12? It would be nice, if the Patch could be commited ... Thanks!
Comment #17
sachbearbeiter commentedI pay some money, if you could commit this asap!
Comment #18
nsalves commentedCommitted the patch to the dev branch, a new release will be issued soon. Thanks guys
Comment #19
nsalves commentedComment #20
sachbearbeiter commented@nsalves Thank you very much!
Comment #22
sivaji_ganesh_jojodae commentedOn a related note, we are getting the following error with the flatten method.