1

How can I create field collection in another field collection using Drupal 7 Entity?

The field structure is given below;

Content type: Properties

  • field_1

  • field_2

  • field_collection_1 (I can create this field collection with the below fields)

        - field_1

        - field_2

        - field_collection_2 (But I cannot create/edit this field)

Code which I'm using to create the field_collection_1.

$fc_item = entity_create('field_collection_item', ['field_name' => 'field_property_options_col']);
$fc_item->setHostEntity('node', $property);
$fc_wrapper = entity_metadata_wrapper('field_collection_item', $fc_item);
$fc_wrapper->field_room_name->set($roomName);

Any idea?

2
  • Any idea why the code you don't show us isn't working? Please update your question so we can help you to move on.
    – leymannx
    Commented Aug 16, 2018 at 20:27
  • @leymannx Apologies, the code added which I'm using to create the field collection for the desired node. Commented Aug 16, 2018 at 22:30

0

Your Answer

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

Browse other questions tagged or ask your own question.