You are here

function _image_attach_set_image_weight in Image 6

Get image weights and return an iid array ordered by weight.

This private function is called by submit handlers to discover how the user has ordered their images. It returns an array with identical keys and values (just like the ordinary iid array).

Parameters

$raw_weight_data: An array of iids and weights from the drag-to-reorder table, derived from either the $form_state object or the $node object.

$select_box_array: The array of existing images that the user wants to include. This may be different to the iids passed in $raw_weight_data.

Return value

A weight-sorted (from lightest to heaviest) array of iids, with identical keys and (integer) values.

2 calls to _image_attach_set_image_weight()
image_attach_image_add_submit in contrib/image_attach/image_attach.module
Save attached image nids and rebuild form.
image_attach_nodeapi in contrib/image_attach/image_attach.module
Implementation of hook_nodeapi().

File

contrib/image_attach/image_attach.module, line 333
image_attach.module

Code

function _image_attach_set_image_weight($raw_weight_data, $select_box_array) {

  // Build up an array of iids => weights.
  $weights = array();
  foreach ($select_box_array as $iid) {

    // Check the delete box has not been ticked.
    if ($raw_weight_data[$iid]['delete'] !== 1) {

      // If the image exists in the drag-to-reorder array, get its weight, otherwise, assign it the heaviest weight possible.
      $weights[$iid] = isset($raw_weight_data[$iid]['weight']) ? $raw_weight_data[$iid]['weight'] : count($select_box_array);
    }
  }

  // Sort the iids array by weight.
  asort($weights);

  // Take the keys to make the return array.
  $items = drupal_map_assoc(array_keys($weights));
  return $items;
}