节点参考Drupal中的表 [英] Node Reference to Table in Drupal

查看:116
本文介绍了节点参考Drupal中的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Drupal与CCK,

我有一个名为Article的内容类型。

本文有5个节点引用。

我正在使用CCK中的表字段,我正在尝试将其连接到

的引用,因此每个文章[拥有表字段]

将有一个5列的表,每个产品一个

和可以根据用户想要的内容而改变的内容


但是我不太确定这样做,我尝试了

将这些产品添加到列中,一旦在参考文件中选择了

,那么它似乎迟钝了..有没有任何以前的解决方案?


要清除的图像

解决方案

您可以使用查看,但在我们达到之前,如果您对节点进行了一些更改,可能会更好。


  1. 而不是使用每个产品5个独立的节点参考字段,添加引用产品的一个节点参考字段。在该字段的配置中(在内容类型的管理字段选项卡上找到),将数值设置为 5 全局设置。


  2. 然后,删除tableview CCK字段。您不会需要它,因为您将要创建的视图将执行您想要执行的操作。


  3. 现在,转到网站建设 - > 视图 - > 添加。输入视图的名称;让我们说列表。您可以将描述标签更改为任何您想要的,但将查看类型设置为 Node 。 / p>


  4. 现在,设置视图。在字段下,添加要在产品表中显示的字段;假设 Node:Title Node:Body


  5. / em>,为节点添加一个过滤器:键入,以便视图只显示产品,而不显示其他类型的节点。


  6. 基本设置下,将 $ b

    现在,您将看到一个视图,显示表中的每个产品。下一步是限制该表仅显示特定节点引用的产品。


  7. 参数下,添加 Node:ID 。该视图现在将只显示与传递给视图的参数相匹配的ID的节点。


  8. 检查允许每个参数多个术语这将让您一次查找多个节点。


  9. 由于您不会手动传递这些参数,您将自动查看视图生成其寻找的参数。选择下提供默认参数


有几个选项可用,但不匹配您想要的选项:即所引用的节点的节点ID。所以,选择 PHP代码,以便您可以提供自定义参数。使用以下代码:

  $ arguments = array(); 
$ node = node_load(arg(1));

if($ node-> field_product){
foreach($ node-> field_product as $ product){
if($ product ['nid'])$ arguments [] = $ product ['nid'];
}
}

return implode(',',$ arguments);

这将查找页面的节点ID( arg(1) code>),检查它是否具有产品节点参考字段( $ node-> field_product ,更改 field_product 到您的字段的短名称),然后构建一个参数,其中包含引用的每个节点的ID。它返回参数列表,其格式为Views期望值: 1,2,3



现在的视图是完成:唯一需要做的是使视图出现在页面上。您可以创建一个阻止显示,然后将该块添加到站点构建 - > 之间的区域。如果您转到引用产品的页面,该块将与引用块的表一起显示。



如果要将视图作为节点本身的一部分,查看查看参考模块,该模块创建一个引用视图的CCK字段,非常像节点引用引用节点。


I have Drupal with CCK,
I have a content type named Article.
This Article has 5 Node references.
I'm using the table field in CCK and I'm trying to connect it to
the references, so each article [that holds a table field]
would have a table with 5 columns, one for each product
and content that can change according to what the user wants

However I'm not really sure how to do so, I tried
adding the products to the columns once they are chosen in the reference
via jquery, it seemed sluggish.. is there any former solution to this?

Image to clearify

解决方案

You can do this with a View, but before we get to that, it's probably better if you make a few changes to your node.

  1. Instead of using 5 separate node reference fields for each product, add one node reference field that references products. In the configuration for the field (found on the Manage fields tab for the content type) , set Number of values to 5 under Global settings.

  2. Then, get rid of the tableview CCK field. You won't need it as the view you're going to create will do what you're looking to do.

  3. Now, go to Site Building -> Views --> Add. Enter in a name for the view; let's say listing. You can change the Description and Tags to whatever you want, but leave the View type set to Node.

  4. Now, set up the view. Under Fields, add the fields you want to show up in your product table; let's say the Node: Title and the Node: Body.

  5. Under Filters, add a filter for Node: Type so the view will only show products and not other types of nodes.

  6. Under Basic Settings, change the Style from Unformatted to Table.

    You'll now have a view that'll display every product available in a table. The next stage of this is to limit that table to only display products that a particular node references. To do that, you'll create an argument.

  7. Under Arguments, add Node: ID. The view will now display only nodes with IDs that match the argument passed to the view.

  8. Check Allow multiple terms per argument, which will let you look up more than one node at a time.

  9. Since you won't be passing those arguments manually, you'll have the view automatically generate the arguments its looking for. Select Provide default argument under Action to take if argument is not present.

There are a few options available, but none match the one you want: that is, the node IDs for the nodes referenced. So, choose PHP Code so you can supply a custom argument. Use the following code:

$arguments = array();
$node = node_load(arg(1));

if ($node->field_product) {
  foreach ($node->field_product as $product) {
    if ($product['nid']) $arguments[] = $product['nid'];
  }
}

return implode(',', $arguments);

This will look for the page's node ID (arg(1)), check to see if it has the product node reference field ($node->field_product, change field_product to the short name of your field), then build an argument containing the ID of each node referenced. It returns the argument list in the format that Views expects: 1,2,3.

Now the view is complete: the only thing left to do is make the view appear on the page. You can create a Block display, then add that block to a region under Site building -> Blocks. If you go to a page that references products, the block will appear with the table of referenced blocks.

If you want the view to be a part of the node itself, look into the View Reference module, which creates a CCK field that references a view much like Node Reference references a node.

这篇关于节点参考Drupal中的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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