When you create a new stack and add layouts without moving them, they all get weight "0" and are sorted alphabeticaly.
And it shouldn't be like that.
I'm working on a solution for that, i'll post a patch later.

Comments

oresh’s picture

First try. This works, but needs testing for different states.

function panels_frame_stack_ui_frames_sort(&$element, &$form_state) {
  $value = drupal_array_get_nested_value($form_state['values'], $element['#parents']);
  if ($value) {
    $weight = 0;
    foreach ($value as $frame) {
      if ($frame['weight'] == 0) {
        $value[$frame['label']]['weight'] = $weight;
        $weight++;
      }
    }
    uasort($value, 'drupal_sort_weight');
    drupal_array_set_nested_value($form_state['values'], $element['#parents'], $value);
 }
}
oresh’s picture

Ok, previous code was bad and started breaking.
New one.

function panels_frame_stack_ui_frames_sort(&$element, &$form_state) {
  $weight = 0;
  foreach ($form_state['values']['data'] as $delta => $item) {
    if (isset($item['identifier']) && $item['weight'] == 0) {
      $form_state['values']['data'][$delta]['weight'] = $weight++;
    }
  }
  $value = drupal_array_get_nested_value($form_state['values'], $element['#parents']);
  if ($value) {
    uasort($value, 'drupal_sort_weight');
    drupal_array_set_nested_value($form_state['values'], $element['#parents'], $value);
  }
}
helior’s picture

Thanks Oresh, would you be able to produce a patch that includes your changes?

chriz001’s picture

Issue summary: View changes
StatusFileSize
new754 bytes

Here is a patch incorporating the code from comment 2, Thanks Oresh.

oresh’s picture

Thanks, chriz001!
I was too busy to check this issue :)

oresh’s picture

Status: Active » Needs review

  • Commit a423d1c on 7.x-1.x authored by oresh, committed by helior:
    Issue #2112401: Resolving alphabetic sorting bug.
    
helior’s picture

Status: Needs review » Fixed

Patch merged in a423d1c. Thanks @chriz001 for making the patch and thank you @oresh for the code and patience :)

Status: Fixed » Closed (fixed)

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