When ordering variations by dragging them up/down, order is not saved. 1.x-dev (2012-Apr-25).

Gr3fweN

Comments

lastar84’s picture

Same problem. Neither drag-and-drop nor manually entered row weights are saved - it seems to default to the order in which items were added, beginning with 0, 1, 2 and so on.

leanderl’s picture

I'm having the same issue. Noticed that order is saved if you click "edit" or "add" variation and then cancel (or save). So something is missing to trigger the save when you just reorder the variations... I've spent hours and hours going through the code but can't find the right angle...

leanderl’s picture

Status: Active » Needs review

Well, I'm not sure what the heck I'm doing. But it does seem to work well if you put the delta loop before the "abort validation" code like thus (row 699 of inline_entity_form.module):

// Loop over the submitted delta values and update the weight of the entities
  // in the form state.
  foreach (element_children($element['entities']) as $key) {
    $form_state['inline_entity_form'][$parents_key]['entities'][$key]['weight'] = $element['entities'][$key]['delta']['#value'];
  }
  
  // Abort validation if the form has been rebuilt by an unknown element, such
  // as a field widget inside the embedded form.
  if (!in_array($triggering_element_name, array_keys(inline_entity_form_widget_form_actions()))) {
    return;
  }

  // Abort validation if the triggering element doesn't share parents with the
  // current element (which means that the event came from another IEF widget).
  $triggering_parents = array_slice($form_state['triggering_element']['#array_parents'], 0, count($parents));
  if ($parents != $triggering_parents) {
    return;
  }

original code was (row 699-716 of inline_entity_form.module) :

// Abort validation if the form has been rebuilt by an unknown element, such
  // as a field widget inside the embedded form.
  if (!in_array($triggering_element_name, array_keys(inline_entity_form_widget_form_actions()))) {
    return;
  }

  // Abort validation if the triggering element doesn't share parents with the
  // current element (which means that the event came from another IEF widget).
  $triggering_parents = array_slice($form_state['triggering_element']['#array_parents'], 0, count($parents));
  if ($parents != $triggering_parents) {
    return;
  }

  // Loop over the submitted delta values and update the weight of the entities
  // in the form state.
  foreach (element_children($element['entities']) as $key) {
    $form_state['inline_entity_form'][$parents_key]['entities'][$key]['weight'] = $element['entities'][$key]['delta']['#value'];
  }

I guess one of the maintainers should look at the consequences of doing this. But it fixes the problem although it could have other repercussions I'm not aware of.

minorwm’s picture

Same problem here as well. leanderl solution seemed to work for me though.

eme’s picture

Status: Needs review » Reviewed & tested by the community

Yes indeed, it works very well. It was saving the order only when triggering any AJAX action again, but with this little hack, that's perfect.

Thx !

bojanz’s picture

Status: Reviewed & tested by the community » Closed (duplicate)