function _field_weight_multiple_process_instances in Field display weights (per node) 7.2
Parameters
$form:
$multi_fields_value:
$field_weights:
$revision_field_weights:
$weight_instances_original:
$multi_fields:
$node:
$weight_instances:
$revision_weights:
Return value
array
2 calls to _field_weight_multiple_process_instances()
- field_weight_inherit_field_weight_multiple_display_overview_weights_alter in modules/
field_weight_inherit.module - Implements hook_field_weight_multiple_display_overview_weights_alter().
- field_weight_multiple_form_field_weight_display_overview_form_alter in modules/
field_weight_multiple.module - Implements hook_form_FORM_ID_alter().
File
- modules/
field_weight_multiple.module, line 115
Code
function _field_weight_multiple_process_instances(&$form, &$multi_fields_value, $field_weights, $revision_field_weights, $weight_instances_original, $multi_fields, $node, $weight_instances, $revision_weights) {
$highest_weight = count($weight_instances_original);
// For each field, count how many instances there are on this node
foreach ($multi_fields as $multi_field) {
$node_multi_field = field_get_items('node', $node, $multi_field);
if ($node_multi_field === FALSE) {
$node_multi_field = array();
}
// Other modules shouldn't re-run this sort function, but they might.
// Don't double-unset in order to avoid errors and warnings..
if (!empty($weight_instances[$multi_field])) {
// Hide the main field from the form
$multi_fields_value[$multi_field] = $weight_instances[$multi_field];
unset($form['field_weight'][$multi_field]);
unset($weight_instances[$multi_field]);
}
// Add delta-specific keys to weight instances. After we've added them all,
// we'll re-sort it and
// regenerate the form.
foreach ($node_multi_field as $delta => $node_multi_field_data) {
// Is there anything in the database about this?
if (isset($field_weights["{$multi_field}_{$delta}"])) {
$weight_instances["{$multi_field}_{$delta}"] = $field_weights["{$multi_field}_{$delta}"];
if (!isset($revision_field_weights["{$multi_field}_{$delta}"])) {
$weight_instances["{$multi_field}_{$delta}"]['new'] = TRUE;
}
}
else {
// If the module has just been enabled, don't wipe out the value.
if ($delta == "0" && isset($weight_instances[$multi_field])) {
// Use (weight of field) + (delta) to determine
// the weight to put in here.
$weight_instances["{$multi_field}_{$delta}"] = array(
'weight' => $weight_instances_original[$multi_field]['weight'],
'hidden' => $weight_instances_original[$multi_field]['hidden'],
);
}
else {
$weight_instances["{$multi_field}_{$delta}"] = array(
'weight' => "0",
'hidden' => 0,
// Set a property so we can show the user this is unsaved later.
'new' => TRUE,
);
}
}
$highest_weight = max($highest_weight, $weight_instances["{$multi_field}_{$delta}"]['weight']);
// Make sure we always have a label
$multi_field_info_instance = field_info_instance('node', $multi_field, $node->type);
$human_delta = $delta + 1;
$weight_instances["{$multi_field}_{$delta}"]['label'] = "{$multi_field_info_instance['label']} (#{$human_delta})";
// Store the actual field name in case other modules need to know.
$weight_instances["{$multi_field}_{$delta}"]['field_name'] = $multi_field;
$weight_instances["{$multi_field}_{$delta}"]['module'] = 'field_weight_multiple';
}
}
// Re-sort $weight_instances.
uasort($weight_instances, 'drupal_sort_weight');
return array(
$highest_weight,
$weight_instances,
);
}