Does not work when rest data is an object (e.g. when Pager Serializer is enabled)

Created on 11 August 2020, over 4 years ago
Updated 24 June 2024, 5 months ago

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.

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇺🇸United States glynster

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024