Unverified Commit 4a08f67f authored by gg24's avatar gg24 Committed by wundo

Issue #2608540 by gg24, bpresles, RavindraSingh, sakural, ddrozdik, rsvelko,...

Issue #2608540 by gg24, bpresles, RavindraSingh, sakural, ddrozdik, rsvelko, naveenvalecha, wundo: Add Image CAPTCHA Refresh to the module patch
parent 09cecdab
......@@ -20,10 +20,10 @@ function image_captcha_requirements($phase) {
'title' => \Drupal::translation()
->translate('Image CAPTCHA requires GD library'),
'description' =>
\Drupal::translation()
->translate('The Image CAPTCHA module can not be installed because your PHP setup does not provide the <a href="!gddoc">GD library</a>, which is required to generate images.',
\Drupal::translation()
->translate('The Image CAPTCHA module can not be installed because your PHP setup does not provide the <a href="!gddoc">GD library</a>, which is required to generate images.',
['!gddoc' => 'http://www.php.net/manual/en/book.image.php']
),
),
'severity' => REQUIREMENT_ERROR,
];
}
......
......@@ -3,10 +3,15 @@ base:
js:
image_captcha.js: {}
css:
all:
theme:
image_captcha.css: {}
dependencies:
- core/jquery
- core/drupal
- core/drupalSettings
- core/jquery.once
image-captcha-refresh:
version: 1.0
js:
js/image_captcha_refresh.js: {}
......@@ -7,6 +7,7 @@
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\Core\Link;
define('IMAGE_CAPTCHA_ALLOWED_CHARACTERS', 'aAbBCdEeFfGHhijKLMmNPQRrSTtWXYZ23456789');
......@@ -276,3 +277,53 @@ function image_captcha_captcha($op, $captcha_type = '', $captcha_sid = NULL) {
break;
}
}
/**
* Implements hook_theme().
*/
function image_captcha_theme() {
return [
'image_captcha_refresh' => [
'variables' => ['captcha_refresh_link' => NULL],
],
];
}
/**
* Implements hook_element_info_alter().
*/
function image_captcha_element_info_alter(array &$element) {
if (isset($element['captcha'])) {
$element['captcha']['#process'][] = 'image_captcha_after_build_process';
}
}
/**
* Add image refresh button to captcha form element.
*
* @return array
* The processed element.
*
* @see captcha_element_info()
* @see image_captcha_element_info_alter()
*/
function image_captcha_after_build_process($element) {
$form_id = $element['#captcha_info']['form_id'];
$captcha_point = captcha_get_form_id_setting($form_id);
if ($captcha_point && $captcha_point->captchaType &&
$captcha_point->captchaType == 'image_captcha/Image' &&
isset($element['captcha_widgets']['captcha_image'])
) {
$uri = Link::fromTextAndUrl(t('Get new captcha!'),
new Url('image_captcha.refresh',
['form_id' => $form_id],
['attributes' => ['class' => ['reload-captcha']]]
)
);
$element['captcha_widgets']['captcha_refresh'] = [
'#theme' => 'image_captcha_refresh',
'#captcha_refresh_link' => $uri,
];
}
return $element;
}
......@@ -18,3 +18,10 @@ image_captcha.generator:
_controller: '\Drupal\image_captcha\Controller\CaptchaImageGeneratorController::image'
requirements:
_access: 'TRUE'
image_captcha.refresh:
path: '/image-captcha-refresh/{form_id}'
defaults:
_controller: '\Drupal\image_captcha\Controller\CaptchaImageRefresh::refreshCaptcha'
requirements:
_access: 'TRUE'
......@@ -17,14 +17,14 @@ class CaptchaImageGeneratorController implements ContainerInjectionInterface {
/**
* Image Captcha config storage.
*
* @var Config
* @var \Drupal\Core\Config\Config
*/
protected $config;
/**
* Watchdog logger channel for captcha.
*
* @var LoggerChannelInterface
* @var \Drupal\Core\Logger\LoggerChannelInterface
*/
protected $logger;
......@@ -58,7 +58,7 @@ class CaptchaImageGeneratorController implements ContainerInjectionInterface {
/**
* Main method that throw ImageResponse object to generate image.
*
* @return CaptchaImageResponse
* @return \Drupal\image_captcha\Response\CaptchaImageResponse
* Make a CaptchaImageResponse with the correct configuration and return it.
*/
public function image() {
......
......@@ -17,14 +17,14 @@ class CaptchaImageResponse extends Response {
/**
* Image Captcha config storage.
*
* @var Config
* @var \Drupal\Core\Config\Config
*/
protected $config;
/**
* Watchdog logger channel for captcha.
*
* @var LoggerChannelInterface
* @var \Drupal\Core\Logger\LoggerChannelInterface
*/
protected $logger;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment