Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node_save() in drupalgap #418

Closed
teripak opened this issue Nov 23, 2014 · 5 comments
Closed

node_save() in drupalgap #418

teripak opened this issue Nov 23, 2014 · 5 comments

Comments

@teripak
Copy link

teripak commented Nov 23, 2014

Hi,

I am learning Drupalgap and it is great for developing app for me who are in the field of web.
I need to use node_save() in drupalgap and I could not find ways to save a node which has a entity reference field and a date field.

var node = {
    title:"test node",
    type:"my_custom_type",
    field_my_reference: 'my value1',    //entity reference field
    field_my_date: 'my value2',         //date field
};
node_save(node, {
    success:function(result) {
  }
});

There was no error and a node is created successfully. But no data in the field of entity reference and date.

I found a web page as below
http://drupal.aspcode.net/ppst/635472748100189580182694/how-to-update-geofield-using-a-custom-form-and-drupalgaps-nodesave

so I tried to do it with the same way like below but I could not make it.

    var node = {
        title:"test node",
        type:"my_custom_type",
        field_my_reference: {
            und: {
                 0: {
                    target_id: nid,       //nid is of cause defined before.
                    target_id: 'node'
                 }
            }
        }
    };

The error was as below
Warning: Illegal offset type in isset or empty in _form_validate() (line 1368 of /home/hosting_users/my_site/www/includes/form.inc).

Could you guide me how to do that in dripalgap way?
-Leo.
@signalpoint
Copy link
Owner

@teripak You'll need to build the field's structure to match what Drupal expects. The easiest way to do that, is to first just create a test node in Drupal through the UI.

Then use FireFox poster, to GET the node from this URL:

http://www.example.com/?q=drupalgap/node/123.json

That will return the JSON structure of the node, examine that structure and take note of how it is built.

Then build your field(s) JSON structure in the exact same way.

Also, FYI DrupalGap has built in support for creating/editing nodes. Here are some common paths that you can navigate to

node (listing of content)
node/add (listing of content types that can be added)
node/add/article (add an article)
node/123/edit (edit a node)

Utilizing these features, DrupalGap will automatically build the form for you.

@teripak
Copy link
Author

teripak commented Nov 24, 2014

Thanks it works~

But I needed some modifications to the generated json format.
I got a json by 123.json as below and it didn't work with error.

        "field_course":{
            "und":[{
                "target_id":"5416",
                "title":"\uc911\ud559 \uc608\ube44\uacfc\uc815 \uc601\uc5b4\u2460",
                "entity_type":"node",
                "bundle":"course_schedule"
            }]
        },

So I tried to change it and below works without error.

        type:"course_schedule",
        "field_course":{
            "und":{
                "target_id":nid
            }
        }

In the above changes, the "[" was removed and 3 items (title, entity_type, bundle) were also not used.

Did I do it right? It works anyway..

@signalpoint
Copy link
Owner

@teripak Correct, I think only the target_id property is needed when creating/updating an entity reference field.

@teripak
Copy link
Author

teripak commented Nov 24, 2014

I think I am not fully understand about this.
When I use a datetime field, there is an error and I couldn't find a way.

Below is what I did.

    "field_start_date":{
        "und":[{
            "value":"2014-11-24 00:00:00",
            "value2":"2014-11-25 00:00:00"
        }]
    },

And I got below errors

    The value input for field Start Date Start date is invalid.
    The value input for field Start Date End date is invalid.

The field_start_date is set as a required field and also checked as collect an end date.

Do you have any idea what I was wrong?

@signalpoint
Copy link
Owner

@teripak For the date field, the format of the JSON depends on what type of date field you are using, and what type of widget you are using on the date field. For example:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants