protected newsletter inscription form with honeypot
This commit is contained in:
@@ -1,15 +1,33 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
|
|
||||||
function materio_simplenews_entity_type_alter(array &$entity_types) {
|
function materio_simplenews_entity_type_alter(array &$entity_types) {
|
||||||
$entity_types['simplenews_subscriber']->setFormClass('materio_block', '\Drupal\materio_simplenews\Form\MaterioSubscriptionsBlockForm');
|
$entity_types['simplenews_subscriber']->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().
|
* Implements hook_form_alter().
|
||||||
*/
|
*/
|
||||||
// node_simplenews_issue_edit_form
|
// 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) {
|
function materio_simplenews_form_node_simplenews_issue_form_alter(&$form, &$form_state, $form_id) {
|
||||||
if(isset($_REQUEST['newsletter'])){
|
if(isset($_REQUEST['newsletter'])){
|
||||||
$news_id = $_REQUEST['newsletter'];
|
$news_id = $_REQUEST['newsletter'];
|
||||||
|
|||||||
Reference in New Issue
Block a user