You are here

function honeypot_get_protected_forms in Honeypot 8

Same name and namespace in other branches
  1. 6 honeypot.module \honeypot_get_protected_forms()
  2. 7 honeypot.module \honeypot_get_protected_forms()
  3. 2.0.x honeypot.module \honeypot_get_protected_forms()

Build an array of all the protected forms on the site, by form_id.

1 call to honeypot_get_protected_forms()
honeypot_form_alter in ./honeypot.module
Implements hook_form_alter().

File

./honeypot.module, line 86
Honeypot module, for deterring spam bots from completing Drupal forms.

Code

function honeypot_get_protected_forms() {
  $forms =& drupal_static(__FUNCTION__);

  // If the data isn't already in memory, get from cache or look it up fresh.
  if (!isset($forms)) {
    if ($cache = \Drupal::cache()
      ->get('honeypot_protected_forms')) {
      $forms = $cache->data;
    }
    else {
      $form_settings = \Drupal::config('honeypot.settings')
        ->get('form_settings');
      if (!empty($form_settings)) {

        // Add each form that's enabled to the $forms array.
        foreach ($form_settings as $form_id => $enabled) {
          if ($enabled) {
            $forms[] = $form_id;
          }
        }
      }
      else {
        $forms = [];
      }

      // Save the cached data.
      \Drupal::cache()
        ->set('honeypot_protected_forms', $forms);
    }
  }
  return $forms;
}