diff --git a/captcha.libraries.yml b/captcha.libraries.yml new file mode 100644 index 0000000..b52fcaa --- /dev/null +++ b/captcha.libraries.yml @@ -0,0 +1,9 @@ +base: + version: 1.0 + js: + captcha.js: {} + dependencies: + - core/jquery + - core/drupal + - core/drupalSettings + - core/jquery.once diff --git a/captcha.module b/captcha.module index 127d58d..89baaac 100644 --- a/captcha.module +++ b/captcha.module @@ -33,26 +33,6 @@ define('CAPTCHA_DEFAULT_VALIDATION_CASE_SENSITIVE', 0); define('CAPTCHA_DEFAULT_VALIDATION_CASE_INSENSITIVE', 1); /** - * Implements hook_library_info(). - */ -function captcha_library_info() { - $libraries['captcha.js'] = array( - 'title' => 'Captcha Javascript', - 'version' => '1.0', - 'js' => array( - drupal_get_path('module', 'captcha') . '/captcha.js' => array(), - ), - 'dependencies' => array( - array('system', 'jquery'), - array('system', 'drupal'), - array('system', 'drupalSettings'), - array('system', 'jquery.once'), - ), - ); - return $libraries; -} - -/** * Implementation of hook_help(). */ function captcha_help($path, $arg) { @@ -195,8 +175,7 @@ function captcha_element_process($element, &$form_state, $complete_form) { module_load_include('inc', 'captcha'); // Add Javascript for general CAPTCHA functionality. - drupal_add_library('captcha','captcha.js'); - + $element['#attached']['library'][] = 'captcha/base'; // Prevent caching of the page with CAPTCHA elements. // This needs to be done even if the CAPTCHA will be ommitted later: // other untrusted users should not get a cached page when diff --git a/lib/Drupal/captcha/Form/CaptchaSettingsForm.php b/lib/Drupal/captcha/Form/CaptchaSettingsForm.php index 66ca20b..090cd5f 100644 --- a/lib/Drupal/captcha/Form/CaptchaSettingsForm.php +++ b/lib/Drupal/captcha/Form/CaptchaSettingsForm.php @@ -59,7 +59,7 @@ class CaptchaSettingsForm extends SystemConfigFormBase { module_load_include('inc','captcha','captcha.admin'); // Use javascript for some added usability on admin form. - drupal_add_library('captcha','captcha.js'); + $form['#attached']['library'][] = 'captcha/base'; // Configuration of which forms to protect, with what challenge. $form['captcha_form_protection'] = array(