You are here

function _potx_build_module_form in Translation template extractor 5

Same name and namespace in other branches
  1. 5.2 potx.module \_potx_build_module_form()
  2. 6 potx.module \_potx_build_module_form()

Build a chunk of the module selection form.

Parameters

$form: Form to populate with fields.

$modules: Structured array with modules as returned by _potx_module_list().

$dirname: Name of directory handled.

1 call to _potx_build_module_form()
potx_select_form in ./potx.module
Module selection interface.

File

./potx.module, line 170
Gettext translation template and translation extractor.

Code

function _potx_build_module_form(&$form, &$modules, $dirname = '') {

  // Pop off count of modules in this directory.
  if (isset($modules['.modulecount'])) {
    $modules_in_dir = $modules['.modulecount'];
    unset($modules['.modulecount']);
  }
  ksort($modules);
  $dirkeys = array_keys($modules);

  // A directory with one module.
  if (isset($modules_in_dir) && count($modules) == 1) {
    $module_dir = dirname($modules[$dirkeys[0]]->filename);
    $form[_potx_form_id('dir', $module_dir)] = array(
      '#type' => 'radio',
      '#title' => t('Extract from %module_name module, in directory %dir_name', array(
        '%dir_name' => $module_dir,
        '%module_name' => basename($modules[$dirkeys[0]]->basename, '.module'),
      )),
      '#description' => t('Generates output from all files found in this directory.'),
      '#default_value' => 0,
      '#return_value' => $module_dir,
      // Get all radio buttons into the same group.
      '#parents' => array(
        'module',
      ),
    );
    return;
  }

  // A directory with multiple modules in it.
  if (preg_match('!/modules\\b(/.+)?!', $dirname, $pathmatch)) {
    $subst = array(
      '@dir_name' => substr($dirname, 1),
    );
    if (isset($pathmatch[1])) {
      $form[_potx_form_id('dir', $dirname)] = array(
        '#type' => 'radio',
        '#title' => t('Extract from all modules in directory "@dir_name"', $subst),
        '#description' => t('To extract from a single module in this directory, choose the module entry in the fieldset below.'),
        '#default_value' => 0,
        '#return_value' => substr($dirname, 1),
        // Get all radio buttons into the same group.
        '#parents' => array(
          'module',
        ),
      );
    }
    $element = array(
      '#type' => 'fieldset',
      '#title' => t('Modules in "@dir_name"', $subst),
      '#collapsible' => true,
      '#collapsed' => true,
    );
    $form[_potx_form_id('fs', $dirname)] =& $element;
  }
  else {
    $element =& $form;
  }
  foreach ($dirkeys as $entry) {

    // A module in this directory with multiple modules.
    if ($entry[0] == '#') {
      $subst = array(
        '%module_dir' => dirname($modules[$entry]->filename),
        '%module_name' => basename($modules[$entry]->basename, '.module'),
        '%module_pattern' => basename($modules[$entry]->basename, '.module') . '.*',
      );
      $element[_potx_form_id('mod', $modules[$entry]->basename)] = array(
        '#type' => 'radio',
        '#title' => t('Extract from module %module_name', $subst),
        '#description' => t('Extract from files named %module_pattern, in directory %module_dir.', $subst),
        '#default_value' => 0,
        '#return_value' => $modules[$entry]->filename,
        // Get all radio buttons into the same group.
        '#parents' => array(
          'module',
        ),
      );
    }
    else {
      _potx_build_module_form($element, $modules[$entry], "{$dirname}/{$entry}");
    }
  }
  return count($modules);
}