From b75dff7d2a53398ffa4ac3a52426e378f7a15b5b Mon Sep 17 00:00:00 2001 From: bach Date: Thu, 10 Sep 2026 14:36:06 +0200 Subject: [PATCH] protected newsletter inscription form with honeypot --- .../materio_simplenews.module | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/web/modules/custom/materio_simplenews/materio_simplenews.module b/web/modules/custom/materio_simplenews/materio_simplenews.module index 261268f1..4541f3ae 100644 --- a/web/modules/custom/materio_simplenews/materio_simplenews.module +++ b/web/modules/custom/materio_simplenews/materio_simplenews.module @@ -1,15 +1,33 @@ setFormClass('materio_block', '\Drupal\materio_simplenews\Form\MaterioSubscriptionsBlockForm'); } +/** + * Implements hook_form_alter(). + * + * Forces Honeypot protection on simplenews subscription block forms + * (form ID includes a dynamic block unique_id, e.g. + * simplenews_subscriptions_block_footersimplenewssubscriptionblock). + * This can never appear as a checkbox on Honeypot's own settings form + * (which only lists a fixed set of core/contact/node/comment forms), so + * config-based protection would silently disappear if that settings + * form is ever saved. Applying it here in code makes it permanent and + * covers any future block instance of this type automatically. + */ +function materio_simplenews_form_alter(&$form, FormStateInterface $form_state, $form_id) { + if (strpos($form_id, 'simplenews_subscriptions_block_') === 0 && \Drupal::moduleHandler()->moduleExists('honeypot')) { + \Drupal::service('honeypot')->addFormProtection($form, $form_state, ['honeypot', 'time_restriction']); + } +} /** * Implements hook_form_alter(). */ // node_simplenews_issue_edit_form -// function materio_simplenews_form_alter(&$form, &$form_state, $form_id) { function materio_simplenews_form_node_simplenews_issue_form_alter(&$form, &$form_state, $form_id) { if(isset($_REQUEST['newsletter'])){ $news_id = $_REQUEST['newsletter'];