You are here

public function ContentSingleImportForm::validateForm in Content Synchronization 8

Same name and namespace in other branches
  1. 8.2 src/Form/ContentSingleImportForm.php \Drupal\content_sync\Form\ContentSingleImportForm::validateForm()
  2. 3.0.x src/Form/ContentSingleImportForm.php \Drupal\content_sync\Form\ContentSingleImportForm::validateForm()

Form validation 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 FormBase::validateForm

File

src/Form/ContentSingleImportForm.php, line 44

Class

ContentSingleImportForm
Provides a form for importing a single content file.

Namespace

Drupal\content_sync\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  try {

    // Decode the submitted import.
    $data = Yaml::decode($form_state
      ->getValue('import'));

    // Store the decoded version of the submitted import.
    $form_state
      ->setValueForElement($form['import'], $data);
  } catch (\Exception $e) {
    $form_state
      ->setErrorByName('import', $this
      ->t('The import failed with the following message: %message', [
      '%message' => $e
        ->getMessage(),
    ]));
    $this
      ->logger('content_sync')
      ->error('The import failed with the following message: %message', [
      '%message' => $e
        ->getMessage(),
      'link' => 'Import Single',
    ]);
  }
}