进行node_save时cck图像消失

发布于 2024-11-14 05:27:04 字数 973 浏览 3 评论 0原文

我保存一个带有图像的节点,该节点正在被服务填充。我用 drupal_write_record 写入图像,并且图片已经出现在节点中。但是当 - 在脚本末尾 - 我调用 node_save 时,图像再次消失。

我的代码:

  $file_drupal_path= $filedata['location'];
  $file = new stdClass();
  $file->filename = $filedata['name'];
  $file->filepath = $file_drupal_path; 
  $file->filemime = $filedata['mime'];
  $file->filesize = filesize($file_drupal_path);
  $file->filesource = $filedata['name'];

  $file->uid = 1;
  $file->status = FILE_STATUS_PERMANENT;
  $file->timestamp = time();  
  $file->list = 1;

  // fid is populated by drupal_write_record
  drupal_write_record('files', $file);

  $imageData = field_file_load($file->fid, TRUE);
  return $imageData;

node_save也有未设置值的键。

function transport_service_save($node) {
    $node = (object) ($node);
    $node->promote = 1;
    node_save(node_submit($node));
    return print_r( $node , TRUE );
}

以及节点中 cck 图像字段中的

I save a node with images which is beeing filled by a service. I write the image with drupal_write_record and the pictures appear in the node already. But when - at the end of the script - I call a node_save the image disappears again.

My Code:

  $file_drupal_path= $filedata['location'];
  $file = new stdClass();
  $file->filename = $filedata['name'];
  $file->filepath = $file_drupal_path; 
  $file->filemime = $filedata['mime'];
  $file->filesize = filesize($file_drupal_path);
  $file->filesource = $filedata['name'];

  $file->uid = 1;
  $file->status = FILE_STATUS_PERMANENT;
  $file->timestamp = time();  
  $file->list = 1;

  // fid is populated by drupal_write_record
  drupal_write_record('files', $file);

  $imageData = field_file_load($file->fid, TRUE);
  return $imageData;

and the node_save

function transport_service_save($node) {
    $node = (object) ($node);
    $node->promote = 1;
    node_save(node_submit($node));
    return print_r( $node , TRUE );
}

in the cck image field in the node there are keys with unset values as well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

豆芽 2024-11-21 05:27:04

安德烈亚斯,

有完全相同的问题。

按照此处所述使用 drupal_execute() 立即解决了问题:

// Save the node, updated or new
// Get the node object as an array the node_form can use
$values = (array)$node;

// Save the node (this is like pushing the submit button on the node edit form)
drupal_execute('abc_node_form', $values, $node);

来源:
http:// /www.drupalisms.com/gregory-go/blog/use-drupalexecute-instead-of-nodesave-to-save-a-node-programmatically

但是一个公平的警告:它对前几个人来说就像一个魅力回合,但现在我收到大量错误类型:

warning: call_user_func_array() [function.call-user-func-array]: 
First argument is expected to be a valid callback, 'node_form' was given in ...

看不到发生了什么变化。我所做的只是多次调用保存的页面来测试它。

最后(希望如此!)编辑此回复。似乎需要包含包含node_form的node.module文件,因此

module_load_include('', 'node', 'node.pages.inc');

在代码中添加以下内容(如hook_init())即可解决问题。

在这里工作,现在我的节点保存了完整的图像。

Andreas,

Had the exact same problem.

Using drupal_execute() as described here fixed the problem immediately:

// Save the node, updated or new
// Get the node object as an array the node_form can use
$values = (array)$node;

// Save the node (this is like pushing the submit button on the node edit form)
drupal_execute('abc_node_form', $values, $node);

Source:
http://www.drupalisms.com/gregory-go/blog/use-drupalexecute-instead-of-nodesave-to-save-a-node-programmatically

But a fair warning: it ran like a charm for the first few rounds, but now I get tonnes of errors type:

warning: call_user_func_array() [function.call-user-func-array]: 
First argument is expected to be a valid callback, 'node_form' was given in ...

Can't see what changed. All I did was call the page that did the saving a few times to test it.

And a final (hopefully!) edit to this reply. It seems that including the node.module file that contains node_form is needed, so adding this:

module_load_include('', 'node', 'node.pages.inc');

in your code (like in hook_init()) will do the trick.

Worked here, and now my nodes save with images intact.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文