0

I have the following structure in a content type:

. field_collection_parent (multiple value = 7)

.. computed field (single value)

.. field_collection_child (unlimited multiple value)

field_collection_parent represents the days of the week and field_collection_child are some work reports of each day. The computed field returns the day (monday, tuesday, etc.)

The problem is that I can have data in the first and thrid items of the field_collection_parent (that is Monday and Wednesday), but when I save the node, I only have two rows, because the second was empty, and computed returns Monday and Tuesday.

So, is it possible to get the weight of each field collection item although they were empty, and code it in the computed field?

Thanks.

P.D. I tried

$wrapper = entity_metadata_wrapper('field_collection_item', $entity);
$entity_field[0]['value'] = print_r($wrapper->delta(), true);

as indicated in "how to get weight or delta of current field collection item that is being computed" but it returns "Fatal error: Call to undefined method EntityDrupalWrapper::delta()"

  • Drupal's entity API does not store empty slots of multi-value fields in the DB. But you could store a magic value (e.g. -1) for those unset empty weekdays. – Hudri Apr 3 at 7:17
0

Ok, finally I got a workaround. I was focussed on entities and computed field, but it turned out to be a death end. So, I change the approach and found the rules_form module.

This modules allows apply a rule in the node form, so I created an integer field called delta in my field_collection_parent and populate it with rules when the form is created. In this way, I always keep a seven-rows field_collection_parent even though the field_collection_child is empty (because the field delta is filled).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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