Skip to content
Snippets Groups Projects
Commit 7980f41a authored by endless_wander's avatar endless_wander Committed by Owen Bush
Browse files

Issue #3332196 by endless_wander, owenbush: Add ability to choose registration...

Issue #3332196 by endless_wander, owenbush: Add ability to choose registration form redirect from settings
parent c3eeacdb
Branches 8.x-1.x
No related merge requests found
show_capacity: true
insert_redirect_choice: current
insert_redirect_other: ''
use_admin_theme: false
limit: 10
date_format: 'F jS, Y h:iA'
......
......@@ -5,6 +5,12 @@ recurring_events_registration.registrant.config:
show_capacity:
type: boolean
label: 'Whether to display the remaining capacity for an event during registration'
insert_redirect_choice:
type: radios
label: 'Choose where registrant form redirects'
insert_redirect_other:
type: url
label: 'Type custom URL here'
use_admin_theme:
type: boolean
label: 'Use the administration theme when managing registrations'
......
......@@ -514,3 +514,13 @@ function recurring_events_registration_update_8010() {
$config->set('use_admin_theme', FALSE);
$config->save();
}
/**
* Set the default redirection after registration.
*/
function recurring_events_registration_update_8011() {
$config = \Drupal::configFactory()->getEditable('recurring_events_registration.registrant.config');
$config->set('insert_redirect_choice', 'current');
$config->set('insert_redirect_other', '');
$config->save();
}
......@@ -20,6 +20,7 @@ use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\content_moderation\ModerationInformation;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Routing\TrustedRedirectResponse;
use Drupal\recurring_events_registration\NotificationService;
/**
......@@ -546,7 +547,27 @@ class RegistrantForm extends ContentEntityForm {
$this->messenger->addMessage(new FormattableMarkup($this->notificationService->parseTokenizedString($message), []));
}
$form_state->setRedirectUrl(Url::fromRoute('<current>'));
$redirect_choice = $this->config('recurring_events_registration.registrant.config')->get('insert_redirect_choice');
switch ($redirect_choice) {
case 'instance':
$form_state->setRedirect('entity.eventinstance.canonical', ['eventinstance' => $event_instance->id()]);
break;
case 'series':
$form_state->setRedirect('entity.eventseries.canonical', ['eventseries' => $event_series->id()]);
break;
case 'other':
$url = $this->config('recurring_events_registration.registrant.config')->get('insert_redirect_other');
$response = new TrustedRedirectResponse(Url::fromUri($url)->toString());
$form_state->setResponse($response);
break;
default:
$form_state->setRedirectUrl(Url::fromRoute('<current>'));
break;
}
// @todo Remove when https://www.drupal.org/node/3173241 drops.
if ($this->moderationInformation) {
......
......@@ -111,6 +111,8 @@ class RegistrantSettingsForm extends ConfigFormBase {
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->config('recurring_events_registration.registrant.config')
->set('show_capacity', $form_state->getValue('show_capacity'))
->set('insert_redirect_choice', $form_state->getValue('insert_redirect_choice'))
->set('insert_redirect_other', $form_state->getValue('insert_redirect_other'))
->set('use_admin_theme', $form_state->getValue('use_admin_theme'))
->set('limit', $form_state->getValue('limit'))
->set('date_format', $form_state->getValue('date_format'))
......@@ -172,6 +174,32 @@ class RegistrantSettingsForm extends ConfigFormBase {
'#default_value' => $config->get('show_capacity'),
];
$form['process']['insert_redirect_choice'] = [
'#type' => 'radios',
'#title' => $this->t('Choose where registrant form redirects'),
'#default_value' => $config->get('insert_redirect_choice'),
'#options' => [
'current' => $this->t('Current page where form appears'),
'instance' => $this->t('Event instance page'),
'series' => $this->t('Event series page'),
'other' => $this->t('Custom URL'),
],
];
$form['process']['insert_redirect_other'] = [
'#type' => 'url',
'#title' => $this->t('Type custom URL here'),
'#default_value' => $config->get('insert_redirect_other'),
'#states' => [
'visible' => [
':input[name="insert_redirect_choice"]' => ['value' => 'other'],
],
'required' => [
':input[name="insert_redirect_choice"]' => ['value' => 'other'],
],
],
];
$form['display'] = [
'#type' => 'details',
'#title' => $this->t('Registrant Display'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment