Hopefully this is in the right place! This post largely relates to the entityform module (https://drupal.org/project/entityform). That in itself is based on Model (https://drupal.org/project/model), as are the other entities I have created.
I need to create entityform-types dynamically and automatically based on the creation of another object, and via a button. I also need to populate them based on the content of other entities.
I can usually do anything I need to in Drupal via configuration, albeit I have created (simple) modules before. On this occasion prior to getting this far down the line, I had identified a code snippet to allow for the creation of entityforms - however upon getting to this step I now realise that it actually creates entityform submissions, based on an existing entityform. As of this moment I am actively trying to solve this with a deadline looming.
(This is actually very simplified, but should answer the core questions involved - I apologise for the length, I could see a way of shortening it!).
I have an entity called a company, with various fields (in the example I will use 'acme').
I have an entity called a task, with various fields, that include a 'multiple' text field called 'information'. (i.e. it might exist once, or ten times per task)
I have an entity called an guide. It has an entity reference field, that allows multiple questions to be selected, and a singular entity reference field to select the guides 'parent' company. (in the 'acme' guide, lets assume I pick 5 tasks)
there are various filters, and an entity view to decide which tasks can be selected in a given guide, but that is a sideline.
Given that I have selected a company, via the 'guide' entity that relates to it, I should now know the tasks that are relevant for the company.
I can produce views output that show me that all of this is working.
I now create an entity called 'questions'. It contains a multiple choice question with 5 answers, and a boolean yes/no, and I relate it (again via entity reference) to a company.
Given all of the above, I now want to create (dynamically) my entity form, so all of the employees (users) of acme can fill it out.
The logic for creating and populating the entityform-type, is something like this:
For a given company, identify the guide that relates to it.
Use the data in the guide to identify all of the tasks that are in the guide.
Add the questions in the companys 'question' entity to the guide once per task. (i.e. the same questions, will be asked 5 times, but in each case the answers are task specific), with each 'set' of questions on a unique page.
Add each individual task title to the guide (once per page), alongside the task 'information fields' (once per page).
The end result should be a multipage form, that can be filled in by multiple users. Each page will contain a unique task title, information about the task, and two questions.
Ultimately I need to be able to report on the surveys (views and google charts) by company.
My first task is to create new entities programatically from my own module, and not via the UI provided by entitymodel. I guess the create code would sit in a custom function, and be triggered by a button on the company page - thus passing to the function the ID of the company concerned.
If I want to create a new entityform-type (i.e. 'Acme Interview') am I looking into the generic entity api - or is there a better way of creating a new object that is already based on the 'model' project ?
I am imagining that I can get the result of a view in code (am sure I have seen this code), and use that in a php loop with a 'for each one do this'.
With the details of the 'do this' being put to one side - is this the right approach ?
Does anyone have anything I can review to help me get started ?
Any suggestions or feedback are welcome!