You are here

public function CustomServicesEditForm::submitForm in Shorten URLs 8

Same name and namespace in other branches
  1. 8.2 modules/shorten_cs/src/Form/CustomServicesEditForm.php \Drupal\shorten_cs\Form\CustomServicesEditForm::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

modules/shorten_cs/src/Form/CustomServicesEditForm.php, line 61

Class

CustomServicesEditForm
Settings form.

Namespace

Drupal\shorten_cs\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $v = $form_state
    ->getValues();
  $config_factory = \Drupal::configFactory();
  $record = array();
  foreach (array(
    'name',
    'url',
    'type',
    'tag',
    'sid',
  ) as $key) {
    $record[$key] = $v[$key];
  }
  \Drupal::database()
    ->merge('shorten_cs')
    ->fields($record)
    ->key([
    'sid',
  ])
    ->execute();
  if ($v['old_name'] == \Drupal::config('shorten.settings')
    ->get('shorten_service', 'is.gd')) {
    $config_factory
      ->getEditable('shorten.settings')
      ->set('shorten_service', $v['name']);
  }
  if ($v['old_name'] == \Drupal::config('shorten.settings')
    ->get('shorten_service_backup', 'TinyURL')) {
    $config_factory
      ->getEditable('shorten.settings')
      ->set('shorten_service', $v['name']);
  }
  drupal_set_message(t('The changes to service %service have been saved.', array(
    '%service' => $record['name'],
  )));
  $form_state
    ->setRedirect('shorten_cs.theme_shorten_cs_admin');
  return;
}