Sorts submitted field values according to drag-n-drop reordering.
array $items: The field values.
protected function sortItems(array &$items) {
$is_multiple = $this->field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || $this->field['cardinality'] > 1;
if ($is_multiple && isset($items[0]['_weight'])) {
usort($items, function ($a, $b) {
$a_weight = is_array($a) ? $a['_weight'] : 0;
$b_weight = is_array($b) ? $b['_weight'] : 0;
return $a_weight - $b_weight;
});
// Remove the '_weight' entries.
foreach ($items as $delta => &$item) {
if (is_array($item)) {
unset($item['_weight']);
}
}
}
}