Question

I have a student books products in drupal 7 which they have a companion teacher's book product. I want to make a view mode that presents the student book (product display) along with an entity reference to teacher's book which is also a book product. Thing is that I can display the either id, title, or rendered entity but not other entity fields. I want to display is this:

Student's ISDN: ______

Teacher's's ISDN: ______

... Other product fields (Student) ...

I 've tried several modules like display suite but nothing, can you please help? what I 'm missing?

Was it helpful?

Solution 2

I did it this way:

  // 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;

OTHER TIPS

A quick solution is to create a new node template for your content type. E.g: node--student.tpl.php, then use the following code as example:

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

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top