You are here

function mandrill_get_module_key_names in Mandrill 7

Same name and namespace in other branches
  1. 8 mandrill.module \mandrill_get_module_key_names()
  2. 7.2 mandrill.module \mandrill_get_module_key_names()

Display the names of the modules that are using Mailsystem.

This is consistent with with Mailsystem's display. In the future, if Mailsystem were to provide an API for their labeling, that should be used.

Return value

array Array of all module names indexing to their "display" names, and some special items for non-module values like null, default-system, and some clarification talked onto the end of the Mandrill module's name.

1 call to mandrill_get_module_key_names()
mandrill_template_map_form in modules/mandrill_template/mandrill_template.admin.inc
Return a form for adding/editing a Mandrill template map.

File

./mandrill.module, line 267
Enables Drupal to send email directly through Mandrill.

Code

function mandrill_get_module_key_names() {
  $name_array = array(
    '' => '--none--',
    'default-system' => "Site-wide default",
  );
  $descriptions = array();
  foreach (system_rebuild_module_data() as $item) {
    if ($item->status) {
      $descriptions[$item->name] = (empty($item->info['package']) ? '' : $item->info['package']) . ' » ' . t('!module module', array(
        '!module' => $item->info['name'],
      ));
    }
  }
  asort($descriptions);
  $mailsystem_settings = mailsystem_get();
  unset($mailsystem_settings['default-system']);
  foreach ($mailsystem_settings as $id => $class) {

    // Separate $id into $module and $key.
    $module = $id;
    while ($module && empty($descriptions[$module])) {

      // Remove a key from the end.
      $module = implode('_', explode('_', $module, -1));
    }

    // If an array key of the $mail_system variable is neither "default-system"
    // nor begins with a module name, then it should be unset.
    if (empty($module)) {

      // This shouldn't happen.
    }

    // Set $title to the human-readable module name.
    $title = preg_replace('/^.* » /', '', $descriptions[$module]);
    if ($key = substr($id, strlen($module) + 1)) {
      $title .= " ({$key} key)";
    }
    $name_array[$id] = $title;
  }
  return $name_array;
}