You are here

public function ActionsForm::copyLocalValidateForm in S3 File System 4.0.x

Same name and namespace in other branches
  1. 8.3 src/Form/ActionsForm.php \Drupal\s3fs\Form\ActionsForm::copyLocalValidateForm()

Validates the form.

Parameters

array $form: Array that contains the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

File

src/Form/ActionsForm.php, line 256

Class

ActionsForm
Defines an actions form.

Namespace

Drupal\s3fs\Form

Code

public function copyLocalValidateForm(array &$form, FormStateInterface $form_state) {
  $this
    ->validateConfigValidateForm($form, $form_state);
  $normal_wrappers = \Drupal::service('stream_wrapper_manager')
    ->getNames(StreamWrapperInterface::NORMAL);
  $triggering_element = $form_state
    ->getTriggeringElement();
  $destination_scheme = $triggering_element['#name'];
  if (!empty($normal_wrappers[$destination_scheme])) {
    if ($destination_scheme == 'private' && !Settings::get('file_private_path')) {
      $form_state
        ->setError($form, $this
        ->t("Private system is not properly configurated, check \$settings['file_private_path'] in your settings.php."));
    }
  }
  else {
    $form_state
      ->setError($form, $this
      ->t('Scheme @scheme is not supported.', [
      '@scheme' => $destination_scheme,
    ]));
  }
  $config = \Drupal::config('s3fs.settings')
    ->get();
  $submittedCondition = $form_state
    ->getValue('upload_condition');
  $uploadConditions = [];
  switch ($submittedCondition) {
    case 'always':
      $uploadConditions['always'] = TRUE;
      break;
    case 'newer_size':
      $uploadConditions['newer'] = TRUE;
      $uploadConditions['size'] = TRUE;
      break;
    case 'newer':
      $uploadConditions['newer'] = TRUE;
      break;
    case 'size':
      $uploadConditions['size'] = TRUE;
      break;
  }
  $form_state
    ->set('upload_conditions', $uploadConditions);

  // Use this values for submit step.
  $form_state
    ->set('s3fs', [
    'config' => $config,
    'scheme' => $destination_scheme,
  ]);
}