0

I am currently using the latest release of Drupal 8.0 (downloaded and installed today).

I have two content types. I have a entity reference on one of the content types that references content from the other content type.

Using both the Views REST Export and the built in REST API I am unable to find a way to return the associated content entity fields. Currently what gets returned is the target_id as well as a link to the entity. I am using the hal_json content type.

I have scoured the Drupal docs and I am unable to figure this out. Any help would be greatly appreciated!

1 Answer 1

1

RESTws will retrieve your content using an Entity Metadata Wrapper. By default, this won't retrieve the referenced node. To get the nested content you'd need to write your own resource class in a custom module.

The new resource class is registered with hook_restws_resource_info(). In your resource class, extend RestWSEntityResourceController or just implement RestWSQueryResourceControllerInterface (You can see the default implementation here.)

Your new resource class would look something like this:

class MyCustomResourceController extends RestWSEntityResourceController {

  /**
   * Override the wrapper method.
   */
  public function wrapper($id) {
    $wrapper = entity_metadata_wrapper($this->entityType, $id);
    /**Add something here to add the referenced node */
    return $wrapper;
  }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.