public function CustomServicesDeleteForm::submitForm in Shorten URLs 8
Same name and namespace in other branches
- 8.2 modules/shorten_cs/src/Form/CustomServicesDeleteForm.php \Drupal\shorten_cs\Form\CustomServicesDeleteForm::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 FormInterface::submitForm
File
- modules/
shorten_cs/ src/ Form/ CustomServicesDeleteForm.php, line 83
Class
- CustomServicesDeleteForm
- Settings form.
Namespace
Drupal\shorten_cs\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$service = $form_state
->getValues()['service'];
$config_factory = \Drupal::configFactory();
if ($service == \Drupal::config('shorten.settings')
->get('shorten_service')) {
if (\Drupal::config('shorten.settings')
->get('shorten_service_backup')) {
$config_factory
->getEditable('shorten.settings')
->set('shorten_service', 'TinyURL')
->save();
}
else {
$config_factory
->getEditable('shorten.settings')
->set('shorten_service', 'is.gd')
->save();
}
drupal_set_message(t('The default URL shortening service was deleted, so it has been reset to @service.', array(
'@service' => \Drupal::config('shorten.settings')
->get('shorten_service'),
)));
}
if ($service == \Drupal::config('shorten.settings')
->get('shorten_service_backup')) {
if (\Drupal::config('shorten.settings')
->get('shorten_service')) {
$config_factory
->getEditable('shorten.settings')
->set('shorten_service_backup', 'is.gd')
->save();
}
else {
$config_factory
->getEditable('shorten.settings')
->set('shorten_service_backup', 'TinyURL')
->save();
}
drupal_set_message(t('The backup URL shortening service was deleted, so it has been reset to @service.', array(
'@service' => \Drupal::config('shorten.settings')
->get('shorten_service_backup'),
)));
}
db_delete('shorten_cs')
->condition('name', $service)
->execute();
drupal_set_message(t('The service %service has been deleted.', array(
'%service' => $service,
)));
$form_state
->setRedirect('shorten_cs.theme_shorten_cs_admin');
return;
}