我位于同一站点的不同路径上,并且我需要允许用户更改他/她在不同位置写入的节点上的字段内容。我有 nodeid 和字段名称,以及 ids 等 np.
我不认为这太难,但教程或解释会很棒。
Thanks.
编辑:谢谢 anschauung 的提问,所以澄清一下:
它是一个 CCK 文本区域。至于为什么,有一个中心节点类型,有许多链接节点参考节点。从任何引用中心节点的节点的编辑页面,都需要能够编辑和保存中心节点的字段。这就是我的用例。
再次感谢。
非常感谢 googletorp,我真的非常感谢你的帮助。
这是我到目前为止所拥有的:
对于第一步:
function update_main_field_menu() {
$items = array();
$items['update_main_field/%'] = array(
'title' => 'Update Main Field',
'page callback' => 'post_to_main_node',
'page arguments' => 1,
'type' => MENU_CALLBACK
);
return $items;
}
第二步:
function post_to_main_node(){
// Sorry, I'm totally lost. What do I put here?
}
您还提到了这一点:
在 hook_form_alter 中,
hook_nodeapi 或其他一些钩子
当节点形式为
生成的。你应该调查一下
这最适合您的情况。
如何生成节点表单?
第三步:
function modulename_form_mainct???_node_form_alter (&$form, &$form_state) {
// I'm not sure about which form I'm doing node form alter on. If I do it to the mainct, wouldn't that alter the regular edit page the user is viewing? I only want to load the js for the ajax submission. Is there a update_main_field node form?
drupal_add_js(drupal_get_path('module', 'modulename') ."/updateField.js");
}
另外,步骤 2 中的函数和步骤 3 中获取节点形式之间有什么关系?
Step 4:我想我大部分都明白了,尽管由于其他原因我还无法测试它。 :)
我真的很想学习如何在 drupal 中做到这一点,但是如果你能稍微提高你的语言的虚拟级别,那就太好了。 :D 再次非常感谢你。
再次编辑:
实际上,我昨天尝试添加访问参数,但由于某种原因它不起作用。 :( 但现在确实如此!是的,你有魔法。
现在,当我像这样触发帖子时:
Drupal.behaviors.ajax_update_field = function (context) {
$("#button").click(function(){
var url = $("#edit-field-reference-0-nid-nid").val().replace(/.*?\[nid:(\d+)?]/ig, "$1");
url = "/update_main_field/"+url;
// The data is just some silly test thing
$.post(url, {data: $("#edit-field-reference-0-nid-nid-wrapper label").text()}, function(value) {
// Here you can write your js to handle a response to the user,
// or if something went wrong an error message.
// value = response data from drupal
alert(value);
});
});
}
我看到一个带有正确数据的 url 帖子。这很好。但没有回应。警报为空。
还有一个新的空白……已经创建了一些东西。其中没有任何内容,但在过滤节点时我可以在视图中看到它。它没有标题、任何字段等。只有发布日期。
我想要更新的节点没有更新。
所以这让我认为第二步可能有点不正确。我对此有几个疑问。
function post_to_main_node(){
// Is this sufficient to load the node? nid doesn't have to be set as an arg for the function?
$node = node_load($_POST['nid']);
// Is the field set like this? 'field_library' is the 'machine name' of the field. This is what's needed right?
$node->field_library = $_POST['data'];
node_save($node);
}
再次非常感谢您。