Node Reference Drupalフィールドの重要なタスク

CCKモジュールが提供する最も有用なフィールドの1つはNode Referenceです。 そのタスクは簡単で理解しやすい-サイトのコンテンツと関係を結びつけることです。これは例で簡単に理解できます。



私が直面しなければならなかったタスクは、このフィールドを表示する方法です。





デフォルトでは、CCK自体が複数または単一のノード参照選択をリストまたは対応するノードへのリンクとして作成します。 レシピを見つけるタスクは、レシピと材料がノードであることを前提としています。



したがって、Viewsを使用してコンテンツをレンダリングすると、次の結果が得られます。



ブルガリアチキン(レシピ)


  1. 鶏肉(材料)
  2. オレンジ(成分)
  3. スパイス(材料)


代わりに:



ブルガリアチキン(レシピ)


  1. 1鶏肉(材料)
  2. 2オレンジ(成分)
  3. 50gスパイス(材料)


残念ながら、GoogleとDrupal.orgでこの問題の解決策を見つけられなかったため、外に出なければなりませんでしたが、非常にシンプルで美しいことがわかりました。



Productノードに対して、別のTextマルチポールを追加します。これは、ノード参照の後にフィールドビューに配置します。



また、views-view-fields.tpl.phpテンプレート(または必要に応じて特定のビュー)に、マジックを記述します。



<?php

$nids = array();

?>

<?php foreach ($fields as $id => $field): ?>

<?php

if($id == 'field_product_nid') {

$nids = array_shift($field->handler->field_values);

continue;

}



if($id == 'field_product_title_value') {

$items = array();

$index = 0;

$titles = array_shift($field->handler->field_values);

foreach($titles as $title) {

$items[] = l($title['value'], 'node/' . $nids[$index++]['nid']);

}

// TODO: theming here

$field->content = theme('item_list', $items);

}

?>

<?php if (!empty($field->separator)): ?>

<?php print $field->separator; ?>

<?php endif; ?>



<<?php print $field->inline_html;?> class="views-field-<?php print $field->class; ?>">

<?php if ($field->label): ?>

<?php print $field->label; ?>:



<?php endif; ?>

<?php

// $field->element_type is either SPAN or DIV depending upon whether or not

// the field is a 'block' element type or 'inline' element type.

?>

<<?php print $field->element_type; ?> class="field-content"><?php print $field->content; ?></<?php print $field->element_type; ?>>

</<?php print $field->inline_html;?>>

<?php endforeach; ?>









これにより、タイトルフィールドのノード参照が置き換えられ、ビューがレンダリングされます。 この問題の解決策はありますか?



All Articles