0

I have a site which shows paintings by artists. On each painting page there is a section called 'related paintings'. This is a related field which provides the admin user the ability to tick other related paintings.

I would like to tick paintings by the same artist by default, so admin doesn't have to do it. I initially did this and it works, but obviously only ticks one painting:

return array(
    0 => array('nid' => '278')
);

Then I tried this, which does work in a template, i.e. it produces an array in the right format:

$artist_nid = $node->field_artist[0]["nid"];
$artist_paintings = node_load($artist_nid)->field_painting_nodes[0]              ["items"];
$a = array();
foreach ($artist_paintings as $painting)  {
   $a[] = array('nid' => $painting["nid"]);
}

But this doesn't work when called, I get the error:

warning: Invalid argument supplied for foreach() in /home/will/sites/modernprints/www/sites/all/modules/cck/content.module(2220) : eval()'d code on line 4.    

I'm guessing that $node doesn't exist or something in that context? What variables are available?

4

1 回答 1

0

我刚刚意识到我正在尝试做的是完全有缺陷的 - 添加新绘画时节点还不存在,所以你无法获得艺术家和艺术家的绘画。

如果用户先保存它可能会起作用,但它不是很方便。

正确执行此操作的唯一方法是使用javascript,即一旦用户选择了艺术家来选择相关绘画复选框,就会触发一个事件。

于 2013-10-26T13:20:17.450 回答