You are here

public function HCaptcha::getWidget in hCaptcha 8

Build the hCaptcha captcha form.

Return value

mixed

File

src/HCaptcha/HCaptcha.php, line 42

Class

HCaptcha

Namespace

Drupal\hcaptcha\HCaptcha

Code

public function getWidget($validation_function) {

  // Captcha requires TRUE to be returned in solution.
  $widget['solution'] = true;
  $widget['captcha_validate'] = $validation_function;
  $widget['form']['captcha_response'] = array(
    '#type' => 'hidden',
    '#value' => 'hCaptcha no captcha',
  );

  // As the validate callback does not depend on sid or solution, this
  // captcha type can be displayed on cached pages.
  $widget['cacheable'] = true;
  $widget['form']['hcaptcha_widget'] = array(
    '#markup' => '<div' . $this
      ->getAttributesString() . '></div>',
  );
  return $widget;
}