【问题标题】:Get relationships from API call to Drupal从 API 调用获取关系到 Drupal
【发布时间】:2018-03-10 16:18:34
【问题描述】:

我正在尝试将 Drupal 设置为无头 CMS,以便使用 JSONAPI 向 Angular 应用程序提供数据。我能够从我的 GET 请求中获取响应对象,但响应数据不包含任何引用字段类型(例如图像或标签)。相反,它返回一个包含引用字段类型的关系对象。

示例响应对象:

"data": {
  "type": "node--release",
  "id": "21bff999-241d-4807-bd00-4af7f5a767ff",
  "attributes": {
    "nid": 11,
    "uuid": "21bff999-241d-4807-bd00-4af7f5a767ff",
    "vid": 11,
    "title": "Example title",
    "created": 1506621775,
    "changed": 1506621912,
    "revision_timestamp": 1506621912,
    "revision_log": null,
    "path": null,
    "field_artist": "Band name",
    "field_description": {
      "value": "<p>Album description</p>\r\n",
      "format": "basic_html"
    },
    "field_title": "Album name",
  },
  "relationships": {
    "field_image_large": {
      "data": {
        "type": "file--file",
        "id": "83d45147-1339-45a0-ae8e-fc662575d77b",
      },
      "links": {
        "self": "http://localhost/error-records/jsonapi/node/release/21bff999-241d-4807-bd00-4af7f5a767ff/relationships/field_image_large",
        "related": "http://localhost/error-records/jsonapi/node/release/21bff999-241d-4807-bd00-4af7f5a767ff/field_image_large"
      }
    },
  },
} 

我想显示上传到“field_image_large”的图像,但没有任何链接(无论是自身的还是相关的)都直接指向图像的存储位置。此外,当我对其中任何一个进行 API 调用时,返回的结果也不提供指向图像存储位置的链接。

【问题讨论】:

    标签: angular drupal-8 json-api


    【解决方案1】:

    你可以 GET /jsonapi/node/release/{resourceID}?include=field_image_largeincluded[0].links 中,您会找到一个图像路径。 顺便说一句,使用一堆模块,您甚至可以获得响应式图像。其中之一是Consumer Image Styles。有关它的更多信息,您可以在上述链接中找到。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-13
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 2015-11-29
      • 1970-01-01
      相关资源
      最近更新 更多