You are here

public function SharethisConfigurationForm::submitForm in ShareThis 8.2

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/SharethisConfigurationForm.php, line 390

Class

SharethisConfigurationForm
Provides a settings for sharethis module.

Namespace

Drupal\sharethis\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $entity_types = '';
  $values = $form_state
    ->getValues();
  $input_values = $form_state
    ->getUserInput();
  $config = $this
    ->config('sharethis.settings');

  // If the location change to/from 'content', clear the Field Info cache.
  $current_location = $config
    ->get('location');
  $new_location = $values['location'];
  if (($current_location == 'content' || $new_location == 'content') && $current_location != $new_location) {
    $this->entityFieldManager
      ->clearCachedFieldDefinitions();
  }
  $entity_info = $this->entityTypeBundleInfo
    ->getAllBundleInfo('node');
  if (isset($entity_info['node'])) {
    $entity_types = $entity_info['node'];
  }
  $config
    ->set('button_option', $values['button_option'])
    ->set('service_option', $values['service_option'])
    ->set('option_extras', $values['option_extras'])
    ->set('callesi', $values['callesi'])
    ->set('location', $values['location'])
    ->set('node_types', $input_values['node_types'])
    ->set('comments', $values['comments'])
    ->set('weight', $values['weight'])
    ->set('publisherID', $values['publisherID'])
    ->set('late_load', $values['late_load'])
    ->set('twitter_suffix', $values['twitter_suffix'])
    ->set('twitter_handle', $values['twitter_handle'])
    ->set('twitter_recommends', $values['twitter_recommends'])
    ->set('option_onhover', $values['option_onhover'])
    ->set('option_neworzero', $values['option_neworzero'])
    ->set('option_shorten', $values['option_shorten'])
    ->set('cns.donotcopy', $input_values['cns']['donotcopy'])
    ->set('cns.hashaddress', $input_values['cns']['hashaddress'])
    ->save();
  if (is_array($entity_types)) {
    foreach ($entity_types as $key => $entity_type) {
      $config
        ->set('sharethisnodes.' . $key, $values[$key . '_options'])
        ->save();
    }
  }
  parent::submitForm($form, $form_state);
}