public function SourceSelectForm::submitForm in WordPress Migrate 8.3
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
- wordpress_migrate_ui/
src/ Form/ SourceSelectForm.php, line 67
Class
- SourceSelectForm
- Simple wizard step form.
Namespace
Drupal\wordpress_migrate_ui\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$validators = [
'file_validate_extensions' => [
'xml',
],
];
// file_save_upload renames if file already exists (default behavior)
$file = file_save_upload('wxr_file', $validators, 'public://', 0);
if ($file) {
$cached_values = $form_state
->getTemporaryValue('wizard');
$cached_values['file_uri'] = $file
->getFileUri();
if ($form_state
->getValue('keep_wxr_file')) {
/* Set the status flag permanent of the file object */
$file
->setPermanent();
/* Save the file in database */
try {
$file
->save();
} catch (EntityStorageException $e) {
$this
->messenger()
->addError('The WXR file failed to upload. Please try again.');
$this
->logger('wordpress_migrate')
->error('The WXR file failed to upload. (EntityStorageException)');
}
}
$form_state
->setTemporaryValue('wizard', $cached_values);
// @todo: Preprocess the file
// @link https://www.drupal.org/node/2742301
}
else {
$form_state
->setRebuild();
$this
->messenger()
->addError($this
->t('WXR file upload failed. Please try again. Your log messages may have additional information.'));
$this
->logger('wordpress_migrate')
->error('The WXR file failed to upload.');
}
}