Commit 13bd098c authored by git's avatar git Committed by wundo

Issue #2808087 by Ginovski, naveenvalecha, Berdir, ddrozdik: Improve...

Issue #2808087 by Ginovski, naveenvalecha, Berdir, ddrozdik: Improve captcha_install(), correctly create dynamic captcha points, move static captcha points to default config
parent 7b7b7354
......@@ -5,7 +5,6 @@
* Install, update and uninstall functions for the CAPTCHA module.
*/
use Drupal\captcha\Entity\CaptchaPoint;
use Drupal\Core\Url;
/**
......@@ -112,27 +111,24 @@ function captcha_requirements($phase) {
* Implements hook_install().
*/
function captcha_install() {
// Insert some default CAPTCHA points.
$form_ids = [
'contact_message_feedback_form',
'contact_message_personal_form',
'user_register_form',
'user_pass',
'user_login_form',
'node_forum_form',
];
// Add form_ids of all currently known node types too.
foreach (node_type_get_names() as $type => $name) {
$form_ids[] = 'node_' . $type . '_form';
}
foreach ($form_ids as $form_id) {
$values = [
'formId' => $form_id,
'captchaType' => 'default',
'status' => FALSE,
];
$captcha_point = new CaptchaPoint($values, 'captcha_point');
$captcha_point->trustData()->save();
if (!\Drupal::service('config.installer')->isSyncing()) {
$form_ids = [];
// Add form_ids of all currently known node types too.
foreach (node_type_get_names() as $type => $name) {
$form_ids[] = 'node_' . $type . '_form';
}
$captcha_storage = \Drupal::entityTypeManager()
->getStorage('captcha_point');
foreach ($form_ids as $form_id) {
$values = [
'formId' => $form_id,
'captchaType' => 'default',
'status' => FALSE,
];
$captcha_storage->create($values)->save();
}
}
// Explain to users that page caching may be disabled.
......
langcode: en
status: false
dependencies: { }
formId: contact_message_feedback_form
captchaType: default
label: null
langcode: en
status: false
dependencies: { }
formId: contact_message_personal_form
captchaType: default
label: null
langcode: en
status: false
dependencies: { }
formId: user_login_form
captchaType: default
label: null
langcode: en
status: false
dependencies: { }
formId: user_pass
captchaType: default
label: null
langcode: en
status: false
dependencies: { }
formId: user_register_form
captchaType: default
label: null
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