You are here

function minifyjs_form_system_performance_settings_alter in Minify JS 8.2

Same name and namespace in other branches
  1. 8 minifyjs.module \minifyjs_form_system_performance_settings_alter()
  2. 7 minifyjs.module \minifyjs_form_system_performance_settings_alter()

Implements hook_FORM_ID_alter().

File

./minifyjs.module, line 17
Hooks and functions for the minifyjs module.

Code

function minifyjs_form_system_performance_settings_alter(array &$form, FormStateInterface $form_state, $form_id) {
  if (\Drupal::currentUser()
    ->hasPermission('administer minifyjs')) {

    // Determine the number of files minified.
    $files = \Drupal::service('minifyjs')
      ->loadAllFiles();
    $files_minified = 0;
    foreach ($files as $file) {
      if (!empty($file->minified_uri)) {
        $files_minified++;
      }
    }
    $form['bandwidth_optimization']['use_minified_javascript'] = [
      '#type' => 'checkbox',
      '#title' => t('Use Minified JavaScript files.'),
      '#disabled' => $files_minified ? FALSE : TRUE,
      '#description' => t('Toggle minified javascript files on or off. There are @minified minified files out of @total total files available. <a href=":href">Click here to manage your javascript files</a>.', [
        '@minified' => $files_minified,
        '@total' => count($files),
        ':href' => Url::fromUri('base:/admin/config/development/performance/js')
          ->toString(),
      ]),
      '#default_value' => \Drupal::config('minifyjs.config')
        ->get('use_minified'),
    ];
    $form['#submit'][] = 'minifyjs_system_performance_settings_submit';
  }
}