-
Notifications
You must be signed in to change notification settings - Fork 173
Description
Hi,
I am trying to submit a post request to my resource containing a node reference to another node in my drupal site.
My resource is a log file where I can submit entries with a type and a description, and this has a node reference field which should be referencing a student.
I can use the restful drupal module to post a description and type (these are just text fields) and the node reference field is set to autocomplete, therefore I am trying to pass a node id and it should autocomplete the rest of the reference.
Below is a code snippet of my resource:
<?php
/**
* @file
* Contains \Drupal\restful\Plugin\resource\GustLog__1_0.
*/
namespace Drupal\restful\Plugin\resource;
/**
* Class Gust Log
* @package Drupal\restful\Plugin\resource
*
* @Resource(
* name = "gustlog:1.0",
* resource = "gustlog",
* label = "Gust Log",
* description = "Export the Gust Log entity.",
* authenticationTypes = TRUE,
* authenticationOptional = FALSE,
* dataProvider = {
* "entityType": "gust_log",
* "bundles": {
* "gust_log"
* },
* },
* majorVersion = 1,
* minorVersion = 0
* )
*/
class GustLog__1_0 extends ResourceEntity implements ResourceInterface {
/**
* {@inheritdoc}
*/
protected function publicFields()
{
$public_fields = parent::publicFields();
// The mail will be shown only to the own user or privileged users.
$public_fields['type'] = array(
'property' => 'field_type',
);
$public_fields['description'] = array(
'property' => 'field_task_description',
);
$public_fields['nodeReference'] = array(
'property' => 'field_node_references'
);
return $public_fields;
}
}
Below is a screenshot of my postman requests. I have tried several different formats for the value of node reference, but it never creates the reference, only a blank array.
P.S. This is a project for a client who already had an installation of drupal and wanted a mobile app to interact with the site, I have very little experience with drupal prior to this and no experience with the RESTful module, so any help will be greatly appreciated. Thanks in advance.
