You are here

function node_gallery_images_edit_submit in Node Gallery 6.2

Same name and namespace in other branches
  1. 6 node_gallery.pages.inc \node_gallery_images_edit_submit()
2 string references to 'node_gallery_images_edit_submit'
node_gallery_edit_images_form in ./node_gallery.pages.inc
node_gallery_sort_images_form in ./node_gallery.pages.inc
This is exactly like the edit images form except it removes the ability to edit the image content and removes pagination

File

./node_gallery.pages.inc, line 546
Node gallery pages.

Code

function node_gallery_images_edit_submit(&$form, &$form_state) {
  $ng_table = drupal_get_schema_unprocessed('node_gallery', 'node_galleries');
  foreach ($ng_table['fields'] as $k => $f) {
    $compare_fields[] = $k;
  }
  foreach ($form['#gallery']->config['display_fields'] as $k => $f) {
    if ($f) {
      $compare_fields[] = $k == 'body_field' ? 'body' : $k;
    }
  }
  foreach ($form_state['values']['files'] as $fid => $form_values) {
    $image_node = $form_values['edit_form'];
    unset($form_values['edit_form']);
    $image_node = (object) array_merge($image_node, $form_values);
    if ($form_state['values']['is_cover'] == $fid) {
      $image_node->is_cover = 1;
    }
    else {
      $image_node->is_cover = 0;
    }
    if ($form_values['remove']) {
      $op_images['delete'][] = $image_node;
    }
    else {

      //modify image;
      if (node_gallery_images_check_update($form['#gallery']->images[$fid], $image_node, $compare_fields)) {
        $op_images['update'][] = $image_node;
      }
      elseif (empty($image_node->nid)) {
        $op_images['update'][] = $image_node;
      }
    }
  }
  $delete_total = count($op_images['delete']);
  if (!empty($delete_total)) {
    $operations[] = array(
      'image_delete_process',
      array(
        $op_images['delete'],
      ),
    );
  }
  $update_total = count($op_images['update']);
  if (!empty($update_total)) {
    $operations[] = array(
      'image_upload_process',
      array(
        $op_images['update'],
        $form_state['values']['is_upload'],
      ),
    );
  }
  if (!empty($operations)) {
    $batch = array(
      'operations' => $operations,
      'finished' => 'image_process_finished',
      'title' => empty($form_state['values']['is_upload']) ? t("Processing Images Edit") : t('Processing Images Upload.'),
      'init_message' => empty($form_state['values']['is_upload']) ? t("Images update is starting.") : t('Images upload is starting.'),
      //'progress_message' => t('Processed @current out of @total.'),
      'error_message' => empty($form_state['values']['is_upload']) ? t('Images edit has encountered an error.') : t('Images upload has encountered an error.'),
    );
    batch_set($batch);

    //hack for batch process in form, see line 426 in form.inc;
    $tmp = $form_state['values']['form_build_id'];
    $form_state = array();
    $form_state['values']['form_build_id'] = $tmp;
    $form = array();
  }
  $form_state['redirect'] = 'node/' . $image_node->gid;
}