Download & Extend

'entity/node/1' doesn't work correctly after enable rest module.

Project:Drupal core
Version:8.x-dev
Component:rest.module
Category:bug report
Priority:normal
Assigned:Unassigned
Status:postponed
Issue tags:WSCCI

Issue Summary

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

#1

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.

<?php
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.

AttachmentSizeStatusTest resultOperations
drupal-rest_unsupported_operand_types-1902810-1.patch649 bytesIdlePASSED: [[SimpleTest]]: [MySQL] 48,790 pass(es).View details | Re-test

#2

Status:active» needs review

#3

Status:needs review» postponed

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

#4

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

<?php
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).
?>

#5

Status:needs work» postponed

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

nobody click here