实体引用在视图模式下使用其他字段

问题描述 投票:0回答:2

我有一个学生在 drupal 7 中使用书籍产品,他们有一个配套的教师书籍产品。我想制作一个视图模式,展示学生用书(产品显示)以及对教师用书(也是图书产品)的实体引用。 问题是我可以显示 id、标题或呈现的实体,但不能显示其他实体字段。我想显示的是这样的:

学生的 ISDN:______

教师的 ISDN:______

...其他产品领域(学生)...

我已经尝试了几个模块,例如显示套件,但没有任何效果,你能帮忙吗?我缺少什么?

php drupal drupal-7 drupal-modules drupal-commerce
2个回答
1
投票

一个快速解决方案是为您的内容类型创建一个新的节点模板。例如:

node--student.tpl.php
,则使用以下代码为例:

$referenced_node = node_load($node->field_ref[LANGUAGE_NONE]['0']['target_id']);
print node_view($referenced_node, "teaser");

希望这有帮助。


1
投票

我是这样做的:

  // Initial weight
  $weight = 2;
  // Student's book entity
  $student_book_entity = $node->field_student_book[LANGUAGE_NONE][0]['entity'];

  // Get Student's book ISBN and alter some attributes
  $student_isbn_field = array_merge(field_view_field('commerce_product', $student_book_entity, 'field_book_isbn'), array(
      '#field_name' => 'field_students_book_isbn',
      '#title' => t('Student\'s Book ISBN'),
      '#weight' => $weight++,
    )
  );
  $node->content['field_students_book_isbn'] = $student_isbn_field;

  // Teacher's book entity
  $teachers_book_entity = $node->field_teacher_book[LANGUAGE_NONE][0]['entity'];

  // Get Teacher's book ISBN and alter some attributes
  $teacher_isbn_field = array_merge(field_view_field('commerce_product', $teachers_book_entity, 'field_book_isbn'), array(
      '#field_name' => 'field_teachers_book_isbn',
      '#title' => t('Teacher\'s Book ISBN'),
      '#weight' => $weight++,
    )
  );
  $node->content['field_teachers_book_isbn'] = $teacher_isbn_field;
© www.soinside.com 2019 - 2024. All rights reserved.