You are here

function captcha_set_form_id_setting in CAPTCHA 8

Same name and namespace in other branches
  1. 6.2 captcha.inc \captcha_set_form_id_setting()
  2. 7 captcha.inc \captcha_set_form_id_setting()

Helper function for adding/updating a CAPTCHA point.

Parameters

string $form_id: the form ID to configure.

string $captcha_type: The setting for the given form_id, can be:

  • 'default' to use the default challenge type
  • NULL to remove the entry for the CAPTCHA type
  • something of the form 'image_captcha/Image'
  • an object with attributes $captcha_type->module

and $captcha_type->captcha_type.

14 calls to captcha_set_form_id_setting()
CaptchaAdminTest::testCaptchaPlacementCacheClearing in tests/src/Functional/CaptchaAdminTest.php
Test the CAPTCHA placement clearing.
CaptchaAdminTest::testCaptchaPointSettingGetterAndSetter in tests/src/Functional/CaptchaAdminTest.php
Test the CAPTCHA point setting getter/setter.
CaptchaAdminTest::testUntrustedUserPosting in tests/src/Functional/CaptchaAdminTest.php
Test untrusted user posting.
CaptchaAdminTest::testXssOnCaptchaDescription in tests/src/Functional/CaptchaAdminTest.php
Test XSS vulnerability on CAPTCHA description.
CaptchaCacheTest::testCacheableCaptcha in tests/src/Functional/CaptchaCacheTest.php
Tests a cacheable captcha type.

... See full list

File

./captcha.inc, line 25
General CAPTCHA functionality and helper functions.

Code

function captcha_set_form_id_setting($form_id, $captcha_type) {

  /* @var Drupal\captcha\Entity\CaptchaPoint $captcha_point */
  $captcha_point = CaptchaPoint::load($form_id);
  if ($captcha_point) {
    $captcha_point
      ->setCaptchaType($captcha_type);
  }
  else {
    $captcha_point = new CaptchaPoint([
      'formId' => $form_id,
      'captchaType' => $captcha_type,
    ], 'captcha_point');
  }
  $captcha_point
    ->enable();
  $captcha_point
    ->save();
}