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

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

问题描述



我想在drupal中创建一个定制表单,其中包含一个节点引用字段。我想为节点引用添加一些额外的功能自动完成我创建了一个视图,它包含一个参数。我希望能够将这个参数从下拉列表中输入到自动完成脚本中。



有谁知道我将如何开始关闭。

  / * FIELD 1  - 下拉菜单* / 
$ sql =SELECT nid,title FROM node其中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 - 节点引用字段* /
$ form ['sor'] ['type '] = array(
'#type'=>'select',
'#title'=> t('资源类型'),
'#required'=> TRUE,
'#options'=> $ options,
);


$ form ['sor'] ['field_asor_sors'] = array(
'#type'=>'textfield',
'#title' => t('向此作业添加SOR项目),
'#autocomplete_path'=>'nodereference / autocomplete / field_asor_sors',
'#element_validate'=>数组('myelement_validate_is_valid_noderef '),
'#required'=> TRUE,

);

非常感谢



Matt

解决方案

AFAIK没有办法做到这一点。



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



如果你想尝试,你应该看看补丁在这个线程,因为他们也想做这样的事情,可能包含一些有用的提示/示例。



一个可能更容易的替代方法可能是交换 #autocomplete_path 使用您自己的自定义版本回调节点字段,该自定义版本将生成结果,同时将js逻辑添加到下拉列表中,以便在选择更改时向该路径添加一个附加参数。


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,

      );

Many Thanks

Matt

解决方案

AFAIK there is no easy way to do this.

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.

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天全站免登陆