You are here

public function BackgroundVideoSettingsForm::submitForm in Background Video 8

Form submission 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 ConfigFormBase::submitForm

File

src/Form/BackgroundVideoSettingsForm.php, line 89

Class

BackgroundVideoSettingsForm

Namespace

Drupal\background_video\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $config = $this
    ->configFactory()
    ->getEditable('config.background_video');
  $values = $form_state
    ->getValues();
  $config
    ->set('background_video_source_mp4', $values['background_video_source_mp4'])
    ->set('background_video_source_webm', $values['background_video_source_webm'])
    ->set('background_video_source_ogv', $values['background_video_source_ogv'])
    ->set('background_video_id', $values['background_video_id'])
    ->set('background_video_control_position', $values['background_video_control_position'])
    ->set('background_video_autoplay', $values['background_video_autoplay'])
    ->set('background_video_loop', $values['background_video_loop'])
    ->set('background_video_source_poster', $values['background_video_source_poster'])
    ->save();
  $file_types = [
    'mp4',
    'ogv',
    'webm',
    'poster',
  ];
  foreach ($file_types as $ftype) {
    $fid = $values['background_video_source_' . $ftype][0];
    $file = File::load($fid);
    $file->status = FILE_STATUS_PERMANENT;
    $file
      ->save();
    $file_usage = \Drupal::service('file.usage');
    $file_usage
      ->add($file, 'background_video', 'file', $fid);
    parent::submitForm($form, $form_state);
  }
}