_field_sort_items

  1. drupal
    1. 8
    2. 7
Versions
7 – 8 _field_sort_items($field, $items)

Helper function to sort items in a field according to user drag-n-drop reordering.

Related topics

Code

modules/field/field.module, line 532

<?php
function _field_sort_items($field, $items) {
  if (($field['cardinality'] > 1 || $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) && isset($items[0]['_weight'])) {
    usort($items, '_field_sort_items_helper');
    foreach ($items as $delta => $item) {
      if (is_array($items[$delta])) {
        unset($items[$delta]['_weight']);
      }
    }
  }
  return $items;
}
?>