I installed both

version = "7.x-1.0-beta1+6-dev"

and

version = "7.x-1.0-beta1"

Drupal 7.14

this modules is great but I cant add more than one product reference to my display node.

The site is multilingual but thats hardly the reason - cause I tried the same thing with a commerce kickstarter vanilla instlall.

I tried both versions from above- no luck...

Our use case is a 1-1 product-display ratio and this is not a problem... but....

Here is a small screencast of the bug.

http://bit.ly/drupal-commerce-inline-entity-form-module-cant-add-more-th...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

eme’s picture

Indeed, I can confirm the bug. Products are correctly added, but after saving, the product reference is not added it seems.

eme’s picture

Priority: Critical » Normal

Ok. I'm just silly : I've put 1 product only in the widget, and not illimited.

So it's no critical bug : just edit the widget type and put 'illimited'.

Still a bug, as it is not possible to configure the widget as not being unlimited : if so, the button is still there even if the specified number is reached.

rsvelko’s picture

aha! wow / omg / etc! Thanks dude .

I tested it after changing the reference field on the prod-display manage fields page - now all works...

So the module's fix would be:
- add a short text with a hint above of / on the same line to the "Add variation" button - a text saying: "currently this widget is set up to allow X products. To change that number go here ( link-url is admin/structure/types/manage/content-type-example/fields/field_example_reference"

What is left to be coded is to:
- find the place in the module where the form is generated
- add a "#after" / "#before" fomr API element with the hint
- to generate the hint - get the current node type and hyphenate its name if not done
- get all its entity fields and filter for a product reference
- build the settings page url and build the link with l() and t()

tadaaaa

anybody willing to crowdfund/sponsor this with 20 eur so that I will do it? Or maybe I will find some whole in my time and do it as usual 4 free...

Cheers..

rsvelko’s picture

this issue is a docs defficiency but we need the docs where appropriate in teh form itself... not hidden in the readme...

context based help is the next big drupal thing - imagine a tiny hover icon with a youtube vid related to each tiny button/setting in drupal ? This is context help. And I once saw a module for drupal is already here... forgot the name...

bojanz’s picture

Yeah, IEF needs to handle this better. It is currently only optimized for unlimited values.

I was thinking of not showing the add button anymore when cardinality is reached, and always showing a message notifying the user about the maximum allowed number of entities.

See also this issue: #1598296: Add a simplified widget for fields that accept only one entity of a specific type where I'm attempting to optimize for cardinality 1 (showing the inline form in a fieldset, no table, no buttons).

rsvelko’s picture

Category: bug » task

so this issue is redundant - lets make it a task then - a task to document
And with the pointed above tasks done a hint may become not necessary.

bojanz’s picture

Title: cant add more than one product with this module ! help » Optimize for cardinality > 1

Okay, so #1598296: Add a simplified widget for fields that accept only one entity of a specific type was committed, which means we now handle optimally both cardinality: 1 and cardinality: unlimited.

We now need to handle the other cases, by showing the maximum number of values in the widget #description, and hiding the "add" button once that number is reached.

andyg5000’s picture

Here's a patch that compares cardinality to number of entities referenced. It updates the $element description and prevents adding more entities if cardinality has been reached.

andyg5000’s picture

Status: Active » Needs review

Setting as needs review

joachim’s picture

Status: Needs review » Needs work

Quick eyeball review. All nitpicky fiddly stuff :)

+++ b/inline_entity_form.module
@@ -387,6 +388,22 @@ function inline_entity_form_field_widget_form(&$form, &$form_state, $field, $ins
+  $entity_count = sizeof($form_state['inline_entity_form'][$ief_id]['entities']);

sizeof is an alias of count according to PHP docs -- it's probably better code style to stick to one.

+++ b/inline_entity_form.module
@@ -387,6 +388,22 @@ function inline_entity_form_field_widget_form(&$form, &$form_state, $field, $ins
+  $cardinality == -1 ? $cardinality_count = 'Unlimited' : $cardinality_count = $cardinality;

FieldAPI has a special constant for the unlimited cardinality; don't use -1.

Also, shouldn't 'Unlimited' be translated?

+++ b/inline_entity_form.module
@@ -387,6 +388,22 @@ function inline_entity_form_field_widget_form(&$form, &$form_state, $field, $ins
+  if($cardinality > 0 && $entity_count >= $cardinality){

Needs a space after the if

+++ b/inline_entity_form.module
@@ -387,6 +388,22 @@ function inline_entity_form_field_widget_form(&$form, &$form_state, $field, $ins
+      return $element;

Indentation is wrong.

Also, comments need a full stop.

joachim’s picture

Category: task » bug

This also about how IEF lets me attempt to add further items, but then loses them if I've gone over the cardinality -- hence that's data loss and hence a bug :)

I've applied the patch and I can confirm it's no longer letting me go past the cardinality in the UI.

andyg5000’s picture

Status: Needs work » Needs review
FileSize
2.14 KB

Thanks for the review @joachim. Here's and updated patch.

marcin.wosinek’s picture

Status: Needs review » Reviewed & tested by the community

#12 patch works really nice. I've tested in commerce environment, and outside (reference from node to node).

@andyg5000 thanks for the patch!

bojanz’s picture

Status: Reviewed & tested by the community » Fixed

Tweaked the wording, made the message not show up if the field is unlimited, fixed a bug, committed. Huge thanks, Andy!

http://drupalcode.org/project/inline_entity_form.git/commitdiff/9483464?...

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

changed link