Drupal 7 服务使用图像创建节点

问题描述 投票:0回答:1

我安装了新的 Drupal 7.56 发行版。 我想通过java客户端创建新节点。 然而,经过一番谷歌搜索后,我发现了 Drupal 7 的“服务”模块。

所以我安装了它,以及下一个模块:

  • 服务
  • Ctools(服务所需)
  • 图书馆(服务所需)
  • OAuth 1.0

所以,我安装了这些模块。我从结构菜单中创建了服务。

  • 端点:API
  • 服务器:休息

我启用了会话和 OAuth 身份验证。

我创建了一个新的内容类型。 名称:TestContent(机器名称:testcontent) 领域:

  • 标题(简称:
    title
  • 身体(M.n.:
    body
  • 图片(M.n:
    field_pics
    )(类型:图像)值数:5

在此服务中,我启用了所有资源(文件、用户等..) 我禁用了 OAuth,因为我稍后会设置它。

现在,我打开了 Postman 客户端。 登录:admin/admin

{
    "sessid": "QZTYSQu3-I9pacOpoSP--V_LkGcusy2grl12U_CyKrY",
    "session_name": "SESS51ebf8732a20744576a234cf7af43040",
    "token": "jkUDb6MsGMHt_mBlGbm02O-lyZq-2nRTqD1OslxtvAg",
    "user": {
        "uid": "6",
        "name": "admin",
…

现在我有了一个令牌。现在我上传两张照片。

http://test.dd:8083/api/file

收到这些回复

{
    "fid": "6",
    "uri": "http://test.dd:8083/api/file/6"
}
{
    "fid": “7”,
    "uri": "http://test.dd:8083/api/file/7”
}

好的,现在我将尝试创建一个新的

TestContent
,并将这些图像连接到节点。

好的,节点创建完成。但图像未连接到节点。但我没有收到错误消息。 为什么?怎么了?

我尝试过:

[ {fid:6} , {fid:7}]
und: [ { fid: 6 }]

请给我想法。谢谢你

php drupal postman drupal-7
1个回答
0
投票

我在 Drupal 网站上找到了解决方案。

运行这些GIT差异!

diff --git a/resources/node_resource.inc b/resources/node_resource.inc
index 8f870b7..6669a1a 100644
--- a/resources/node_resource.inc
+++ b/resources/node_resource.inc
@@ -339,8 +339,9 @@ function _node_resource_create($node) {
   );
   $stub_form = drupal_build_form($node_type . '_node_form', $stub_form_state);
   $form_state['triggering_element'] = $stub_form['actions']['submit'];
+  $node = (object) array_merge((array) $stub_node, (array) $node);

-  drupal_form_submit($node_type . '_node_form', $form_state, (object)$stub_node);
+  drupal_form_submit($node_type . '_node_form', $form_state, $node);

   if ($errors = form_get_errors()) {
     return services_error(implode(" ", $errors), 406, array('form_errors' => $errors));
@@ -423,6 +424,7 @@ function _node_resource_update($nid, $node) {

   $node_type = $node['type'];
   node_object_prepare($old_node);
+  $old_node = (object) array_merge((array) $old_node, (array) $node);

   // Setup form_state.
   $form_state = array();
diff --git a/resources/user_resource.inc b/resources/user_resource.inc
index 304a293..c1f9b5a 100644
--- a/resources/user_resource.inc
+++ b/resources/user_resource.inc
@@ -471,6 +471,7 @@ function _user_resource_update($uid, $account) {
     return services_error(t('You are not allowed to change your username.'), 406);
   }

+  $account_loaded = (object) array_merge((array) $account_loaded, (array) $account);
   $form_state['values']['op'] = variable_get('services_user_save_button_resource_update', t('Save'));
   $form_state['values']['#user_category'] = $category;
   $form_state['values']['#account'] = $account_loaded;

查看更多:这里

© www.soinside.com 2019 - 2024. All rights reserved.