You are here

function mandrill_template_map_usage in Mandrill 8

Same name and namespace in other branches
  1. 7.2 modules/mandrill_template/mandrill_template.module \mandrill_template_map_usage()
  2. 7 modules/mandrill_template/mandrill_template.module \mandrill_template_map_usage()

Get all mailsystem keys pointed at mandrill and their template mappings.

Return value

array Returns an array with indexes matching each module which is assigned to use Mandrill for email sends, and values equal to the template_map_ids that are assigned to those modules. If no template maps are assigned, the value is set to NULL.

1 call to mandrill_template_map_usage()
MandrillTemplateMapForm::form in modules/mandrill_template/src/Form/MandrillTemplateMapForm.php
Gets the actual form array to be built.

File

modules/mandrill_template/mandrill_template.module, line 82
Enables Drupal to send email using Mandrill's template system.

Code

function mandrill_template_map_usage() {
  $mailsystem_config = \Drupal::service('config.factory')
    ->get('mailsystem.settings');
  $defaults = $mailsystem_config
    ->get('defaults');
  $modules = $mailsystem_config
    ->get('modules');
  $system_assignments = array();
  if (in_array($defaults['sender'], [
    'mandrill_mail',
    'mandrill_test_mail',
  ])) {
    $system_assignments['default-system'] = NULL;
  }
  if (!empty($modules)) {
    foreach (array_keys($modules) as $module_name) {
      foreach ($modules[$module_name] as $key => $options) {
        if (in_array($options['sender'], [
          'mandrill_mail',
          'mandrill_test_mail',
        ])) {
          $system_assignments[$module_name . '_' . $key] = NULL;
        }
      }
    }
  }
  $maps = mandrill_template_map_load_entities();
  foreach ($maps as $map) {
    if (isset($map->mailsystem_key) && array_key_exists($map->mailsystem_key, $system_assignments) && isset($map->mandrill_template_map_entity_id)) {
      $system_assignments[$map->mailsystem_key] = $map->mandrill_template_map_entity_id;
    }
  }
  uksort($system_assignments, '_mandrill_template_map_mailsystem_sort');
  return $system_assignments;
}