Commit 9720aecd authored by catch's avatar catch

Issue #2721139 by klausi, dawehner: Replace deprecated files ParameterBag usage

parent 9fc74f76
......@@ -99,8 +99,8 @@ public function buildForm(array $form, FormStateInterface $form_state) {
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
// If both fields are empty or filled, cancel.
$file_upload = $this->getRequest()->files->get('files[upload]', NULL, TRUE);
if ($form_state->isValueEmpty('remote') == empty($file_upload)) {
$all_files = $this->getRequest()->files->get('files', []);
if ($form_state->isValueEmpty('remote') == empty($all_files['upload'])) {
$form_state->setErrorByName('remote', $this->t('<em>Either</em> upload a file or enter a URL.'));
}
}
......
......@@ -67,13 +67,16 @@ public function buildForm(array $form, FormStateInterface $form_state) {
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$file_upload = $this->getRequest()->files->get('files[import_tarball]', NULL, TRUE);
if ($file_upload && $file_upload->isValid()) {
$form_state->setValue('import_tarball', $file_upload->getRealPath());
}
else {
$form_state->setErrorByName('import_tarball', $this->t('The file could not be uploaded.'));
$all_files = $this->getRequest()->files->get('files', []);
if (!empty($all_files['import_tarball'])) {
$file_upload = $all_files['import_tarball'];
if ($file_upload->isValid()) {
$form_state->setValue('import_tarball', $file_upload->getRealPath());
return;
}
}
$form_state->setErrorByName('import_tarball', $this->t('The file could not be uploaded.'));
}
/**
......
......@@ -709,11 +709,12 @@ function file_save_upload($form_field_name, $validators = array(), $destination
$user = \Drupal::currentUser();
static $upload_cache;
$file_upload = \Drupal::request()->files->get("files[$form_field_name]", NULL, TRUE);
$all_files = \Drupal::request()->files->get('files', array());
// Make sure there's an upload to process.
if (empty($file_upload)) {
if (empty($all_files[$form_field_name])) {
return NULL;
}
$file_upload = $all_files[$form_field_name];
// Return cached objects without processing since the file will have
// already been processed and the paths in $_FILES will be invalid.
......@@ -1168,10 +1169,11 @@ function file_managed_file_submit($form, FormStateInterface $form_state) {
*/
function file_managed_file_save_upload($element, FormStateInterface $form_state) {
$upload_name = implode('_', $element['#parents']);
$file_upload = \Drupal::request()->files->get("files[$upload_name]", NULL, TRUE);
if (empty($file_upload)) {
$all_files = \Drupal::request()->files->get('files', array());
if (empty($all_files[$upload_name])) {
return FALSE;
}
$file_upload = $all_files[$upload_name];
$destination = isset($element['#upload_location']) ? $element['#upload_location'] : NULL;
if (isset($destination) && !file_prepare_directory($destination, FILE_CREATE_DIRECTORY)) {
......
......@@ -122,8 +122,8 @@ public function buildForm(array $form, FormStateInterface $form_state) {
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$uploaded_file = $this->getRequest()->files->get('files[project_upload]', NULL, TRUE);
if (!($form_state->getValue('project_url') xor !empty($uploaded_file))) {
$all_files = $this->getRequest()->files->get('files', []);
if (!($form_state->getValue('project_url') xor !empty($all_files['project_upload']))) {
$form_state->setErrorByName('project_url', $this->t('You must either provide a URL or upload an archive file to install.'));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment