In response to Clive's comments under my question I have setup a project on drupal.org and issue to the Entity module issue queue as adding this functionality appears to be the best action. This would be the first contribution I've made so I'm eager for others to take on co-maintenance.
After I've thought a bit on how to go about doing this (still very open to suggestions) I'll add code etc. For the time being Clive's suggestion of using Entity module might be right but I've not yet checked it all out.
In the meantime, here is the code I was using (just as a fairly straight-forward form callback) with a form and call_user_func_array() passing through the callback the user would have used. That's just in a basic custom module I called entity_to_form because tbh that's all I know how to do at the moment).
code:
/**
* Form callback
*
* @param entity type, existing entity type as in entity_load() $entity_type
* @param callback, as in call_user_func_array() $callback
* @param array, as in call_user_func_array() $param_arr
*/
function entity_to_form_new_form($form, &$form_state, $entity_type, $callback) {
// if not a valid entity type, set error and return
$info = entity_get_info($entity_type);
if (!is_array($info)) {
global $user;
$variables = array(
'%uid' => $user->uid,
'%timestamp' => time(),
'%callback' => $callback,
'%param_arr' => json_encode($param_arr),
);
watchdog('entity_to_form', 'callback not existing: error during function
entity_to_form_new_form() timestamp = %timestamp, uid = %uid,
callback = %callback, param_arr = %param_arr', $variables,
WATCHDOG_ERROR, $link = NULL);
drupal_set_message('An error occurred and processing did not complete',
'error');
return;
}
// if not a valid callback, set error and return
if (!function_exists($callback)) {
global $user;
$variables = array(
'%uid' => $user->uid,
'%timestamp' => time(),
'%callback' => $callback,
'%param_arr' => json_encode($param_arr),
);
watchdog('entity_to_form', 'callback not existing: error during function
entity_to_form_new_form() timestamp = %timestamp, uid = %uid,
callback = %callback, param_arr = %param_arr', $variables,
WATCHDOG_ERROR, $link = NULL);
drupal_set_message('An error occurred and processing did not complete',
'error');
return;
}
// get information about the entity properties and custom fields
$property_info = entity_get_all_property_info($entity_type);
// dynamically set elements for the properties and custom fields
// fullfil the final requirements for the submit handler
$form['entity-to-form']['submit-callback'] = array(
'#type' => 'value',
'#value' => $callback,
);
$form['entity-to-form']['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
return $form;
}
/**
* Form submit handler
*/
function entity_to_form_new_form_submit($form, &$form_state) {
$callback = $form_state['values']['submit-callback'];
$variables = '';
call_user_func_array($callback, $variables);
}