You are here

sendinblue.module in SendinBlue 8

Same filename and directory in other branches
  1. 8.2 sendinblue.module
  2. 7.2 sendinblue.module
  3. 7 sendinblue.module

The entry point of Sendinblue module.

File

sendinblue.module
View source
<?php

/**
 * @file
 * The entry point of Sendinblue module.
 */
use Drupal\sendinblue\SendinblueManager;
use Drupal\user\UserInterface;

/**
 * Implements hook_help().
 */
function sendinblue_help($path, $arg) {
  switch ($path) {
    case 'admin/help#sendinblue':
      return t('Sendinblue module provides integration with the SendinBlue email delivery service.');
  }
}

/**
 * Register a module (or theme's) theme implementations.
 *
 * @see hook_theme_registry_alter()
 */
function sendinblue_theme($existing, $type, $theme, $path) {
  return [
    'generateHomeLogout' => [
      'variables' => [
        'formulaire_api_key' => NULL,
      ],
    ],
    'generateHomeLogin' => [
      'variables' => [
        'api_version' => NULL,
        'account_username' => NULL,
        'account_email' => NULL,
        'account_data' => NULL,
        'total_subscribers' => NULL,
        'sendinblue_logout_form' => NULL,
        'sendinblue_user_register_form' => NULL,
        'sendinblue_send_email_form' => NULL,
      ],
    ],
    'iframe_page' => [
      'variables' => [
        'url_iframe' => NULL,
      ],
    ],
  ];
}

/**
 * Add attachments (typically assets) to a page before it is rendered.
 *
 * @param array &$attachments
 *   An array that you can add attachments to.
 *
 * @see hook_page_attachments_alter()
 */
function sendinblue_page_attachments(array &$attachments) {
  if (\Drupal::service('router.admin_context')
    ->isAdminRoute()) {
    $route_match = \Drupal::routeMatch();
    if (strpos($route_match
      ->getRouteName(), 'sendinblue') !== FALSE) {
      $attachments['#attached']['library'][] = 'sendinblue/sendinblue.admin-setting';
    }
  }
}

/**
 * Implements hook_ENTITY_TYPE_insert() for node entities.
 *
 * This tests saving a node on node insert.
 *
 * @see \Drupal\node\Tests\NodeSaveTest::testNodeSaveOnInsert()
 */
function sendinblue_user_insert(UserInterface $user) {

  /** @var \Drupal\sendinblue\SendinblueManager $sendInBlueManager */
  $sendInBlueManager = \Drupal::service('sendinblue.manager');

  /** @var \Drupal\Core\Config\ConfigFactoryInterface $configFactory */
  $configFactory = \Drupal::service('config.factory');
  $sendinblue_registered_active = $configFactory
    ->get(SendinblueManager::CONFIG_SETTINGS_REGISTERING_USER)
    ->get('sendinblue_put_registered_user')['active'];
  $sendinblue_registered_list = $configFactory
    ->get(SendinblueManager::CONFIG_SETTINGS_REGISTERING_USER)
    ->get('sendinblue_put_registered_user')['list'];
  if ($sendInBlueManager
    ->isLoggedInState() && $sendinblue_registered_active) {
    $sendInBlueManager
      ->subscribeUser($user
      ->getEmail(), [
      'nom' => $user
        ->getAccountName(),
    ], [
      $sendinblue_registered_list,
    ]);
    return;
  }
}

Functions

Namesort descending Description
sendinblue_help Implements hook_help().
sendinblue_page_attachments Add attachments (typically assets) to a page before it is rendered.
sendinblue_theme Register a module (or theme's) theme implementations.
sendinblue_user_insert Implements hook_ENTITY_TYPE_insert() for node entities.