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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hernani’s picture

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.

hernani’s picture

Status: Active » Needs review

For reviewing

vasike’s picture

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).

bojanz’s picture

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").

hernani’s picture

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?

bojanz’s picture

Yes.

Kristen Pol’s picture

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

almc’s picture

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.

arpitr’s picture

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.

DamienMcKenna’s picture

Title: New widget to allow direct edit of multiple referenced entities directly » New widget to allow editing multiple entities directly (ala Field Collection)
FileSize
5.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".

DamienMcKenna’s picture

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

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
6.84 KB

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

DamienMcKenna’s picture

Status: Needs review » Needs work

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

DamienMcKenna’s picture

The patch also fails to provide a way to remove items from the list or provide a way to add new ones. It really needs some work :-\

DamienMcKenna’s picture

I'm going to try redoing this to just auto-open the edit form for the existing multi-item widget, see if that works.

DamienMcKenna’s picture

This is a WIP patch that will, eventually, provide a checkbox on the field settings page that lets entities always load the 'edit' form, and it replaces the 'cancel' button with the 'remove' button. There are still problems with it, e.g. sorting doesn't work, and saving the form creates all sorts of crazy errors, and there isn't a checkbox to enable the always-edit option (it's basically hardcoded), but I wanted to save what I have so far.

DamienMcKenna’s picture

Title: New widget to allow editing multiple entities directly (ala Field Collection) » Option to allow editing multiple entities directly (ala Field Collection)
Status: Needs work » Needs review
FileSize
6.3 KB

Further WIP, there's now a field setting to control whether the multi-edit functionality is loaded, completely removing the need for a separate widget. I still need to fix a problem where you get a face/screen full of error messages, but the data is at least being saved correctly.

DamienMcKenna’s picture

Oops, forgot to include a change to "includes/entity.inline_entity_form.inc".

DamienMcKenna’s picture

After some further testing, the errors I was seeing were because of #2237097: Support for inline_entity_form, this patch seems to work nicely.

capnut’s picture

The patch does work and it's great usability improvement for specific cases!

Additional suggestions:
* add a button with functionality to save all edited items at once
* add an ability to choose a specific display style to control how the actual nested form looks like -- although it is probably a scope for a new widget altogether

DamienMcKenna’s picture

@capnut: IIRC, hitting save on the parent entity will cause the sub entities to also save.

capnut’s picture

Indeed, "save" on parent entity saves the new values or changes of entities in inline entity form with multi-edit enabled as well :)

DamienMcKenna’s picture

FileSize
7.55 KB

A small tweak, this ass the 'form-actions' class to the actions button group.

vasike’s picture

I can confirm the latest patch worked.

There is a new patch that adds to previous patch:
1. Sorting/Ordering, also fix the ordering for default open Edit forms.
2. Remove the Fields Headers for Multi-edit (fields cells with colspan).
3. Remove the Save/Update button for Multi-edit, i don't think we need this for All Open edit forms.
4. Use "Product title (SKU)" for Fieldset title of every product on Multi-edit.

I hope we're closer now.

daulet2030’s picture

I tried the patches against Inline Entity Form 7.x-1.5+6-dev it has some conflicts and doesnt work properly. What version are these patches for? Am I missing something?

DamienMcKenna’s picture

Status: Needs review » Needs work

Looks like we need a reroll.

CatherineOmega’s picture

daulet2030: the patch in #24 applies cleanly to 7.x-1.5+6-dev for me. Did you attempt to apply any others?

daulet2030’s picture

Well, silly me, I started applying from patch #10 through #24, when I just need to apply #24!
It works, it opens edit forms for all entities referenced if you tick "multi-edit".
However, it's still not in table form(as shown in picture). As I understand from code, it only supports table form for commerce module. A generic entity will need to define its own inline entity form controller with overriden EntityInlineEntityFormController::tableFields() to display its fields in a table row?

DamienMcKenna’s picture

@daulet2030: We're focusing this issue on making the multi-edit functionality work in the first place, #2238003: New widget: multiple items, table-based editor is focused on making it work as a table.

daulet2030’s picture

Yeah, sorry about that, you already stated that in #11. I got confused by the picture.

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
10.51 KB

Rerolled.

DamienMcKenna’s picture

DamienMcKenna’s picture

I believe the latest patch has a problem with file fields, when attaching a file it gives the following error:
Notice: Array to string conversion in form_process_checkbox() (line 3217 of includes/form.inc).

iampuma’s picture

Tested the latest patch from #31 against 7.x-1.5 and it works great. I did not have any file field issues though.

nmalinoski’s picture

One thing this would help with is display of custom entities that do not use the title attribute (Such as those that can be created with ECK); if you don't specify a title, all you get is a nid, which isn't helpful at all.

szeidler’s picture

Not sure, if that issue is still meant to be active. I had the same use-case and needed rerolled the patch. It should work against the current dev, which also applies to 7.x-1.8.

edit: sorry. there seems to be a major issue with the attached patch. I will investigate what it's all about

Status: Needs review » Needs work

The last submitted patch, 36: inline_entity_form-n1960686-36.patch, failed testing.

szeidler’s picture

ptsimard’s picture

@szeidler, have you found what was the issue with your patch?

While content modeling today I ran into this exact use case and issue that #35 is talking about (ECK without title).

bdone’s picture

re-roll of #30 against 7.x-1.x (492f460d), with screenshots.