cforge-2.0.x-dev/modules/cforge_broadcast/cforge_broadcast.module

modules/cforge_broadcast/cforge_broadcast.module
<?php

/**
 * @file
 * Hooks for cforge_broadcast module.
 */

const CFORGE_BROADCAST_ME = 0;
const CFORGE_BROADCAST_NEIGHBOURHOOD = 1;
const CFORGE_BROADCAST_OGS = 2;
const CFORGE_BROADCAST_SITE = 3;

/**
 * Implements hook_form_alter().
 *
 * Add settings to the main cforge settings page.
 */
function cforge_broadcast_form_cforge_settings_alter(&$form, &$form_state) {
  $form_state->loadInclude('cforge_broadcast', 'inc');
  _cforge_broadcast_form_cforge_settings_form_alter($form, $form_state);
}

/**
 * Implements hook_user_form_alter().
 *
 * Allows the user to opt out of broadcast if global settings allow.
 */
function cforge_broadcast_form_user_form_alter(&$form, $form_state) {
  $form_object = $form_state->getFormObject();
  if (\Drupal::config('cforge_broadcast.settings')->get('optout')) {
    if ($info = $form_object->getFormDisplay($form_state)->getComponent('contact')) {
      $form['optout'] = [
        '#title' => t("Opt-out of 'broadcast' messages"),
        '#description' => t("Do not send me one-off 'broadcast' messages"),
        '#type' => 'checkbox',
        '#default_value' => \Drupal::service('user.data')
          ->get('cforge_broadcast', $form_object->getEntity()->id(), 'optout'),
        '#weight' => $info['weight'],
      ];
      $form['actions']['submit']['#submit'][] = 'cforge_optout_user_submit';
    }
  }
}

/**
 * Submit callback for user form.
 */
function cforge_optout_user_submit($form, $form_state) {
  \Drupal::service('user.data')
    ->set(
      'cforge_broadcast',
      $form_state->getFormObject()->getEntity()->id(),
      'optout',
      $form_state->getValue('optout')
    );
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function cforge_broadcast_form_node_form_alter(&$form, &$form_state) {
  $form_state->loadInclude('cforge_broadcast', 'inc');
  _cforge_broadcast_entity_form_alter($form, $form_state);
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function cforge_broadcast_form_smallad_form_alter(&$form, &$form_state) {
  $form_state->loadInclude('cforge_broadcast', 'inc');
  _cforge_broadcast_entity_form_alter($form, $form_state);
}

/**
 * Implements hook_mail().
 *
 * Only one $key possible, which is broadcast.
 */
function cforge_broadcast_mail($key, &$message, $params) {
  global $mailing;
  $mailing = TRUE;
  \Drupal::moduleHandler()->loadInclude('cforge_broadcast', 'inc');
  _cforge_broadcast_mail_broadcast($message, $params);
}

/**
 * Implements hook_entity_view_display().
 *
 * We have to remove the comments, so rather than creating an EntityViewDisplay
 * for every entity we might mail, we remove the comment component from the
 * default display on the fly.
 *
 * @see cforge_broadcast_mail
 */
function cforge_broadcast_entity_view_display_alter($display, $display_context) {
  global $mailing;
  if (!empty($mailing)) {
    $display->removeComponent('comments');
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc