You are here

function lingotek_grid_action_submit in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.4 lingotek.bulk_grid.inc \lingotek_grid_action_submit()
  2. 7.5 lingotek.bulk_grid.inc \lingotek_grid_action_submit()
  3. 7.6 lingotek.bulk_grid.inc \lingotek_grid_action_submit()

Submit function for The Grid's actions The action corresponds to the key of the option selected Often redirects to batch operations or to other pages entirely

1 call to lingotek_grid_action_submit()
lingotek_popup in ./lingotek.bulk_grid.inc
1 string reference to 'lingotek_grid_action_submit'
lingotek_bulk_grid_form in ./lingotek.bulk_grid.inc

File

./lingotek.bulk_grid.inc, line 790

Code

function lingotek_grid_action_submit($form, $form_state) {
  $entity_ids = array();
  $entity_type = isset($form_state['entity_type']) ? $form_state['entity_type'] : (isset($form_state['values']['entity_type']) ? $form_state['values']['entity_type'] : NULL);
  if (isset($form_state['clicked_button']) && $form_state['clicked_button']['#name'] == 'submit_actions') {

    // If submitting an action
    foreach ($form_state['values']['the_grid'] as $value) {
      if ($value != 0) {
        $entity_ids[] = $value;
      }
    }
    if (isset($form_state['values']['select_actions'])) {

      // If an action was selected (which it would be, I don't know if this could ever NOT occur with normal use)
      $action = $form_state['values']['select_actions'];

      // Get the action
      if (count($entity_ids) <= 0) {

        // Select a node
        drupal_set_message(t('You must select at least one node to @action.', array(
          '@action' => $action,
        )), 'warning');

        // Or pay the price
      }
      elseif ($action == 'upload') {

        // If uploading
        $batch = array(
          'title' => t('Uploading Content To Lingotek'),
          'finished' => 'lingotek_sync_upload_node_finished',
        );
        $operations = lingotek_get_sync_upload_batch_elements($entity_type, $entity_ids);
        $batch['operations'] = $operations;
        $redirect = current_path();
        batch_set($batch);
        batch_process($redirect);

        // Run batch operations to upload all of the selected nodes to Lingotek
      }
      elseif (substr($action, 0, 8) == 'download') {

        // If downloading all targets
        $locale = substr($action, 9, 10);
        $target_locales = $locale == 'all' ? lingotek_get_target_locales() : array(
          $locale,
        );
        lingotek_grid_download_selected($entity_type, $entity_ids, $target_locales);
      }
      elseif ($action == 'delete' || $action == 'reset' || $action == 'delete-translations') {

        // ajax ctools modal employed (see lingotek_bulk_grid_form() and lingotek.bulk_grid.js)
      }
      elseif ($action == 'edit') {

        // If editing node settings
        drupal_goto(LINGOTEK_MENU_MAIN_BASE_URL . '/manage/edit/');

        // Redirect to the edit Lingotek node settings form - for multiple nodes, form defaults are global defaults
      }
      elseif ($action == 'workflow') {

        // If changing the workflow
        drupal_goto(LINGOTEK_MENU_MAIN_BASE_URL . '/manage/change-workflow/');

        // Redirect to the change-workflow settings form - for multiple nodes, form defaults are global defaults
      }
      elseif ($action == 'sync') {

        // If syncing the progress
        lingotek_update_target_progress_batch_create($entity_type, $entity_ids);

        // Run batch operations to get the progress report from Lingotek
      }
      elseif ($action == 'marked') {
        $batch = array(
          'title' => t('Updating Marked Entities'),
          'finished' => 'lingotek_update_marked_items_finished',
        );
        $operations = lingotek_get_marked_batch_elements($entity_type, $entity_ids);
        $batch['operations'] = $operations;
        $redirect = current_path();
        batch_set($batch);
        batch_process($redirect);
      }
      elseif ($action == 'unmarked') {
        $batch = array(
          'title' => t('Updating Unmarked Entities'),
          'finished' => 'lingotek_update_unmarked_items_finished',
        );
        $operations = lingotek_get_unmarked_batch_elements($entity_type, $entity_ids);
        $batch['operations'] = $operations;
        $redirect = current_path();
        batch_set($batch);
        batch_process($redirect);
      }
      elseif ($action == 'add_language_specific_targets') {
        lingotek_add_language_specific_targets_batch_create($entity_type, $entity_ids);
      }
    }
  }
}