You are here

public function CustomServicesEditForm::submitForm in Shorten URLs 8.2

Same name and namespace in other branches
  1. 8 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 122

Class

CustomServicesEditForm
Settings form.

Namespace

Drupal\shorten_cs\Form

Code

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