You are here

function spamicide_form_alter in Spamicide 8

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

Implements hook_form_alter().

File

./spamicide.module, line 40
Spamicide.module.

Code

function spamicide_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
  $spamicide = \Drupal::entityTypeManager()
    ->getStorage('spamicide')
    ->loadByProperties([
    'id' => $form_id,
    'status' => TRUE,
  ]);
  $spamicide = reset($spamicide);
  if (spamicide_add_button_to_form($spamicide, $form_id)) {
    $form['spamicide_group'] = [
      '#type' => 'details',
      '#open' => FALSE,
      '#title' => t('Spamicide'),
    ];
    $form['spamicide_group']['spamicide_url'] = [
      '#type' => 'link',
      '#title' => t('Add spamicide to this form to prevent spam'),
      '#url' => Url::fromRoute('entity.spamicide.add_form', [], [
        'attributes' => [
          'class' => [
            'button',
          ],
        ],
        'query' => [
          'form_id' => $form_id,
        ],
      ]),
    ];
  }
  if ($spamicide) {
    $form['feed_me'] = [
      '#type' => 'textfield',
      '#title' => 'Feed me',
      '#weight' => 999,
      '#attributes' => [
        'class' => [
          'feed_me_textfield',
        ],
      ],
    ];
    $form['actions']['#weight'] = 1000;
    $form['#attached']['library'][] = 'spamicide/spamicide';
    $form['#validate'][] = 'spamicide_validate';
  }
}