Commit e38a5735 authored by Drew Webber's avatar Drew Webber
Browse files

Issue #2349641 by mcdruid, anoopsingh92, trogels, Mulambo: Fix errors and...

Issue #2349641 by mcdruid, anoopsingh92, trogels, Mulambo: Fix errors and warnings of phpcs coder review
parent d7c986c5
Loading
Loading
Loading
Loading
+26 −29
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ function jquery_update_settings_form() {
    '#description' => t('Select which version of jQuery to use on the site.'),
  );

  // Theme-specific override version
  // Theme-specific override version.
  $themes = list_themes();
  $theme_default = variable_get('theme_default', FALSE);
  $admin_theme = variable_get('admin_theme', FALSE);
@@ -115,7 +115,6 @@ function jquery_update_settings_form() {
    '#rows' => $rows,
  );


  $form['performance'] = array(
    '#type' => 'fieldset',
    '#title' => t('Performance'),
@@ -124,7 +123,7 @@ function jquery_update_settings_form() {
    '#tree' => FALSE,
    '#weight' => -1,
    '#group' => 'jquery_update',
    '#description' => t('Modify how jQuery is loaded to increase download and render performance.')
    '#description' => t('Modify how jQuery is loaded to increase download and render performance.'),
  );

  $form['performance']['jquery_update_compression_type'] = array(
@@ -134,7 +133,7 @@ function jquery_update_settings_form() {
      'min' => t('Production (minified)'),
      'none' => t('Development (uncompressed)'),
    ),
    // Do not show this field if jQuery version is default
    // Do not show this field if jQuery version is default.
    '#states' => array(
      'invisible' => array(
        ':input[name=jquery_update_jquery_version]' => array('value' => "default"),
@@ -151,7 +150,7 @@ function jquery_update_settings_form() {
      'microsoft' => t('Microsoft'),
      'jquery' => t('jQuery'),
    ),
    // Do not show this field if jQuery version is default
    // Do not show this field if jQuery version is default.
    '#states' => array(
      'invisible' => array(
        ':input[name=jquery_update_jquery_version]' => array('value' => "default"),
@@ -239,9 +238,8 @@ function jquery_update_settings_form() {
    '#default_value' => variable_get('jquery_update_custom_path_jquery', ''),
    '#description' => t('Example: %url or %path', array(
      '%url' => 'https://code.jquery.com/jquery-' . $example_version . '.js',
        '%path' => '/sites/default/files/jquery_update/jquery.js'
      )
    ),
      '%path' => '/sites/default/files/jquery_update/jquery.js',
    )),
  );
  $form['jquery_custom']['jquery_update_custom_version_jquery'] = array(
    '#type' => 'textfield',
@@ -258,9 +256,8 @@ function jquery_update_settings_form() {
    '#default_value' => variable_get('jquery_update_custom_path_jqueryui', ''),
    '#description' => t('Example: %url or %path', array(
      '%url' => 'https://cdnjs.cloudflare.com/ajax/libs/jqueryui/' . $example_version . '/jquery-ui.min.js',
        '%path' => '/sites/default/files/jquery_update/jquery-ui.min.js'
      )
    ),
      '%path' => '/sites/default/files/jquery_update/jquery-ui.min.js',
    )),
  );
  $form['jquery_custom']['jquery_update_custom_version_jqueryui'] = array(
    '#type' => 'textfield',
@@ -277,9 +274,8 @@ function jquery_update_settings_form() {
    '#default_value' => variable_get('jquery_update_custom_path_migrate', ''),
    '#description' => t('Example: %url or %path', array(
      '%url' => 'https://cdn.jsdelivr.net/npm/jquery-migrate@' . $example_version . '/dist/jquery-migrate.min.js',
      '%path' => '/sites/default/files/jquery_update/jquery-migrate.js'
    )
  ),
      '%path' => '/sites/default/files/jquery_update/jquery-migrate.js',
    )),
  );
  $form['jquery_custom']['jquery_update_custom_version_jquery_migrate'] = array(
    '#type' => 'textfield',
@@ -296,9 +292,8 @@ function jquery_update_settings_form() {
    '#default_value' => variable_get('jquery_update_custom_path_cookie', ''),
    '#description' => t('Example: %url or %path', array(
      '%url' => 'https://cdn.jsdelivr.net/gh/carhartl/jquery-cookie@' . $example_version . '/jquery.cookie.js',
        '%path' => '/sites/default/files/jquery_update/jquery.cookie.js'
      )
    ),
      '%path' => '/sites/default/files/jquery_update/jquery.cookie.js',
    )),
  );
  $form['jquery_custom']['jquery_update_custom_version_jquery_cookie'] = array(
    '#type' => 'textfield',
@@ -315,9 +310,8 @@ function jquery_update_settings_form() {
    '#default_value' => variable_get('jquery_update_custom_path_form', ''),
    '#description' => t('Example: %url or %path', array(
      '%url' => 'https://cdn.jsdelivr.net/gh/jquery-form/form@' . $example_version . '/dist/jquery.form.min.js',
        '%path' => '/sites/default/files/jquery_update/jquery.form.js'
      )
    ),
      '%path' => '/sites/default/files/jquery_update/jquery.form.js',
    )),
  );
  $form['jquery_custom']['jquery_update_custom_version_jquery_form'] = array(
    '#type' => 'textfield',
@@ -335,7 +329,7 @@ function jquery_update_settings_form() {
 * Validate handler for settings form.
 */
function jquery_update_settings_form_validate($form, &$form_state) {
  // Handle empty custom paths / versions
  // Handle empty custom paths / versions.
  if (!empty($form_state['values']['jquery_update_custom_path_jquery'])) {
    if (empty($form_state['values']['jquery_update_custom_version_jquery'])) {
      form_set_error('jquery_update_custom_version_jquery', 'Please provide a version for the custom jQuery path');
@@ -374,7 +368,7 @@ function jquery_update_form_jquery_update_settings_form_alter(&$form, &$form_sta
 * Submit handler for settings form.
 */
function jquery_update_settings_form_submit($form, &$form_state) {
  // Handle empty custom paths / versions
  // Handle empty custom paths / versions.
  $variables = array(
    'jquery_update_custom_path_cookie',
    'jquery_update_custom_path_form',
@@ -395,6 +389,9 @@ function jquery_update_settings_form_submit($form, &$form_state) {
  }
}

/**
 * The Latest versions fieldset.
 */
function jquery_update_add_latest_version_info(&$form) {

  $form['jquery_latest_versions'] = array(
@@ -416,8 +413,8 @@ function jquery_update_add_latest_version_info(&$form) {
  $refresh_url = url('admin/config/development/jquery_update/refresh-version-info',
    array(
      'query' => array(
        'token' => drupal_get_token('refresh-version-info')
      )
        'token' => drupal_get_token('refresh-version-info'),
      ),
    )
  );
  $form['jquery_latest_versions']['refresh_version_info'] = array(
@@ -468,7 +465,7 @@ function jquery_update_add_latest_version_info(&$form) {
    '#type' => 'checkbox',
    '#title' => t('Warn about available updates?'),
    '#default_value' => variable_get('jquery_update_warning_available_update', TRUE),
    '#description' => t("If enabled, jQuery Update will warn about available updates via messages in its admin UI and the main Status report.")
    '#description' => t("If enabled, jQuery Update will warn about available updates via messages in its admin UI and the main Status report."),
  );
}

+10 −11
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ function jquery_update_requirements($phase) {
        $requirements['jquery_update_error'] = array(
          'title' => t('An error occurred when checking jQuery versions'),
          'severity' => REQUIREMENT_ERROR,
          'description' => t('See the logs for more information.')
          'description' => t('See the logs for more information.'),
        );
        $GLOBALS['theme_key'] = $backup_theme_key;
        return $requirements;
@@ -62,15 +62,14 @@ function jquery_update_requirements($phase) {
      $requirements['jquery_update_' . $theme] = array(
        'title' => t('jQuery Update (@theme: %theme_name)', array(
          '@theme' => $theme,
          '%theme_name' => $theme_name
          '%theme_name' => $theme_name,
        )),
        'severity' => REQUIREMENT_OK,
        'value' => t('jQuery %jquery (<a href="@link">configure</a>) and jQuery UI %ui', array(
          '%jquery' => $library_version['jquery'],
          '%ui' => $library_version['ui'],
            '@link' => url('admin/config/development/jquery_update')
          )
        ),
          '@link' => url('admin/config/development/jquery_update'),
        )),
      );
    }
    $updates_available = _jquery_update_check_available_updates();
@@ -80,9 +79,9 @@ function jquery_update_requirements($phase) {
        'severity' => variable_get('jquery_update_warning_available_update', TRUE) ? REQUIREMENT_WARNING : REQUIREMENT_INFO,
        'value' => format_string('<a href="@link">%libraries</a>', array(
          '@link' => url('admin/config/development/jquery_update', array('fragment' => 'edit-jquery-latest-versions')),
            '%libraries' => implode(', ', $updates_available)
          '%libraries' => implode(', ', $updates_available),
        )),
        'description' => t('Updates are available for at least one library managed by jQuery Update.')
        'description' => t('Updates are available for at least one library managed by jQuery Update.'),
      );
    }
  }
+28 −22
Original line number Diff line number Diff line
@@ -125,7 +125,7 @@ function jquery_update_library_alter(&$libraries, $module) {
  );
  $libraries['drupal.ajax']['dependencies'][] = array('jquery_update', 'jquery_update.ajax.fix');

  // Don't replace anything if Drupal provided jQuery should be used
  // Don't replace anything if Drupal provided jQuery should be used.
  if ('default' == $jquery_version) {
    return;
  }
@@ -239,6 +239,9 @@ function jquery_update_get_version_options($empty = TRUE) {
  return $options;
}

/**
 * Generate an array of jQuery versions including any custom version.
 */
function jquery_update_get_supported_version_options() {
  $options = array();
  foreach (jquery_update_get_versions() as $version) {
@@ -260,7 +263,7 @@ function jquery_update_get_supported_version_options() {
 *   The name of the CDN option to use. Possible options are:
 *   - none
 *   - google
 *   - microsoft
 *   - microsoft.
 * @param string $path
 *   The path to the module where replacements can be found.
 * @param string $min
@@ -342,7 +345,7 @@ function jquery_update_add_jquery_browser_fix(&$libraries, $jquery_version) {
  if (version_compare($jquery_version, '1.9', '>=')) {
    $libraries['jquery']['dependencies'][] = array(
      'jquery_update',
      'jquery_update.browser.fix'
      'jquery_update.browser.fix',
    );
  }
}
@@ -370,7 +373,7 @@ function jquery_update_jquery_backup(&$javascript, $path, $min, $version) {
}

/**
 * Enable and configure the jQuery Migrate Plugin
 * Enable and configure the jQuery Migrate Plugin.
 *
 * @param array $libraries
 *   The library definition array as seen in hook_library_alter().
@@ -401,7 +404,6 @@ function jquery_update_jquery_migrate_replace(&$libraries, $path, $min, $version
    $migrate_version = '1';
  }


  $file = $path . '/replace/jquery-migrate/' . $migrate_version . '/jquery-migrate' . $min . '.js';

  // Note: this adds jQuery Migrate to the "system" module's library definition.
@@ -497,7 +499,7 @@ function jquery_update_jquery_migrate_backup(&$javascript, $path, $min, $migrate
 *   The name of the CDN option to use. Possible options are:
 *   - none
 *   - google
 *   - microsoft
 *   - microsoft.
 * @param string $path
 *   The path to the module where replacements can be found.
 * @param string $min
@@ -511,7 +513,7 @@ function jquery_update_jqueryui_replace(&$javascript, $cdn, $path, $min) {
    $jqueryui_version = '1.10.2';
  }

  // Add new components
  // Add new components.
  $javascript['ui.menu'] = array(
    'title' => 'jQuery UI: Menu',
    'website' => 'http://jqueryui.com/demos/menu/',
@@ -537,7 +539,7 @@ function jquery_update_jqueryui_replace(&$javascript, $cdn, $path, $min) {
    'dependencies' => array(array('system', 'ui.widget'), array('system', 'ui.position')),
  );

  // fix dependencies
  // Fix dependencies.
  $javascript['ui.autocomplete']['dependencies'][] = array('system', 'ui.menu');
  // Replace all CSS files.
  $names = drupal_map_assoc(array(
@@ -560,7 +562,8 @@ function jquery_update_jqueryui_replace(&$javascript, $cdn, $path, $min) {
    'ui.slider', 'ui.sortable', 'ui.tabs', 'ui.widget', 'ui.spinner', 'ui.menu', 'ui.tooltip',
  ));
  $names['ui'] = 'ui.core';
  $names['effects'] = array('effects.core', 'ui.effect'); // map[library_hook] = array(core_fn, updated_fn)
  // map[library_hook] = array(core_fn, updated_fn)
  $names['effects'] = array('effects.core', 'ui.effect');
  $names = jquery_update_make_library_hook_to_file_name_segment_map_for_effects($names);

  $custom_path = variable_get('jquery_update_custom_path_jqueryui', FALSE);
@@ -597,7 +600,9 @@ function jquery_update_jqueryui_replace(&$javascript, $cdn, $path, $min) {
/**
 * Create a mapping from system.module library hooks to file name segments.
 *
 * @param array $map Optional. If given, append to it.
 * @param array $map
 *   Optional. If given, append to it.
 *
 * @return array The keys are library hooks  and the values are each arrays of
 *   2 file name segments as values. The first file name segment can be used to
 *   reach Drupal core's jQuery UI effect files, and the second file name segment
@@ -611,7 +616,8 @@ function jquery_update_make_library_hook_to_file_name_segment_map_for_effects($m
  );
  foreach ($effect_names as $effect_name) {
    $library_hook = 'effects.' . $effect_name;
    $file_name_segment_core = $library_hook; // Yes, for the effect files, this is indeed identical.
    // Yes, for the effect files, this is indeed identical.
    $file_name_segment_core = $library_hook;
    $file_name_segment_updated = 'ui.effect-' . $effect_name;
    $map[$library_hook] = array($file_name_segment_core, $file_name_segment_updated);
  }
@@ -646,7 +652,7 @@ function jquery_update_jqueryui_backup(&$javascript, $path, $min) {
 *   The name of the CDN option to use. Possible options are:
 *   - none
 *   - google
 *   - microsoft
 *   - microsoft.
 * @param array $javascript
 *   The $libraries array as seen in hook_library_alter()
 * @param string $path
@@ -724,7 +730,7 @@ function jquery_update_permission() {
}

/**
 * Enable and configure the jQuery Cookie Plugin
 * Enable and configure the jQuery Cookie Plugin.
 *
 * @param array $libraries
 *   The library definition array as seen in hook_library_alter().
@@ -755,7 +761,7 @@ function jquery_update_jquery_cookie_replace(&$libraries, $path, $min) {
}

/**
 * Enable and configure the jQuery Form Plugin
 * Enable and configure the jQuery Form Plugin.
 *
 * @param array $libraries
 *   The library definition array as seen in hook_library_alter().
@@ -940,7 +946,7 @@ function _jquery_update_convert_settings_to_supported_versions() {
          array(
            '@theme' => $theme_key,
            '@before' => $theme_jquery_version,
            '@after' => $mapped_theme_jquery_version
            '@after' => $mapped_theme_jquery_version,
          ), WATCHDOG_WARNING);
      }
    }
+5 −5
Original line number Diff line number Diff line
@@ -48,7 +48,6 @@ class JqueryUpdateTestCase extends DrupalWebTestCase {

    // n.b. version numbers are arbitrary in most cases here, so probably no
    // real need update them as new releases come out.

    $form = array(
      'jquery_update_custom_path_jquery' => "https://code.jquery.com/jquery-3.6.0.js",
      'jquery_update_custom_version_jquery' => "3.6.0",
@@ -224,9 +223,9 @@ class JqueryUpdateTestCase extends DrupalWebTestCase {
    );

    foreach ($updates as $library => $update) {
      // drupal_set_message warnings
      // drupal_set_message warnings.
      $this->assertRaw('<li>' . $update . '</li>', format_string('Warning message showing update available for $%library', array('%library' => $library)));
      // update messages in the form
      // Update messages in the form.
      $this->assertRaw('<strong>' . $update . '</strong>', format_string('Info showing update available for $%library', array('%library' => $library)));
    }

@@ -244,9 +243,9 @@ class JqueryUpdateTestCase extends DrupalWebTestCase {
    $this->drupalLogin($this->admin);
    $this->drupalGet('/admin/config/development/jquery_update');
    foreach ($updates as $library => $update) {
      // drupal_set_message warnings
      // drupal_set_message warnings.
      $this->assertNoRaw('<li>' . $update . '</li>', format_string('No warning message showing update available for $%library', array('%library' => $library)));
      // update messages in the form
      // Update messages in the form.
      $this->assertRaw('<strong>' . $update . '</strong>', format_string('Info showing update available for $%library', array('%library' => $library)));
    }

@@ -325,4 +324,5 @@ class JqueryUpdateTestCase extends DrupalWebTestCase {
    $this->assertRaw('Example: <em class="placeholder">5.6.7</em>', 'Updated example jquery.form custom version');

  }

}
+5 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Module to help test jQuery Update.
 */

/**
 * Implements hook_init().
 */