function field_weight_sort_instances in Field display weights (per node) 7.2
Parameters
$instances:
$weights:
$revision_weights:
Return value
array
4 calls to field_weight_sort_instances()
- field_weight_display_overview_form in ./
field_weight.module - Admin form displayed at node/%/display.
- field_weight_inherit_field_weight_display_overview_weights_alter in modules/
field_weight_inherit.module - Implements hook_field_weight_display_overview_weights_alter().
- hook_field_weight_display_overview_weights_alter in ./
field_weight.api.php - hook_field_weight_multiple_display_overview_weights_alter in modules/
field_weight_multiple.api.php - Change the order in which fields managed by Multiple-Value Field Weights are displayed on the administrative form. This hook reeks of implementation details, but see Field Weight Inherit for another implementation example.
File
- ./
field_weight.module, line 211 - Field display weight module.
Code
function field_weight_sort_instances($instances, $weights, $revision_weights) {
// Create new array of instances
$weight_instances = array();
$highest_weight = count($instances);
foreach (array_keys($instances) as $key) {
// Default to actual rendered weight if not found. i.e field added
// after weights have last been saved or no weights saved.
if (array_key_exists($key, $weights)) {
$weight_instances[$key] = $weights[$key];
if (!array_key_exists($key, $revision_weights)) {
$weight_instances[$key]['new'] = TRUE;
}
}
else {
// Distinguish between never set (empty $weights) and new field.
// This is so that the form matches the render handling.
$default_weight = empty($weights) ? _field_weight_field_instance_get_weight($instances[$key]) : 0;
$default_hidden = 0;
// Always 0 to start with
$weight_instances[$key] = array(
'weight' => $default_weight,
'hidden' => $default_hidden,
// Set a property so we can show the user this is unsaved later.
'new' => TRUE,
);
}
$highest_weight = max($highest_weight, $weight_instances[$key]['weight']);
}
uasort($weight_instances, 'drupal_sort_weight');
return array(
$weight_instances,
$highest_weight,
);
}