You are here

function mandrill_get_module_key_names in Mandrill 8

Same name and namespace in other branches
  1. 7.2 mandrill.module \mandrill_get_module_key_names()
  2. 7 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()
MandrillTemplateMapForm::form in modules/mandrill_template/src/Form/MandrillTemplateMapForm.php
Gets the actual form array to be built.

File

./mandrill.module, line 104
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 (\Drupal::service('extension.list.module')
    ->getList() as $item) {
    if ($item->status && !empty($item->info['name'])) {
      $descriptions[strtolower($item
        ->getName())] = (empty($item->info['package']) ? '' : $item->info['package']) . ' » ' . t(':module module', array(
        ':module' => $item->info['name'],
      ));
    }
  }
  asort($descriptions);
  $mailsystem_config = \Drupal::service('config.factory')
    ->get('mailsystem.settings');
  $modules = $mailsystem_config
    ->get('modules');
  if (!empty($modules)) {
    foreach (array_keys($modules) as $module_name) {
      foreach ($modules[$module_name] as $key => $options) {
        $id = $module_name . '_' . $key;
        $title = preg_replace('/^.* » /', '', $descriptions[$module_name]);
        $title .= " ({$key} key)";
        $name_array[$id] = $title;
      }
    }
  }
  return $name_array;
}