You are here

function spamicide_install in Spamicide 8

Same name and namespace in other branches
  1. 5 spamicide.install \spamicide_install()
  2. 6 spamicide.install \spamicide_install()
  3. 7 spamicide.install \spamicide_install()

Implements hook_install().

File

./spamicide.install, line 13
This module provides yet another tool to eliminate spam.

Code

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();
    }
  }
}