public function ShortenShortenForm::submitForm in Shorten URLs 8.2
Same name and namespace in other branches
- 8 src/Form/ShortenShortenForm.php \Drupal\shorten\Form\ShortenShortenForm::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
- src/
Form/ ShortenShortenForm.php, line 103
Class
- ShortenShortenForm
- Builds a form which allows shortening of a URL via the UI.
Namespace
Drupal\shorten\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$storage =& $form_state
->getStorage();
$service = '';
if (isset($values['service'])) {
$service = $values['service'];
}
$shortened = shorten_url($values['url_' . $storage['step']], $service);
if (isset($values['service'])) {
$_SESSION['shorten_service'] = $values['service'];
}
$this
->messenger()
->addStatus($this
->t('%original was shortened to %shortened', [
'%original' => $values['url_' . $storage['step']],
'%shortened' => $shortened,
]));
$form_state
->setRebuild();
if (empty($storage)) {
$storage = [];
}
$storage['short_url'] = $shortened;
$storage['service'] = empty($values['service']) ? '' : $values['service'];
if (isset($storage['step'])) {
$storage['step']++;
}
else {
$storage['step'] = 0;
}
$form_state
->setStorage($storage);
}