【问题标题】:How to update a node from the node page with javascript in Drupal?如何在 Drupal 中使用 javascript 从节点页面更新节点?
【发布时间】:2011-05-30 09:50:57
【问题描述】:

看起来可以使用带有菜单回调的自定义模块,然后是页面中的 ajax 回调函数。 但在我浪费时间探索之前,我敢肯定以前一定有人做过。有小费吗?

仅更新节点变量并调用field_attach_update() 是否足够?那么安全呢?

【问题讨论】:

    标签: javascript drupal drupal-7


    【解决方案1】:

    为了安全:

    您可以确保菜单挂钩使用正确的权限访问

    在菜单挂钩中:

     $items['/ajax/%/edit'] = array(
        'title' => 'something',
        'page callback' => 'your_edit_callback',
        'page arguments' => array(1),
        'access callback' => 'node_access',
        'access arguments' => array('update', 1),
        'type' => MENU_LOCAL_TASK,
      );
    
    function your_edit_callback($node_id){
    //something that edits the node here, only user(s) with node_access will be able to get here.
    }
    

    关于节点访问: * 在确定节点的访问权限时,node_access() 首先检查 * 用户是否有“绕过节点访问”权限。此类用户有 * 不受限制地访问所有节点。用户 1 将始终通过此检查。

    我个人从未使用过 field_attach,但依赖于 node_save。

    $node = node_load($node_id);
    $node->field_fieldname[LANGUAGE_NONE][0]['value'] = "monkeys";
    node_save($node);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 2019-07-09
      • 1970-01-01
      相关资源
      最近更新 更多