Skip to main content
EDIT 2
Source Link
Kojo
  • 3.5k
  • 4
  • 33
  • 62

How can I properly render a field collection ? Is there any specific function for that ? I tried field_view_field but it does not output children fields.

My field collection is attached to a line item entity, and I want to display it in a Commerce checkout pane review.

function mymodule_pane_review($form, $form_state, $checkout_pane, $order) {
  //loading line item
  $line_item = commerce_line_item_load($order->commerce_line_items['und'][0]['line_item_id']);
  //loading field_collection from its id
  $paxsup = entity_load('field_collection_item', array($line_item->field_paxsup['und'][0]['value']));
  
  return drupal_render(field_attach_view('field_collection_item',$paxsup, 'full'));
}

but get an error EntityMalformedException: Missing bundle property on entity of type field_collection_item

EDIT : I got a step forward, with the use either of

$paxsup$paxsups = entity_load('field_collection_item', array($line_item->field_paxsup['und'][0]['value']));
$paxs$paxsup = end($paxsup$paxsups);
//or shortcut, as per Marcvangend
$paxs$paxsup = field_collection_field_get_entity($line_item->field_paxsup['und'][0]);

dsm($paxs$paxsup) now returns

dsm($paxs)dsm($paxsup)

So I can output a child field with

$view = field_view_field('field_collection_item', $paxsp$paxsup, 'field_paxsup_civilite', $display);
return drupal_render($view);

ButEDIT 2: I feel stupidended chaining #markup

$display = array('label' => 'hidden');
$cv = field_view_field('field_collection_item', $paxsup, 'field_paxsup_civilite', $display);
$nom = field_view_field('field_collection_item', $paxsup, 'field_paxsup_nom', $display);
$prenom = field_view_field('field_collection_item', $paxsup, 'field_paxsup_prenom', $display);
$date = field_view_field('field_collection_item', $paxsup, 'field_paxsup_datenaiss', $display);
$view .= $cv[0]['#markup'] .' '. $nom[0]['#markup'] .' '. $prenom[0]['#markup'] .t(', né(e) le '). $date[0]['#markup'] ;

But I'm not to be able to concatenate field_view_field of each child fieldhappy with this "old style" solution, orwould have preferred to find a more elegant and simpleDrupal way to output that field collection

How can I properly render a field collection ? Is there any specific function for that ? I tried field_view_field but it does not output children fields.

My field collection is attached to a line item entity, and I want to display it in a Commerce checkout pane review.

function mymodule_pane_review($form, $form_state, $checkout_pane, $order) {
  //loading line item
  $line_item = commerce_line_item_load($order->commerce_line_items['und'][0]['line_item_id']);
  //loading field_collection from its id
  $paxsup = entity_load('field_collection_item', array($line_item->field_paxsup['und'][0]['value']));
  
  return drupal_render(field_attach_view('field_collection_item',$paxsup, 'full'));
}

but get an error EntityMalformedException: Missing bundle property on entity of type field_collection_item

EDIT : I got a step forward, with the use either of

$paxsup = entity_load('field_collection_item', array($line_item->field_paxsup['und'][0]['value']));
$paxs = end($paxsup);
//or shortcut, as per Marcvangend
$paxs = field_collection_field_get_entity($line_item->field_paxsup['und'][0]);

dsm($paxs) now returns

dsm($paxs)

So I can output a child field with

$view = field_view_field('field_collection_item', $paxsp, 'field_paxsup_civilite', $display);
return drupal_render($view);

But I feel stupid not to be able to concatenate field_view_field of each child field, or find a more elegant and simple way to output that field collection

How can I properly render a field collection ? Is there any specific function for that ? I tried field_view_field but it does not output children fields.

My field collection is attached to a line item entity, and I want to display it in a Commerce checkout pane review.

function mymodule_pane_review($form, $form_state, $checkout_pane, $order) {
  //loading line item
  $line_item = commerce_line_item_load($order->commerce_line_items['und'][0]['line_item_id']);
  //loading field_collection from its id
  $paxsup = entity_load('field_collection_item', array($line_item->field_paxsup['und'][0]['value']));
  
  return drupal_render(field_attach_view('field_collection_item',$paxsup, 'full'));
}

but get an error EntityMalformedException: Missing bundle property on entity of type field_collection_item

EDIT : I got a step forward, with the use either of

$paxsups = entity_load('field_collection_item', array($line_item->field_paxsup['und'][0]['value']));
$paxsup = end($paxsups);
//or shortcut, as per Marcvangend
$paxsup = field_collection_field_get_entity($line_item->field_paxsup['und'][0]);

dsm($paxsup) now returns

dsm($paxsup)

So I can output a child field with

$view = field_view_field('field_collection_item', $paxsup, 'field_paxsup_civilite', $display);
return drupal_render($view);

EDIT 2: I ended chaining #markup

$display = array('label' => 'hidden');
$cv = field_view_field('field_collection_item', $paxsup, 'field_paxsup_civilite', $display);
$nom = field_view_field('field_collection_item', $paxsup, 'field_paxsup_nom', $display);
$prenom = field_view_field('field_collection_item', $paxsup, 'field_paxsup_prenom', $display);
$date = field_view_field('field_collection_item', $paxsup, 'field_paxsup_datenaiss', $display);
$view .= $cv[0]['#markup'] .' '. $nom[0]['#markup'] .' '. $prenom[0]['#markup'] .t(', né(e) le '). $date[0]['#markup'] ;

But I'm not happy with this "old style" solution, would have preferred to find a more elegant and Drupal way to output that field collection

Tweeted twitter.com/#!/StackDrupal/status/502858535454388224
shortened question for clarity
Source Link
Kojo
  • 3.5k
  • 4
  • 33
  • 62

How can I properly render a field collection ? Is there any specific function for that ? I tried field_view_field but it does not output children fields.

My field collection is attached to a line item entity, and I want to display it in a Commerce checkout pane review.

function mymodule_pane_review($form, $form_state, $checkout_pane, $order) {
  //loading line item
  $line_item = commerce_line_item_load($order->commerce_line_items['und'][0]['line_item_id']);
  //rendering field collection named field_paxsup 
  $display = array('label' => 'hidden');
  $view = field_view_field('commerce_line_item', $line_item, 'field_paxsup', $display);
  return drupal_render($view);
}

This outputs an empty field. dsm(line_item->field_paxsup) gives me a integer value which is the field collection id. So I tried

function mymodule_pane_review($form, $form_state, $checkout_pane, $order) {
  //loading line item
  $line_item = commerce_line_item_load($order->commerce_line_items['und'][0]['line_item_id']);
field_collection from //loadingits field_collectionid
  $paxsup = entity_load('field_collection_item', array($line_item->field_paxsup['und'][0]['value']));
  
  return drupal_render(field_attach_view('field_collection_item',$paxsup, 'full'));
}

but get an error EntityMalformedException: Missing bundle property on entity of type field_collection_item

EDIT : I got a step forward, with the use either of

$paxsup = entity_load('field_collection_item', array($line_item->field_paxsup['und'][$n]['value']>field_paxsup['und'][0]['value']));
$paxs = end($paxsup);
//or shortcut, as per Marcvangend
$paxs = field_collection_field_get_entity($line_item->field_paxsup['und'][0]);

dsm($paxs) now returns

dsm($paxs)

So I can output a child field with

$view = field_view_field('field_collection_item', $paxsp, 'field_paxsup_civilite', $display);
return drupal_render($view);

But I feel stupid not to be able to concatenate field_view_field of each child field, or find a more elegant and simple way to output that field collection

How can I properly render a field collection ? Is there any specific function for that ? I tried field_view_field but it does not output children fields.

My field collection is attached to a line item entity, and I want to display it in a Commerce checkout pane review.

function mymodule_pane_review($form, $form_state, $checkout_pane, $order) {
  //loading line item
  $line_item = commerce_line_item_load($order->commerce_line_items['und'][0]['line_item_id']);
  //rendering field collection named field_paxsup 
  $display = array('label' => 'hidden');
  $view = field_view_field('commerce_line_item', $line_item, 'field_paxsup', $display);
  return drupal_render($view);
}

This outputs an empty field. dsm(line_item->field_paxsup) gives me a integer value which is the field collection id. So I tried

function mymodule_pane_review($form, $form_state, $checkout_pane, $order) {
  //loading line item
  $line_item = commerce_line_item_load($order->commerce_line_items['und'][0]['line_item_id']);
  //loading field_collection
  $paxsup = entity_load('field_collection_item', array($line_item->field_paxsup['und'][0]['value']));
  
  return drupal_render(field_attach_view('field_collection_item',$paxsup, 'full'));
}

but get an error EntityMalformedException: Missing bundle property on entity of type field_collection_item

EDIT : I got a step forward, with the use either of

$paxsup = entity_load('field_collection_item', array($line_item->field_paxsup['und'][$n]['value']));
$paxs = end($paxsup);
//or shortcut, as per Marcvangend
$paxs = field_collection_field_get_entity($line_item->field_paxsup['und'][0]);

dsm($paxs) now returns

dsm($paxs)

So I can output a child field with

$view = field_view_field('field_collection_item', $paxsp, 'field_paxsup_civilite', $display);
return drupal_render($view);

But I feel stupid not to be able to concatenate field_view_field of each child field, or find a more elegant and simple way to output that field collection

How can I properly render a field collection ? Is there any specific function for that ? I tried field_view_field but it does not output children fields.

My field collection is attached to a line item entity, and I want to display it in a Commerce checkout pane review.

function mymodule_pane_review($form, $form_state, $checkout_pane, $order) {
  //loading line item
  $line_item = commerce_line_item_load($order->commerce_line_items['und'][0]['line_item_id']);
  //loading field_collection from its id
  $paxsup = entity_load('field_collection_item', array($line_item->field_paxsup['und'][0]['value']));
  
  return drupal_render(field_attach_view('field_collection_item',$paxsup, 'full'));
}

but get an error EntityMalformedException: Missing bundle property on entity of type field_collection_item

EDIT : I got a step forward, with the use either of

$paxsup = entity_load('field_collection_item', array($line_item->field_paxsup['und'][0]['value']));
$paxs = end($paxsup);
//or shortcut, as per Marcvangend
$paxs = field_collection_field_get_entity($line_item->field_paxsup['und'][0]);

dsm($paxs) now returns

dsm($paxs)

So I can output a child field with

$view = field_view_field('field_collection_item', $paxsp, 'field_paxsup_civilite', $display);
return drupal_render($view);

But I feel stupid not to be able to concatenate field_view_field of each child field, or find a more elegant and simple way to output that field collection

edited body
Source Link
Kojo
  • 3.5k
  • 4
  • 33
  • 62

How can I properly render a field collection ? Is there any specific function for that ? I tried field_view_field but it does not output children fields.

My field collection is attached to a line item entity, and I want to display it in a Commerce checkout pane review.

function mymodule_pane_review($form, $form_state, $checkout_pane, $order) {
  //loading line item
  $line_item = commerce_line_item_load($order->commerce_line_items['und'][0]['line_item_id']);
  //rendering field collection named field_paxsup 
  $display = array('label' => 'hidden');
  $view = field_view_field('commerce_line_item', $line_item, 'field_paxsup', $display);
  return drupal_render($view);
}

This outputs an empty field. dsm(line_item->field_paxsup) gives me a integer value which is the field collection id. So I tried

function mymodule_pane_review($form, $form_state, $checkout_pane, $order) {
  //loading line item
  $line_item = commerce_line_item_load($order->commerce_line_items['und'][0]['line_item_id']);
  //loading field_collection
  $paxsup = entity_load('field_collection_item', array($line_item->field_paxsup['und'][0]['value']));
  
  return drupal_render(field_attach_view('field_collection_item',$paxsup, 'full'));
}

but get an error EntityMalformedException: Missing bundle property on entity of type field_collection_item

EDIT : I got a step forward, with the use either of

$paxsup = entity_load('field_collection_item', array($line_item->field_paxsup['und'][$n]['value']));
$paxs = end($paxsup);
//or shortcut, as per MarcavengerMarcvangend
$paxs = field_collection_field_get_entity($line_item->field_paxsup['und'][0]);

dsm($paxs) now returns

dsm($paxs)

So I can output a child field with

$view = field_view_field('field_collection_item', $paxsp, 'field_paxsup_civilite', $display);
return drupal_render($view);

But I feel stupid not to be able to concatenate field_view_field of each child field, or find a more elegant and simple way to output that field collection

How can I properly render a field collection ? Is there any specific function for that ? I tried field_view_field but it does not output children fields.

My field collection is attached to a line item entity, and I want to display it in a Commerce checkout pane review.

function mymodule_pane_review($form, $form_state, $checkout_pane, $order) {
  //loading line item
  $line_item = commerce_line_item_load($order->commerce_line_items['und'][0]['line_item_id']);
  //rendering field collection named field_paxsup 
  $display = array('label' => 'hidden');
  $view = field_view_field('commerce_line_item', $line_item, 'field_paxsup', $display);
  return drupal_render($view);
}

This outputs an empty field. dsm(line_item->field_paxsup) gives me a integer value which is the field collection id. So I tried

function mymodule_pane_review($form, $form_state, $checkout_pane, $order) {
  //loading line item
  $line_item = commerce_line_item_load($order->commerce_line_items['und'][0]['line_item_id']);
  //loading field_collection
  $paxsup = entity_load('field_collection_item', array($line_item->field_paxsup['und'][0]['value']));
  
  return drupal_render(field_attach_view('field_collection_item',$paxsup, 'full'));
}

but get an error EntityMalformedException: Missing bundle property on entity of type field_collection_item

EDIT : I got a step forward, with the use either of

$paxsup = entity_load('field_collection_item', array($line_item->field_paxsup['und'][$n]['value']));
$paxs = end($paxsup);
//or shortcut, as per Marcavenger
$paxs = field_collection_field_get_entity($line_item->field_paxsup['und'][0]);

dsm($paxs) now returns

dsm($paxs)

So I can output a child field with

$view = field_view_field('field_collection_item', $paxsp, 'field_paxsup_civilite', $display);
return drupal_render($view);

But I feel stupid not to be able to concatenate field_view_field of each child field, or find a more elegant and simple way to output that field collection

How can I properly render a field collection ? Is there any specific function for that ? I tried field_view_field but it does not output children fields.

My field collection is attached to a line item entity, and I want to display it in a Commerce checkout pane review.

function mymodule_pane_review($form, $form_state, $checkout_pane, $order) {
  //loading line item
  $line_item = commerce_line_item_load($order->commerce_line_items['und'][0]['line_item_id']);
  //rendering field collection named field_paxsup 
  $display = array('label' => 'hidden');
  $view = field_view_field('commerce_line_item', $line_item, 'field_paxsup', $display);
  return drupal_render($view);
}

This outputs an empty field. dsm(line_item->field_paxsup) gives me a integer value which is the field collection id. So I tried

function mymodule_pane_review($form, $form_state, $checkout_pane, $order) {
  //loading line item
  $line_item = commerce_line_item_load($order->commerce_line_items['und'][0]['line_item_id']);
  //loading field_collection
  $paxsup = entity_load('field_collection_item', array($line_item->field_paxsup['und'][0]['value']));
  
  return drupal_render(field_attach_view('field_collection_item',$paxsup, 'full'));
}

but get an error EntityMalformedException: Missing bundle property on entity of type field_collection_item

EDIT : I got a step forward, with the use either of

$paxsup = entity_load('field_collection_item', array($line_item->field_paxsup['und'][$n]['value']));
$paxs = end($paxsup);
//or shortcut, as per Marcvangend
$paxs = field_collection_field_get_entity($line_item->field_paxsup['und'][0]);

dsm($paxs) now returns

dsm($paxs)

So I can output a child field with

$view = field_view_field('field_collection_item', $paxsp, 'field_paxsup_civilite', $display);
return drupal_render($view);

But I feel stupid not to be able to concatenate field_view_field of each child field, or find a more elegant and simple way to output that field collection

edit : added search progress
Source Link
Kojo
  • 3.5k
  • 4
  • 33
  • 62
Loading
added 73 characters in body; edited title
Source Link
Kojo
  • 3.5k
  • 4
  • 33
  • 62
Loading
Source Link
Kojo
  • 3.5k
  • 4
  • 33
  • 62
Loading