You are here

function minifyjs_manage_javascript_files_form_submit in Minify JS 7

Helper function for form table (form submit):

  • admin/config/development/performance/js.
1 string reference to 'minifyjs_manage_javascript_files_form_submit'
minifyjs_manage_javascript_files_form in ./minifyjs.admin.inc
Helper function for form table:

File

./minifyjs.admin.inc, line 80
Hook and helper functions for the Minify JS module.

Code

function minifyjs_manage_javascript_files_form_submit($form, &$form_state) {
  if (count($form_state['values']['files'])) {
    $files = minifyjs_load_all_files();

    // Build operations
    $operations = array();
    foreach ($form_state['values']['files'] as $fid => $selected) {
      if ($selected) {
        switch ($form_state['values']['action']) {

          // minify all files.
          case 'minify':
            $operations[] = array(
              'minifyjs_minify_file_operation',
              array(
                $fid,
              ),
            );
            break;

          // minify files that have not yet been minified.
          case 'minify_skip':
            $file = $files[$fid];
            if (!$file->minified_uri) {
              $operations[] = array(
                'minifyjs_minify_file_operation',
                array(
                  $fid,
                ),
              );
            }
            break;

          // restore un-minified version of a file.
          case 'restore':
            $operations[] = array(
              'minifyjs_remove_minified_file_operation',
              array(
                $fid,
              ),
            );
            break;
        }
      }
    }

    // Build the batch.
    $batch = array(
      'operations' => $operations,
      'file' => drupal_get_path('module', 'minifyjs') . '/minifyjs.admin.inc',
      'error_message' => t('There was an unexpected error while processing the batch.'),
      'finished' => 'minifyjs_batch_finished',
    );
    switch ($form_state['values']['action']) {
      case 'minify':
        $batch['title'] = t('Minifying Javascript Files.');
        $batch['init_message'] = t('Initializing minify javascript files batch.');
        break;
      case 'restore':
        $batch['title'] = t('Restoring Un-Minified Javascript Files.');
        $batch['init_message'] = t('Initializing restore un-minified javascript files batch.');
        break;
    }

    // Start the batch.
    batch_set($batch);
  }
}