You are here

function mandrill_template_map_load_by_mailsystem in Mandrill 8

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

Gets the Mandrill Template Map configured for a mailsystem key, if any.

Will search for a default-system mapping if none is availble for a given key.

Parameters

string $module_key: Module key to use when searching for a template mapping.

string $module: Module name to use when searching for a template mapping.

Return value

entity The Mandrill Template Map, if found.

1 call to mandrill_template_map_load_by_mailsystem()
MandrillTemplateService::send in modules/mandrill_template/src/MandrillTemplateService.php
Abstracts sending of messages, allowing queueing option.

File

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

Code

function mandrill_template_map_load_by_mailsystem($module_key, $module) {

  // Append the default-system condition as a fallback.
  $params = array(
    $module_key,
    $module,
    'default-system',
  );
  $map_ids = \Drupal::entityQuery('mandrill_template_map')
    ->condition('mailsystem_key', $params, 'IN')
    ->execute();
  $template_maps = \Drupal\mandrill_template\Entity\MandrillTemplateMap::loadMultiple($map_ids);
  $module_match = FALSE;
  if (!empty($template_maps)) {

    /* @var $map \Drupal\mandrill_template\Entity\MandrillTemplateMap */
    foreach ($template_maps as $template_map) {
      switch ($template_map->mailsystem_key) {
        case $module_key:
          return $template_map;
        case $module:
          $module_match = $template_map;
          break;
      }
    }
    return $module_match ? $module_match : reset($template_maps);
  }
  return NULL;
}