I am in desperate need of help.

I have a custom entity called Question which has a bundle called data. Within the data bundle, I have a collection field called options with two subfields called correct_option & misc_option.


I am desperately trying to programmatically write data into those 2 option fields but the following code is not working:

$field_collection_item_value = 1596; // Get field collection item value.

$field_collection_item = entity_load('field_collection_item', array($field_collection_item_value)); // Load that field collection item.

$field_collection_item->save(); // Save field-collection item.

The 1569 is the ID of an existing question entity.

Whenever the code is executed I get the following error:

Fatal error: Call to a member function save() on array

I would appreciate any help. I'm at a loss and not sure how to get this working.

2 Answers 2


Please use below code for update existing field collection data

//$item_id load item id from your node
//enter_update_field_mechine_name replace with your field name  
  $field_collection_value = field_collection_item_load($item_id);
  $field_collection_value->enter_update_field_mechine_name['und'][0]['value'] = 'update text here';

This code worked for me Thank you


Based on CKL answer here is my code:

  function generar_pagos_abono_contrato_action($nid) {
    $node = node_Load($nid);
    $nw = entity_metadata_wrapper('node', $node);
    $abono = $nw->field_operacion_abono->value();
    if($abono > 0) {
      //  $fc = array feield collection obejets
      $fc = $nw->field_operacion_pagos->value();
      foreach ($fc as $k => $v) {
        // field collection values
        $monto = $v->field_pago_monto[LANGUAGE_NONE][0]['value'];
        $saldo = $v->field_pago_saldo[LANGUAGE_NONE][0]['value'];
        if($monto > $abono) {
            if($saldo > 0) {
              if($abono <= $saldo) {
                $saldo = $saldo - $abono;
                // set & save field collection field value
                $v->field_pago_saldo[LANGUAGE_NONE][0]['value'] = $saldo;
                drupal_set_message(t('Abono aplicado correctamente'), 'status', FALSE);
              } else {
                drupal_set_message(t('El valor del abono no puede ser mayor al saldo del pago'), 'warning', FALSE);
        else {
          drupal_set_message(t('El vaor del abono no puede ser mayor al valor del pago'), 'warning', FALSE);
        $nw->field_operacion_abono = NULL;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.