private function PotxExtractTranslationForm::buildComponentSelector in Translation template extractor 8
Build a chunk of the component selection form.
Parameters
array $form: Form to populate with fields.
array $components: Structured array with components as returned by $this->generateComponentList().
string $dirname: Name of directory handled.
Return value
mixed A count of the number of components or void.
1 call to PotxExtractTranslationForm::buildComponentSelector()
- PotxExtractTranslationForm::buildForm in src/
Form/ PotxExtractTranslationForm.php - Form constructor.
File
- src/
Form/ PotxExtractTranslationForm.php, line 252
Class
- PotxExtractTranslationForm
- Class PotxExtractTranslationForm.
Namespace
Drupal\potx\FormCode
private function buildComponentSelector(array &$form, array &$components, $dirname = '') {
// Pop off count of components in this directory.
if (isset($components['#-count'])) {
$component_count = $components['#-count'];
unset($components['#-count']);
}
$dirkeys = array_keys($components);
// A directory with one component.
if (isset($component_count) && count($components) == 1) {
$component = array_shift($components);
$dirname = $component
->getPath();
$form[$this
->getFormElementId('dir', $dirname)] = [
'#type' => 'radio',
'#title' => t('Extract from %name in the %directory directory', [
'%directory' => $dirname,
'%name' => $component
->getName(),
]),
'#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' => [
'component',
],
];
return;
}
// A directory with multiple components in it.
if (preg_match('!/(modules|themes)\\b(/.+)?!', $dirname, $pathmatch)) {
$t_args = [
'@directory' => substr($dirname, 1),
];
if (isset($pathmatch[2])) {
$form[$this
->getFormElementId('dir', $dirname)] = [
'#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' => [
'component',
],
];
}
$element = [
'#type' => 'details',
'#title' => t('Directory "@directory"', $t_args),
'#open' => FALSE,
];
$form[$this
->getFormElementId('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 = [
'%directory' => $components[$entry]
->getPath(),
'%name' => $components[$entry]
->getName(),
'%pattern' => $components[$entry]
->getName() . '.*',
];
$element[$this
->getFormElementId('com', $components[$entry]
->getExtensionFilename())] = [
'#type' => 'radio',
'#title' => $this
->t('Extract from %name', $t_args),
'#description' => $this
->t('Extract from files named %pattern in the %directory directory.', $t_args),
'#default_value' => 0,
'#return_value' => $components[$entry]
->getExtensionPathname(),
// Get all radio buttons into the same group.
'#parents' => [
'component',
],
];
}
else {
$this
->buildComponentSelector($element, $components[$entry], "{$dirname}/{$entry}");
}
}
return count($components);
}