You are here

function minifyjs_manage_javascript_files_form in Minify JS 7

Helper function for form table:

  • admin/config/development/performance/js.
1 string reference to 'minifyjs_manage_javascript_files_form'
minifyjs_menu in ./minifyjs.module
Implements hook_menu()

File

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

Code

function minifyjs_manage_javascript_files_form($form, &$form_state) {
  drupal_set_title(t('Manage Javascript Files'));

  // Build the rows of the table.
  $files = minifyjs_load_all_files();
  $form = array();
  $rows = array();
  if (count($files)) {
    foreach ($files as $fid => $file) {
      $rows[$fid] = array(
        l($file->uri, $file->uri, array(
          'attributes' => array(
            'target' => '_blank',
          ),
        )),
        date('Y-m-d', $file->modified),
        minifyjs_format_filesize($file->size),
        $file->minified_size > 0 ? minifyjs_format_filesize($file->minified_size) : '-',
        $file->minified_size > 0 ? round(($file->size - $file->minified_size) / $file->size * 100, 2) . '%' : '-',
        $file->minified_modified > 0 ? date('Y-m-d', $file->minified_modified) : '-',
        !empty($file->minified_uri) ? l(basename($file->minified_uri), file_create_url($file->minified_uri), array(
          'attributes' => array(
            'target' => '_blank',
          ),
        )) : '-',
        minifyjs_operations($file),
      );
    }
  }

  // The table.
  $form['files'] = array(
    '#type' => 'tableselect',
    '#header' => array(
      t('Original File'),
      t('Last Modified'),
      t('Original Size'),
      t('Minified Size'),
      t('Savings'),
      t('Last Minified'),
      t('Minified File'),
      t('Operations'),
    ),
    '#options' => $rows,
    '#empty' => t('No files have been found. Please scan using the action link above.'),
  );

  // Bulk minify button.
  if (count($files)) {
    $form['actions'] = array(
      '#type' => 'container',
      '#attributes' => array(
        'class' => array(
          'container-inline',
        ),
      ),
    );
    $form['actions']['action'] = array(
      '#type' => 'select',
      '#options' => array(
        'minify' => t('Minify (and re-minify)'),
        'minify_skip' => t('Minify (and skip minified)'),
        'restore' => t('Restore'),
      ),
    );
    $form['actions']['go'] = array(
      '#type' => 'submit',
      '#value' => t('Perform action on selected files'),
      '#submit' => array(
        'minifyjs_manage_javascript_files_form_submit',
      ),
    );
  }
  return $form;
}