是否可以定制的Drupal节点的引用,并通过你的搜索和论证,从另一个领域你的、节点、领域、Drupal

2023-09-10 17:01:33 作者:酥心

我试图创建在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.

如果你想尝试但是,你应该看一看href="http://drupal.org/node/473670" rel="nofollow">这个线程在