public function UpgradeStatusForm::submitForm in Upgrade Status 8.2
Same name and namespace in other branches
- 8.3 src/Form/UpgradeStatusForm.php \Drupal\upgrade_status\Form\UpgradeStatusForm::submitForm()
- 8 src/Form/UpgradeStatusForm.php \Drupal\upgrade_status\Form\UpgradeStatusForm::submitForm()
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/ UpgradeStatusForm.php, line 759
Class
Namespace
Drupal\upgrade_status\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$operations = [];
$projects = $this->projectCollector
->collectProjects();
$submitted = $form_state
->getValues();
// It is not possible to make an HTTP request to this same webserver
// if the host server is PHP itself, because it is single-threaded.
// See https://www.php.net/manual/en/features.commandline.webserver.php
$use_http = php_sapi_name() != 'cli-server';
$php_server = !$use_http;
if ($php_server) {
// Log the selected processing method for project support purposes.
$this->logger
->notice('Processing projects without HTTP sandboxing because the built-in PHP webserver does not allow for that.');
}
else {
// Attempt to do an HTTP request to the frontpage of this Drupal instance.
// If that does not work then we'll not be able to process projects over
// HTTP. Processing projects directly is less safe (in case of PHP fatal
// errors the batch process may halt), but we have no other choice here
// but to take a chance.
list($error, $message, $data) = static::doHttpRequest('upgrade_status_request_test', 'upgrade_status_request_test');
if (empty($data) || !is_array($data) || $data['message'] != 'Request test success') {
$use_http = FALSE;
$this->logger
->notice('Processing projects without HTTP sandboxing. @error', [
'@error' => $message,
]);
}
}
if ($use_http) {
// Log the selected processing method for project support purposes.
$this->logger
->notice('Processing projects with HTTP sandboxing.');
}
foreach ([
'custom',
'contrib',
] as $type) {
$states = [
'uninstalled',
'installed',
];
foreach ($states as $state) {
if (!empty($submitted[$type]['data'][$state])) {
foreach ($submitted[$type]['data'][$state] as $project => $checked) {
if ($checked !== 0) {
// If the checkbox was checked, add a batch operation.
$operations[] = [
static::class . '::parseProject',
[
$projects[$type][$project],
$use_http,
],
];
}
}
}
}
}
if (!empty($operations)) {
// Allow other modules to alter the operations to be run.
$this->moduleHandler
->alter('upgrade_status_operations', $operations, $form_state);
}
if (!empty($operations)) {
$batch = [
'title' => $this
->t('Scanning projects'),
'operations' => $operations,
];
batch_set($batch);
}
else {
$this
->messenger()
->addError('No projects selected to scan.');
}
}