You are here

simplenews_rules.module in Simplenews 3.x

Module file for Simplenews rules integration.

File

simplenews_rules/simplenews_rules.module
View source
<?php

/**
 * @file
 * Module file for Simplenews rules integration.
 */
use Drupal\simplenews\Entity\Newsletter;
define('SIMPLENEWS_RULES_CONFIRMATION_DEFAULT', 0);
define('SIMPLENEWS_RULES_CONFIRMATION_YES', 1);
define('SIMPLENEWS_RULES_CONFIRMATION_NO', 2);

/**
 * Returns the options for the confirmation paramter.
 */
function simplenews_rules_confirmation_list() {
  return array(
    SIMPLENEWS_RULES_CONFIRMATION_DEFAULT => t('Default'),
    SIMPLENEWS_RULES_CONFIRMATION_YES => t('Yes'),
    SIMPLENEWS_RULES_CONFIRMATION_NO => t('No'),
  );
}

/**
 * Implements hook_simplenews_unsubscribe().
 */
function simplenews_rules_simplenews_unsubscribe($subscriber, $subscription) {
  $args = array(
    'mail' => $subscriber->mail,
    'newsletter' => Newsletter::load($subscription->newsletter_id),
  );
  rules_invoke_event_by_args('simplenews_rules_event_unsubscribe', $args);
}

/**
 * Implements hook_simplenews_subscribe().
 */
function simplenews_rules_simplenews_subscribe($subscriber, $subscription) {
  $args = array(
    'mail' => $subscriber->mail,
    'newsletter' => Newsletter::load($subscription->newsletter_id),
  );
  rules_invoke_event_by_args('simplenews_rules_event_subscribe', $args);
}