1

I have three content types :

  • Classroom (some fields)
  • Student (some fields and one EntityReference to Classroom)
  • KMDone (some fields and a FieldCollection)

KMDone is a content type which contains : - a date - a FieldCollection "kmdone_students"

The FieldCollection "kmdone_students" contains itself - an EntityReference to the Student - a distance "go" (Numeric fied) - a distance "back" (Numeric fied)

Everything works fine except one point :

The generated form for the KMDone content-type requires to click several times on the "Add More" button to have enough rows for every student, choose one student on each select of each row, and then fill the form. Which is not confortable and can give some encoding errors due to user.

So, I would like to alter the form and prepopulate one "row" for each student.

It seems I have to work with the hook_form_alter hook, but how can I can I prepopulate one "row" in the FieldCollection (as if the user clicked on "Add more" button) for each EntityReference ? To say it in other words : if the original form SelectBox have 17 students, I would like then to prepopulate 17 rows and set the EntityReference field for each student.

Many thanks in advance for your tips !

Kind regards,

0

Short answer is : You can't via hook_form_alter

Long answer : there is a workaround there : https://www.drupal.org/node/1337804

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.