RESTful-Drupal / restful

RESTful best practices for Drupal
https://drupal.org/project/restful
419 stars 173 forks source link

Restful API filter node by Field Collection field value #1005

Open leolandotan opened 7 years ago

leolandotan commented 7 years ago

I have implemented custom APIs using the Restful v1 module where I would like to filter the returned JSON results by a field value inside a Field Collection that's attached to my node.

I have tried to do some research but couldn't find any references.

Here is my code to output the contents of the node's Field Collection data:

public function publicFieldsInfo() {
    ...
    $public_fields['featured'] = array(
      'property' => 'field_feature',
      'resource' => array(
      'field_feature' => array(
        'name' => 'fc_feature',
      ),
    ),
    ...
}

Now the current JSON output is good already:

...
"featured": {
  "id": "31766",
  "self": "http://site.local/en/api/v1.0/fc_feature/31766",
  "featured": false,
  "image": null,
  "caption": "Default Caption",
  "credit": null
},
...

Now I need to add a filter in the URL that would list nodes that has the featured value set to TRUE.

Any ideas on how this can be achieved?

Thank you!

fatimahitawala commented 4 years ago

Are you able to solve it?