Problem/Motivation

Enable rest module, go to 'admin/config/services/rest', and save content exposed as web service.
Go to 'entity/node/1', I get error:
Fatal error: Unsupported operand types in D:\Apache\drupal8\core\modules\jsonld\lib\Drupal\jsonld\JsonldEntityNormalizer.php on line 37
By the way, I'm using a win7 system.

Comments

floydm’s picture

I'm on a Mac running PHP 5.3.15 and get the same thing, so it isn't a platform/version problem.

Line 33 $attributes = $entity_wrapper->getProperties(); is returning nothing, so the $attributes = array( ... ) + $attributes is puking. The attached patch fixes the problem by returning an empty array from $entity_wrapper->getProperties() no matter what.

diff --git a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php b/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php
index a2e49e3..458a96a 100644
--- a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php
+++ b/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php
@@ -124,7 +124,7 @@ public function getProperties() {
     }
 
     // Only return properties which are not in the $skip array.
-    return array_diff_key($properties, array_fill_keys($skip, ''));
+    return array_diff_key($properties, array_fill_keys($skip, '')) ? array_diff_key($properties, array_fill_keys($skip, '')) : array();
   }
 
 }

My apologies for being fairly new to contributing patches and unsure if this is the appropriate way to address the issue. Regardless, it should help you guys track it down quickly.

dagmar’s picture

Status: Active » Needs review
klausi’s picture

Status: Needs review » Postponed

Nodes are not yet converted to EntityNG, so this postponed on #1818556: Convert nodes to the new Entity Field API.

smiletrl’s picture

Status: Postponed » Needs work

After apply the patch, I still get the error.
Anyway, I get wierd result:
{"@id":"http:\/\/localhost\/drupal8\/node\/1","@type":"http:\/\/localhost\/drupal8\/site-schema\/content-deployment\/node\/article"}

From my point of view, patch in #1 suppresses the problem, not actuall solve the problem^^

I still get errors on other pages

Warning: Invalid argument supplied for foreach() in Drupal\jsonld\JsonldEntityWrapper->getProperties() (line 117 of core\modules\jsonld\lib\Drupal\jsonld\JsonldEntityWrapper.php).
Notice: Undefined variable: properties in Drupal\jsonld\JsonldEntityWrapper->getProperties() (line 127 of core\modules\jsonld\lib\Drupal\jsonld\JsonldEntityWrapper.php).
Warning: array_diff_key() [function.array-diff-key]: Argument #1 is not an array in Drupal\jsonld\JsonldEntityWrapper->getProperties() (line 127 of core\modules\jsonld\lib\Drupal\jsonld\JsonldEntityWrapper.php).
klausi’s picture

Status: Needs work » Postponed

Yes, you cannot test REST module with nodes right now.

rszrama’s picture

Status: Postponed » Closed (fixed)

I can see no issue in my testing, because quite a lot has changed. There isn't even a REST menu item any more (much less JSON-LD)! : P

Closing this out directly as whatever was causing the issue has obviously been fixed.

rszrama’s picture

Issue summary: View changes

windows system.