You are here

spamicide.install in Spamicide 8

Same filename and directory in other branches
  1. 5 spamicide.install
  2. 6 spamicide.install
  3. 7 spamicide.install

This module provides yet another tool to eliminate spam.

File

spamicide.install
View source
<?php

/**
 * @file
 * This module provides yet another tool to eliminate spam.
 *
 * @ingroup spamicide
 */

/**
 * Implements hook_install().
 */
function spamicide_install() {
  $form_ids = [
    'contact_message_feedback_form',
    'contact_message_personal_form',
    'user_register_form',
    'user_pass',
    'user_login_form',
    'node_forum_form',
    'comment_comment_form',
  ];
  if (!\Drupal::service('config.installer')
    ->isSyncing()) {

    // Add form_ids of all currently known node types too.
    foreach (node_type_get_names() as $type => $name) {
      $form_ids[] = 'node_' . $type . '_form';
    }
    $spamicide_storage = \Drupal::entityTypeManager()
      ->getStorage('spamicide');
    foreach ($form_ids as $form_id) {
      $values = [
        'id' => $form_id,
        'label' => $form_id,
        'status' => TRUE,
      ];
      $spamicide_storage
        ->create($values)
        ->save();
    }
  }
}

/**
 * Implements hook_requirements().
 */
function spamicide_requirements($phase) {
  $requirements = [];
  $spamicide = \Drupal::configFactory()
    ->get('spamicide.settings');
  if ($phase == 'runtime' || $phase == 'install') {
    if ($spamicide
      ->get('spamicide_log_attempts')) {
      $requirements['spamicide_attempt_counter'] = [
        'title' => t('Spamicide'),
        'value' => t('Already blocked @counter form submissions', [
          '@counter' => $spamicide
            ->get('spamicide_counter'),
        ]),
        'severity' => REQUIREMENT_INFO,
      ];
    }
  }
  return $requirements;
}

Functions