Currently there is no way in entity form to support a widget that can be used to edit several entities directly like the following example:

Screenshot

- inline_entity_form_single only works for cardinality 1, and does not respect cardinality.
- inline_entity_form mandates that you have an UX where you can only edit one entity at a time.

After talking with Bojan, he suggested I could fix inline_entity_form_single to support cardinality or name a new widget that would use most of its logic but support multivalue direct edit.

Comments

Initial patch attached. It adds a new widget and reuses most of the logic of already available widgets. Support for correct order of values and does not insert blank values.

Status:Active» Needs review

For reviewing

Status:Needs review» Needs work

it seems the path couldn't be applied as it is, there's an issue about the paths used for the changed files (/docroot/sites/all/modules/contrib/inline_entity_form/ shouldn't be present in these paths).

and it seems it has errors for Commerce products - tried with Commerce Kickstart:
Notice: Undefined index: sku in CommerceProductInlineEntityFormController->entityForm() (line 192 of /kickstart_path/profiles/commerce_kickstart/modules/contrib/inline_entity_form/includes/commerce_product.inline_entity_form.inc).

We should modify the "single" widget to behave like this when cardinality is > 1, and rename the widget to "simple" then (so we have "Simple" and "Complex", complex being the regular multiple values one with the table and "add existing").

Bojan,

The idea will then be to have a patch that fixes the behavior of single to support multiple cardinality and renames the widget as well?

Yes.

I tried applying the patch to latest IEF and it was rejected:

[mac:kristen:inline_entity_form]$ patch -p1 < inline_entity_form.multiple_direct_widget.1960686.patch
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/docroot/sites/all/modules/contrib/inline_entity_form/inline_entity_form.module b/docroot/sites/all/modules/contrib/inline_entity_form/inline_entity_form.module
|index d5fb20a..91d715d 100644
|--- a/docroot/sites/all/modules/contrib/inline_entity_form/inline_entity_form.module
|+++ b/docroot/sites/all/modules/contrib/inline_entity_form/inline_entity_form.module
--------------------------
File to patch: inline_entity_form.module
patching file inline_entity_form.module
Hunk #2 succeeded at 457 (offset -13 lines).
Hunk #3 succeeded at 477 (offset -13 lines).
Hunk #4 succeeded at 487 (offset -13 lines).
Hunk #5 succeeded at 731 (offset -10 lines).
Hunk #6 FAILED at 877.
Hunk #7 succeeded at 951 (offset 14 lines).
1 out of 7 hunks FAILED -- saving rejects to file inline_entity_form.module.rej

Would the development of this feature be continuing? It seems to be what could be an important organic feature of the core - to have multiple entities entry widget similar to fields (with Add and Remove buttons and cardinality from 1 to unlimited). Sometimes it would be much more efficient than using the field collection module.

Issue summary:View changes

I tried using the patch using patch command and also by using manual way. The function mentioned in the patch as @@ -855,6 +887,37 @@ function inline_entity_form_process_entity_form(&$entity_form, &$form_state) {} does not exist in inline_entity_form module.

Title:New widget to allow direct edit of multiple referenced entities directlyNew widget to allow editing multiple entities directly (ala Field Collection)
StatusFileSize
new5.84 KB

I've been rerolling this, but the API has changed sufficiently and I haven't worked out the correct replacement for the following:

***************
*** 891,896 ****
    // If validation passed, execute the submission handler.
    if (!form_get_errors()) {
      $controller->entityFormSubmit($entity_form, $form_state);
      $entity = $entity_form['#entity'];
--- 923,959 ----
    // If validation passed, execute the submission handler.
    if (!form_get_errors()) {
+
+     // Check if values are empty if we are in direct edit.
+     $entity_values = drupal_array_get_nested_value($form_state['values'], $entity_form['#parents']);
+     $values_excluding_fields = $info['fieldable'] ? array_diff_key($entity_values, field_info_instances($this->entityType, $bundle)) : $entity_values;
+
+     // In case of multiple direct edit we can't insert blank values.
+     if (isset($entity_form['#multiple_direct_edit'])) {
+       $is_entity_empty = TRUE;
+       foreach ($values_excluding_fields as $key => $value) {
+         $info = field_info_field($key);
+
+         // Not a valid field.
+         if (empty($info)) {
+           continue;
+         }
+
+         // Ignore checkboxes.
+         if ($info['type'] == 'list_boolean') {
+           continue;
+         }
+
+         $function = $info['module'] . '_field_is_empty';
+         if (!($function($value[LANGUAGE_NONE][0], $info))) {
+           $is_entity_empty = FALSE;
+         }
+       }
+
+       // Entity is blank, ignore it.
+       if ($is_entity_empty) {
+         return;
+       }
+     }
+
      $controller->entityFormSubmit($entity_form, $form_state);
      $entity = $entity_form['#entity'];
***************

The attached file includes everything else.

One small thing - I renamed the widget from "inline_entity_form_multiple_direct_edit" to "inline_entity_form_multiple_edit".

Lets move the feature request to have a table-based edit form into a new issue: #2238003: New widget: multiple items, table-based editor

Status:Needs work» Needs review
StatusFileSize
new6.84 KB

This might be it, but I suspect inline_entity_form_entity_form_submit() needs work.

Status:Needs review» Needs work

The patch needs some work - while the fields show up correctly, they're not handling the validation correctly.