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

Post new entry in Entity List with Node Reference to other Node #1061

Open
charlie-rushton opened this issue Nov 5, 2019 · 2 comments
Open

Comments

@charlie-rushton
Copy link

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.

Screenshot 2019-11-05 at 13 35 25

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.

@charlie-rushton
Copy link
Author

@e0ipso could you provide me with any help/pointers with this issue?

@e0ipso
Copy link
Member

e0ipso commented Nov 5, 2019

@charlie-rushton I am not available for support requests or other maintenance tasks on this module. I am focusing my volunteer time elsewhere nowadays.

Please take a look at the sponsoring options in https://github.com/sponsors/e0ipso or get in touch for a more formal engagement.

I hope you find a resolution to your problem.

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

No branches or pull requests

2 participants