public function PotxExtractTranslationForm::submitForm in Translation template extractor 8
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- src/
Form/ PotxExtractTranslationForm.php, line 130
Class
- PotxExtractTranslationForm
- Class PotxExtractTranslationForm.
Namespace
Drupal\potx\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
// This could take some time.
@set_time_limit(0);
$this->moduleHandler
->loadInclude('potx', 'inc');
$this->moduleHandler
->loadInclude('potx', 'inc', 'potx.local');
// Silence status messages.
potx_status('set', POTX_STATUS_MESSAGE);
// $form_state->getValue('component') either contains a specific file name
// with path, or a directory name for a module/theme or a module suite.
// Examples:
// - modules/watchdog
// - sites/all/modules/coder
// - sites/all/modules/i18n/i18n.module
// - themes/garland.
$component = $form_state
->getValue('component');
$pathinfo = pathinfo($component);
if (!isset($pathinfo['filename'])) {
// The filename key is only available in PHP 5.2.0+.
$pathinfo['filename'] = substr($pathinfo['basename'], 0, strrpos($pathinfo['basename'], '.'));
}
if (isset($pathinfo['extension'])) {
// A specific module or theme file was requested (otherwise there should
// be no extension).
potx_local_init($pathinfo['dirname']);
$files = _potx_explore_dir($pathinfo['dirname'] . '/', $pathinfo['filename']);
$strip_prefix = 1 + strlen($pathinfo['dirname']);
$outputname = $pathinfo['filename'];
}
else {
potx_local_init($component);
$files = _potx_explore_dir($component . '/');
$strip_prefix = 1 + strlen($component);
$outputname = $pathinfo['basename'];
}
// Decide on template or translation file generation.
$template_langcode = $translation_langcode = NULL;
if ($form_state
->hasValue('langcode') && $form_state
->getValue('langcode') != 'n/a') {
$template_langcode = $form_state
->getValue('langcode');
$outputname .= '.' . $template_langcode;
if (!empty($form_state
->getValue('translations'))) {
$translation_langcode = $template_langcode;
$outputname .= '.po';
}
else {
$outputname .= '.pot';
}
}
else {
$outputname .= '.pot';
}
// Collect every string in affected files. Installer related strings are
// discarded.
foreach ($files as $file) {
_potx_process_file($file, $strip_prefix);
}
potx_finish_processing('_potx_save_string');
// Need to include full parameter list to get to passing the language codes.
_potx_build_files(POTX_STRING_RUNTIME, POTX_BUILD_SINGLE, 'general', '_potx_save_string', '_potx_save_version', '_potx_get_header', $template_langcode, $translation_langcode);
_potx_write_files($outputname, 'attachment');
exit;
}