You are here

public function BrightcoveVideoForm::validateForm in Brightcove Video Connect 8

Same name and namespace in other branches
  1. 8.2 src/Form/BrightcoveVideoForm.php \Drupal\brightcove\Form\BrightcoveVideoForm::validateForm()
  2. 3.x src/Form/BrightcoveVideoForm.php \Drupal\brightcove\Form\BrightcoveVideoForm::validateForm()

Button-level validation handlers are highly discouraged for entity forms, as they will prevent entity validation from running. If the entity is going to be saved during the form submission, this method should be manually invoked from the button-level validation handler, otherwise an exception will be thrown.

Overrides ContentEntityForm::validateForm

File

src/Form/BrightcoveVideoForm.php, line 216

Class

BrightcoveVideoForm
Form controller for Brightcove Video edit forms.

Namespace

Drupal\brightcove\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);

  /* @var $entity \Drupal\brightcove\Entity\BrightcoveVideo */
  $entity = $this->entity;
  switch ($form_state
    ->getValue('upload_type')) {
    case 'file':
      if ($entity
        ->isNew() || !empty($form_state
        ->getValue('video_file')[0]['fids'])) {
        $form_state
          ->unsetValue('video_url');
        $entity
          ->setVideoUrl(NULL);
      }
      break;
    case 'url':
      if ($entity
        ->isNew()) {
        $form_state
          ->unsetValue('video_file');
      }
      elseif (!empty($form_state
        ->getValue('video_url')[0]['value'])) {
        $form_state
          ->unsetValue('video_file');
        $entity
          ->setVideoFile(NULL);
      }
      break;
  }
}