I noticed that when I PATCH a node and update the body value, the body format and summary are set to null.

If I try to add the summary and format to the json sent to the API, I receive an error saying:

Unprocessable Entity: validation failed.
Body: this field cannot hold more than 1 values

Any ideas why I get this error and how can I preserve the body format?

This is my js object:

  title: { value: this.state.title }, 
  body: { value: this.state.body, format: "basic_html" }, 
  type: { target_id: 'article' },
  _links: {
    type: {
      href: 'http://localsite.dev/rest/type/node/article'

If I remove the format: "basic_html" part, I get no errors but the format and summary are set to null.



Kind of surprised this even works. The value of a field is a list of field items. Try something like this:

body: [ { value: this.state.body, format: "basic_html" } ],
  • Why surprised? It'd be surprising if this didn't work, no? – Wim Leers Feb 24 '16 at 22:00
  • But what is surprising (well, concerning), is that error message: ` this field cannot hold more than 1 values`. That makes zero sense. – Wim Leers Feb 24 '16 at 22:01
  • Oh, it kind of does. I think what this tried to do is create a body field with two values, so basically this: [ ['value' => 'whatever was in this.state.body'], ['value' => 'basic_html']]. And it probably happened because it first ignored the array keys and made them numeric and in a second step used the two strings as value for the main property, value. – Berdir Feb 24 '16 at 22:05
  • What I find surprising is how it did that upcasting example and how it accepted the thing without format, because then treated it as the value for the first field item. I know field API itself accepts pretty much anything ($node->body = $value works too, for example). But I thought the serialization API would be more strict in requiring a list of field item objects for each field. – Berdir Feb 24 '16 at 22:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.