I notice the form callback for the product inline form does this:

  // Ensure this include file is loaded when the form is rebuilt from the cache.
  $form_state['build_info']['files']['inline_form'] = drupal_get_path('module', 'inline_entity_form') . '/includes/commerce_product.type.inc';

Given the path and name of this file gets defined in hook_inline_entity_type_info(), could inline_entity_form_field_widget_form() take care of setting this and save each implementation of this a bit of work?

Comments

joachim’s picture

Status: Active » Needs review
StatusFileSize
new2.82 KB

Here's a patch which seems to work. At least, nothing blows up with it ... inline_entity_form_field_widget_form() has to be the longest function I've ever seen so I'm not 100% sure of what I'm doing in there :)

joachim’s picture

Added some docs about this feature.

bojanz’s picture

Title: handle file inclusion in the module rather than the callbacks » Simplify the type forms
StatusFileSize
new14.51 KB

Okay, so we have two problems:
1) Type forms contain things that can be added automatically (the pre_render callback, the final #element_validate callback, the build_info).
2) The inline_entity_form_field_widget_form() function is a huge barely-understandable monster.

Here's a refactoring that handles #1 and makes #2 better.
This was also a requirement for easily adding a form alter hook for type forms without making #2 even worse.

bojanz’s picture

Status: Needs review » Fixed

Aaand, committed. Feel free to comment on the patch, it's never too late for a followup :)

joachim’s picture

> 2) The inline_entity_form_field_widget_form() function is a huge barely-understandable monster

Heh, yes. I barely understand it :(
The patch does look like it simplifies quite a few things. Will try another stab at implementing something with this soon!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.