Exemplo n.º 1
0
 /**
  * #pre_render callback for #type 'mollom'.
  *
  * - Hides the CAPTCHA if it is not required or the solution was correct.
  * - Marks the CAPTCHA as required.
  */
 public static function preRenderMollom(array $element)
 {
     // If a CAPTCHA was solved, then no need to continue to display.
     if (isset($element['captcha']['#solved']) && $element['captcha']['#solved'] === TRUE) {
         $element['captcha']['#access'] = FALSE;
     } else {
         // Add the CAPTCHA if required, or hide the element if not required.
         if (!empty($element['captcha_required']['#value'])) {
             Mollom::addMollomCaptcha($element);
         } else {
             $element['captcha']['#access'] = FALSE;
         }
     }
     // UX: Empty the CAPTCHA field value, as the user has to re-enter a new one.
     $element['captcha']['captcha_input']['#value'] = '';
     // DX: Debugging helpers.
     //$element['#suffix'] = 'contentId: ' . $element['contentId']['#value'] . '<br>';
     //$element['#suffix'] .= 'captchaId: ' . $element['captchaId']['#value'] . '<br>';
     return $element;
 }
Exemplo n.º 2
0
 /**
  * Determine if Mollom validation should be run.
  *
  * This is required because even with limit_validation_errors set, Drupal
  * will still run the form validation (and then just not display the errors).
  * We don't want to contact Mollom to validate a CAPTCHA when the request is
  * simply to retrieve a new one.
  */
 protected static function shouldValidate(array $form, FormStateInterface $form_state)
 {
     // If the triggering element is within the captcha element, then no Mollom
     // validation should even run because it's pulling a new captcha element.
     return !Mollom::isCaptchaRefreshProcessing($form_state) && !Mollom::isCaptchaSwitchProcessing($form_state);
 }