You are here

function _potx_component_selector in Translation template extractor 6.2

Same name and namespace in other branches
  1. 6.3 potx.admin.inc \_potx_component_selector()
  2. 7.3 potx.admin.inc \_potx_component_selector()
  3. 7 potx.module \_potx_component_selector()
  4. 7.2 potx.admin.inc \_potx_component_selector()

Build a chunk of the component selection form.

Parameters

$form: Form to populate with fields.

$components: Structured array with components as returned by _potx_component_list().

$dirname: Name of directory handled.

1 call to _potx_component_selector()
potx_select_form in ./potx.module
Component selection interface.

File

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

Code

function _potx_component_selector(&$form, &$components, $dirname = '') {

  // Pop off count of components in this directory.
  if (isset($components['#-count'])) {
    $component_count = $components['#-count'];
    unset($components['#-count']);
  }

  //ksort($components);
  $dirkeys = array_keys($components);

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

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

    // A component in this directory with multiple components.
    if ($entry[0] == '#') {

      // Component entry.
      $t_args = array(
        '%directory' => dirname($components[$entry]->filename),
        '%name' => $components[$entry]->name,
        '%pattern' => $components[$entry]->name . '.*',
      );
      $element[_potx_form_id('com', $components[$entry]->basename)] = array(
        '#type' => 'radio',
        '#title' => t('Extract from %name', $t_args),
        '#description' => t('Extract from files named %pattern in the %directory directory.', $t_args),
        '#default_value' => 0,
        '#return_value' => $components[$entry]->filename,
        // Get all radio buttons into the same group.
        '#parents' => array(
          'component',
        ),
      );
    }
    else {
      _potx_component_selector($element, $components[$entry], "{$dirname}/{$entry}");
    }
  }
  return count($components);
}