是否可以自定义 drupal 节点引用并传递您的搜索和来自另一个字段的参数 [英] Is it possible to customise drupal node reference and pass your search and a argument from another field

查看:21
本文介绍了是否可以自定义 drupal 节点引用并传递您的搜索和来自另一个字段的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 drupal 中创建一个带有节点引用字段的定制表单.

I'm trying to create a bespoke form in drupal, with a node reference field.

我想为节点引用自动完成添加一些额外的功能.我创建了一个包含参数的视图.我希望能够将该参数从下拉列表以及键入的文本传递到自动完成脚本中.

I'd like to add a little extra functionality to the node reference auto complete. I've created a view, that contains an argument. I'd like to be able to pass that argument from a drop down as well as the typed text into the autocomplete script.

有谁知道我会如何开始.

Does anyone know how I'd start this off.

/* FIELD 1 - the drop down  */
    $sql = "SELECT nid, title  FROM node where type='resourcetype' AND status =1 order by title
    ";
       $result = db_query($sql);
     $counter = 0 ;
     $options = array();
      while ($data = db_fetch_array($result)) {
       // krumo ($data);
      $options[$data[nid] ] =     $data[title]   ;
      if ($counter ==0 ) {$df = $data[nid]; }
      $counter ++;


      }


/* FIELD 2 - the node reference field  */    
         $form['sor']['type'] = array(
        '#type' => 'select',
        '#title' => t('Resource type'),
      '#required' =>TRUE,
      '#options' => $options,
      )     ;


      $form['sor']['field_asor_sors'] = array(
        '#type' => 'textfield',
        '#title' => t('Add a SOR item to this job'),
      '#autocomplete_path' => 'nodereference/autocomplete/field_asor_sors',
           '#element_validate' => array('myelement_validate_is_valid_noderef'),
      '#required' =>TRUE,

      );

非常感谢

马特

推荐答案

AFAIK 没有简单的方法可以做到这一点.

AFAIK there is no easy way to do this.

我之前想做类似的事情(使用基于节点上下文的不同参数),但没有这样做,因为它需要对自动完成回调逻辑进行一些重大更改.您需要更改几个 nodereference 函数以添加对将参数传递给初始回调 nodereference_autocomplete() 的支持,然后将其从那里传递给 _nodereference_potential_references(),最后_nodereference_potential_references_views(),同时确保更改不会破坏其他任何内容.

I wanted to do something similar a while ago (using different arguments based on node context), but refrained from doing it, since it would've needed some significant changes of the autocomplete callback logic. You'd need to change several nodereference functions to add support for passing an argument to the initial callback nodereference_autocomplete(), passing it on from there to _nodereference_potential_references(), and finally to _nodereference_potential_references_views(), while ensuring that the changes don't break anything else.

如果你仍然想尝试,你应该看看这个线程中的补丁,因为他们也想做类似的事情,并且可能包含一些有用的提示/示例.

If you want to try nonetheless, you should take a look at the patches in this thread, as they also want to do something like that and might contain some useful hints/examples.

一个可能更简单的替代方法可能是将 nodereference 字段的 #autocomplete_path 回调与您自己的将生成结果的自定义版本交换,同时将 js 逻辑添加到您的下拉列表中以添加额外的参数选择更改时的路径.

A potentially easier alternative might be to exchange the #autocomplete_path callback of the nodereference field with your own custom version that would generate the result, while adding js logic to your dropdown to add an additional argument to that path when the selection changes.

这篇关于是否可以自定义 drupal 节点引用并传递您的搜索和来自另一个字段的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆