Hi,

I have been using this module for a while without problem, but today I came across a error when updating an array.

The field is an unlimited texteared.

Here is the example:

{
  "field_leverans_adress":["asdasd32", "other option"]
}

The error;

Recoverable fatal error: Argument 2 passed to RestWSBaseFormat::getResourceReferenceValue() must be of the type array, string given, called in /Users/xx/Sites/pv/SERVER/production/sites/all/modules/restws/restws.formats.inc on line 274 and defined in RestWSBaseFormat->getResourceReferenceValue() (line 307 of /Users/xx/Sites/pv/SERVER/production/sites/all/modules/restws/restws.formats.inc).

How can I fix that? thanks in advance

Comments

sebastiannm’s picture

I noticed that the error only happens when the format of the field is plan text

sebastiannm’s picture

Issue summary: View changes

Adding som extra info

tdiprima33’s picture

Issue summary: View changes
StatusFileSize
new26.29 KB

Hi There!

I attached a patch: 2070213-fix-error-on-array.patch

Basically, if you are trying to populate a text field, and that field can have unlimited values (essentially, an Array), the code is attempting to manipulate that array. It is calling method getResourceReferenceValue, and that is where the code is failing.

Recoverable fatal error: Argument 2 passed to RestWSBaseFormat::getResourceReferenceValue() must be an array, string given, called in [drupal]/sites/all/modules/restws/restws.formats.inc on line 294 and defined in RestWSBaseFormat->getResourceReferenceValue() (line 334 of [drupal]/sites/all/modules/restws/restws.formats.inc).

Not only is running this code unnecessary, but calling getResourceReferenceValue throws an error:
$list_value = $this->getResourceReferenceValue($list_type, $list_value);

Cheers!
Tammy

tdiprima33’s picture

Status: Active » Needs review
tdiprima33’s picture

StatusFileSize
new849 bytes

Status: Needs review » Needs work

The last submitted patch, 4: 2070213-fix-error-on-array.patch, failed testing.

mkolar’s picture

I had exactly same problem... Entity with field with multivalue text (plain_text).. This patch do the trick, no more errors with this patch and entity is saved with all given values.

roppa_uk’s picture

I have the same problem. I had to add the patch manually but it still didn't work. This is a real issue for us.

PovilasID’s picture

Patch breaks intended architecture and results in compatibility issues in more complex structures.
It seams that code author has forgotten to implement simple text field array in getResourceReferenceValue it should be an easy fix for code author.

I applied a dirty fix for my particular case (line 275):

            else if(($list_type = entity_property_list_extract_type($info['type'])) !== "decimal"){
              foreach ($property_value as &$list_value) {
                $list_value = $this->getResourceReferenceValue($list_type, $list_value);
              }
            }

However this needs more broad scope approach that would encompass other common cases like text fields etc.

P.S. This of course effects not only PUT but also POST queries and before this issue is fixed none of multiple value text field based content is saved which is a major issue

PovilasID’s picture

Title: Error on PUT array » Error on PUT/POST array
Version: 7.x-2.1 » 7.x-2.4
Priority: Normal » Major