You are here

public function VimeoSettingsForm::submitForm in Vimeo Video Uploader 8

Same name and namespace in other branches
  1. 8.4 src/Form/VimeoSettingsForm.php \Drupal\vimeo_video_uploader\Form\VimeoSettingsForm::submitForm()

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/VimeoSettingsForm.php, line 100
Contains \Drupal\vimeo_video_uploader\Form\SettingsForm.

Class

VimeoSettingsForm
Provide configuration form for user to provide vimeo API information for a

Namespace

Drupal\vimeo_video_uploader\Form

Code

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

  // Set configuration.
  $config = self::config('vimeo_video_uploader.settings');
  $form_state_values = $form_state
    ->getValues();
  $message = "Saved the Vimeo configuration.";
  $old_content_type_select = $config
    ->get('values.content_type_select');
  if ($old_content_type_select !== $form_state_values['values']['content_type_select']) {

    //delete some things
    $entityManager = \Drupal::service('entity.manager');
    $fields = $entityManager
      ->getFieldDefinitions('node', $old_content_type_select);
    if (isset($fields['field_vimeo_file_browse']) && ($field = $fields['field_vimeo_file_browse'])) {
      $field
        ->delete();
    }
    if (isset($fields['field_embeddedvideo']) && ($field1 = $fields['field_embeddedvideo'])) {
      $field1
        ->delete();
    }
    $this
      ->AddContentTypeField($form_state_values['values']['content_type_select']);
    $message = "Created 'Browse video for uploading to Vimeo' field in '" . strtoupper($form_state_values['values']['content_type_select']) . "' Content type.";
  }
  $config
    ->set('values.client_id', $form_state_values['values']['client_id'])
    ->set('values.client_secret', $form_state_values['values']['client_secret'])
    ->set('values.access_token', $form_state_values['values']['access_token'])
    ->set('values.content_type_select', $form_state_values['values']['content_type_select']);
  $config
    ->save();
  drupal_set_message($message, 'status');
}