diff core/modules/update/src/Form/UpdateManagerInstall.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children
line wrap: on
line diff
--- a/core/modules/update/src/Form/UpdateManagerInstall.php	Thu Feb 28 11:14:44 2019 +0000
+++ b/core/modules/update/src/Form/UpdateManagerInstall.php	Thu Feb 28 13:11:55 2019 +0000
@@ -135,18 +135,19 @@
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
     $local_cache = NULL;
+    $all_files = $this->getRequest()->files->get('files', []);
     if ($form_state->getValue('project_url')) {
       $local_cache = update_manager_file_get($form_state->getValue('project_url'));
       if (!$local_cache) {
-        drupal_set_message($this->t('Unable to retrieve Drupal project from %url.', ['%url' => $form_state->getValue('project_url')]), 'error');
+        $this->messenger()->addError($this->t('Unable to retrieve Drupal project from %url.', ['%url' => $form_state->getValue('project_url')]));
         return;
       }
     }
-    elseif ($_FILES['files']['name']['project_upload']) {
+    elseif (!empty($all_files['project_upload'])) {
       $validators = ['file_validate_extensions' => [archiver_get_extensions()]];
       if (!($finfo = file_save_upload('project_upload', $validators, NULL, 0, FILE_EXISTS_REPLACE))) {
         // Failed to upload the file. file_save_upload() calls
-        // drupal_set_message() on failure.
+        // \Drupal\Core\Messenger\MessengerInterface::addError() on failure.
         return;
       }
       $local_cache = $finfo->getFileUri();
@@ -157,13 +158,13 @@
       $archive = update_manager_archive_extract($local_cache, $directory);
     }
     catch (\Exception $e) {
-      drupal_set_message($e->getMessage(), 'error');
+      $this->messenger()->addError($e->getMessage());
       return;
     }
 
     $files = $archive->listContents();
     if (!$files) {
-      drupal_set_message($this->t('Provided archive contains no files.'), 'error');
+      $this->messenger()->addError($this->t('Provided archive contains no files.'));
       return;
     }
 
@@ -174,12 +175,12 @@
 
     $archive_errors = $this->moduleHandler->invokeAll('verify_update_archive', [$project, $local_cache, $directory]);
     if (!empty($archive_errors)) {
-      drupal_set_message(array_shift($archive_errors), 'error');
+      $this->messenger()->addError(array_shift($archive_errors));
       // @todo: Fix me in D8: We need a way to set multiple errors on the same
       // form element and have all of them appear!
       if (!empty($archive_errors)) {
         foreach ($archive_errors as $error) {
-          drupal_set_message($error, 'error');
+          $this->messenger()->addError($error);
         }
       }
       return;
@@ -193,7 +194,7 @@
       $updater = Updater::factory($project_location, $this->root);
     }
     catch (\Exception $e) {
-      drupal_set_message($e->getMessage(), 'error');
+      $this->messenger()->addError($e->getMessage());
       return;
     }
 
@@ -201,16 +202,16 @@
       $project_title = Updater::getProjectTitle($project_location);
     }
     catch (\Exception $e) {
-      drupal_set_message($e->getMessage(), 'error');
+      $this->messenger()->addError($e->getMessage());
       return;
     }
 
     if (!$project_title) {
-      drupal_set_message($this->t('Unable to determine %project name.', ['%project' => $project]), 'error');
+      $this->messenger()->addError($this->t('Unable to determine %project name.', ['%project' => $project]));
     }
 
     if ($updater->isInstalled()) {
-      drupal_set_message($this->t('%project is already installed.', ['%project' => $project_title]), 'error');
+      $this->messenger()->addError($this->t('%project is already installed.', ['%project' => $project_title]));
       return;
     }