/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { // File deletion status. $status = TRUE; // Delete the selected file(s), with recursion if selected. $status = uc_file_remove_by_id($form_state->getValue('file_ids'), !$form_state->isValueEmpty('recurse_directories')) && $status; if ($status) { drupal_set_message($this->t('The selected file(s) have been deleted.')); } else { drupal_set_message($this->t('One or more files could not be deleted.'), 'warning'); } $form_state->setRedirect('uc_file.downloads'); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { switch ($form_state->getValue('action')) { case 'uc_file_delete': // File deletion status. $status = TRUE; // Delete the selected file(s), with recursion if selected. $status = uc_file_remove_by_id($form_state->getValue('file_ids'), !$form_state->isValueEmpty('recurse_directories')) && $status; if ($status) { drupal_set_message(t('The selected file(s) have been deleted.')); } else { drupal_set_message(t('One or more files could not be deleted.')); } break; case 'uc_file_upload': // Build the destination location. We start with the base directory, // then add any directory which was explicitly selected. $dir = \Drupal::config('uc_file.settings')->get('base_dir') . '/' . $form_state->getValue('upload_dir'); if (is_dir($dir)) { // Retrieve our uploaded file. $file_object = $form_state->get('temp_file'); // Copy the file to its final location. if (copy($file_object->uri, $dir . '/' . $file_object->filename)) { // Check if any hook_uc_file_action('upload', $args) are implemented $module_handler = \Drupal::moduleHandler(); foreach ($module_handler->getImplementations('uc_file_action') as $module) { $name = $module . '_uc_file_action'; $name('upload', array('file_object' => $file_object, 'form_id' => $form_id, 'form_state' => $form_state)); } // Update the file list uc_file_refresh(); drupal_set_message(t('The file %file has been uploaded to %dir', array('%file' => $file_object->filename, '%dir' => $dir))); } else { drupal_set_message(t('An error occurred while copying the file to %dir', array('%dir' => $dir))); } } else { drupal_set_message(t('Can not move file to %dir', array('%dir' => $dir))); } break; default: // This action isn't handled by us, so check if any // hook_uc_file_action('submit', $args) are implemented $module_handler = \Drupal::moduleHandler(); foreach ($module_handler->getImplementations('uc_file_action') as $module) { $name = $module . '_uc_file_action'; $name('submit', array('form_id' => $form_id, 'form_state' => $form_state)); } break; } // Return to the original form state. $form_state->setRebuild(FALSE); drupal_goto('admin/store/products/files'); }