angular-drupal icon indicating copy to clipboard operation
angular-drupal copied to clipboard

How to create node with entity field

Open fufu7755 opened this issue 9 years ago • 15 comments

@signalpoint Thank you for helping me solve the last problem. I have found the answer.

I have a new problem, when I create node with entity field always gave error, I think it should be the format problem.

var node = { type: 'article', title: 'Hello world', language: 'und', body: { und: [ { value: 'How are you?' }] } };

I change them to

var node = { type: 'article', title: 'Hello world', language: 'und', fiele_engtity: { und: [ { entity_id : *** }] } };

Pleas give me some tips. thank you very much. Hopefully it will not take you too much time.

fufu7755 avatar Nov 01 '16 04:11 fufu7755

I have a new problem, when I create node with entity field always gave error, I think it should be the format problem.

@fufu7755 What is the error?

signalpoint avatar Nov 01 '16 18:11 signalpoint

@fufu7755 Is this from your actual code?

var node = { type: 'article', title: 'Hello world', language: 'und', fiele_engtity: { und: [ { entity_id : *** }] } };

What happens if you change fiele_engtity to field_entity?

kentr avatar Nov 01 '16 22:11 kentr

@fufu7755 I agree with @kentr and it's likely you'll need to use target_id instead of entity_id like so:

var node = {
  type: 'article',
  title: 'Hello world',
  language: 'und',
  field_entity: { und: [ { target_id : '... (123)' }] }
};

signalpoint avatar Nov 02 '16 00:11 signalpoint

I use var node = { type: 'article', title: 'Hello world', language: 'und', field_entity: { und: [ { target_id : 123 }] } };

var node = { type: 'article', title: 'Hello world', language: 'und', field_entity: { und: [ { target_id : '123' }] } };

var node = { type: 'article', title: 'Hello world', language: 'und', field_entity: { und: [ { target_id : 'node(123)' }] } };

still return error message.

fufu7755 avatar Nov 03 '16 02:11 fufu7755

@fufu7755 What's the error message?

signalpoint avatar Nov 03 '16 02:11 signalpoint

Message is "Not Acceptable : An illegal choice has been detected. Please contact the site administrator."

fufu7755 avatar Nov 03 '16 02:11 fufu7755

wechatimg2

fufu7755 avatar Nov 03 '16 02:11 fufu7755

@fufu7755 It should also mention what field is causing the problem. What is that field? Then what is the Widget set to for that particular field on your Manage fields page? The way in which you send the the data is sometimes dependent on the widget selected for the field.

As an example, if you're using an autocomplete widget for your entity reference field, then you need to send a value like this:

field_entity: { und: [ { target_id : '... (123)' }] }

The ... and the space are important, the placement of the parenthesis are important, and the integer value must lie within the parenthesis.

UPDATE

As I can see from your screenshot, the field I am asking questions about it the field_record_pid field. What type of field is this? What module powers it? What widget is it using? Is it one, or more, or unlimited values, etc?

signalpoint avatar Nov 03 '16 02:11 signalpoint

Thank you very much. I see what you mean. Using the autocomplete widget, the code format is field_entity: { und: [ { target_id : '... (123)' }] } If I use the Check box or select list, then what is the format of the code?

My English is not good. Thank you so much for your patience.

fufu7755 avatar Nov 03 '16 02:11 fufu7755

If I set entity field's Widget with Check box, then what is code format? Thanks

fufu7755 avatar Nov 03 '16 03:11 fufu7755

@fufu7755 I don't know what the format is, I'm guessing it is just this:

field_entity: { und: [ { target_id : '123' }] }

In cases like this, I usually open up Firefox Poster and try many different combinations of JSON, until it properly saves.

However, my question still stands:

As I can see from your screenshot, the field I am asking questions about it the field_record_pid field. What type of field is this? What module powers it? What widget is it using? Is it one, or more, or unlimited values, etc?

signalpoint avatar Nov 03 '16 13:11 signalpoint

This field is node entity field and use autocomplete as Widget, just one value.

wechatimg1

fufu7755 avatar Nov 03 '16 13:11 fufu7755

@signalpoint Question again, If I want to work with more or unlimited values, how to write code. Thanks again.

fufu7755 avatar Nov 03 '16 13:11 fufu7755

@fufu7755 If it's an autocomplete, then definitely use the format previosly discussed. For multiple values you need this patch, and this format:

field_entity: { und: [
  { target_id : '... (123)' }],
  { target_id : '... (456)' }],
}

signalpoint avatar Nov 03 '16 13:11 signalpoint

Thank you very much.

fufu7755 avatar Nov 03 '16 14:11 fufu7755