Skip to content

Commit

Permalink
Allow profile parameter for token-based forms
Browse files Browse the repository at this point in the history
  • Loading branch information
jensschuppe committed Feb 20, 2024
1 parent dd050ef commit 4fca028
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
20 changes: 16 additions & 4 deletions modules/civiremote_event/civiremote_event.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@ civiremote_event.register_form:
context:
type: string
civiremote_event.register_token_form:
path: '/civiremote/event/register/{event_token}'
path: '/civiremote/event/register/{event_token}/{profile}'
defaults:
_controller: '\Drupal\civiremote_event\Controller\RegisterFormController::formWithToken'
_title_callback: '\Drupal\civiremote_event\Controller\RegisterFormController::titleWithToken'
context: create
# The profile is optional.
profile: null
context: 'create'
requirements:
_custom_access: '\Drupal\civiremote_event\Controller\RegisterFormController::accessWithToken'
options:
no_cache: TRUE
parameters:
event_token:
type: civiremote_event_token
profile:
type: string
context:
type: string

Expand Down Expand Up @@ -70,10 +74,12 @@ civiremote_event.registration_cancel_token_form:
context: string

civiremote_event.registration_update_form:
path: '/civiremote/event/{event}/update'
path: '/civiremote/event/{event}/update/{profile}'
defaults:
_controller: '\Drupal\civiremote_event\Controller\RegisterFormController::form'
_title_callback: '\Drupal\civiremote_event\Controller\RegisterFormController::title'
# The profile is optional.
profile: null
context: 'update'
requirements:
_custom_access: '\Drupal\civiremote_event\Controller\RegisterFormController::access'
Expand All @@ -82,13 +88,17 @@ civiremote_event.registration_update_form:
parameters:
event:
type: civiremote_event
profile:
type: string
context:
type: string
civiremote_event.registration_update_token_form:
path: '/civiremote/event/update/{event_token}'
path: '/civiremote/event/update/{event_token}/{profile}'
defaults:
_controller: '\Drupal\civiremote_event\Controller\RegisterFormController::formWithToken'
_title_callback: '\Drupal\civiremote_event\Controller\RegisterFormController::titleWithToken'
# The profile is optional.
profile: null
context: 'update'
requirements:
_custom_access: '\Drupal\civiremote_event\Controller\RegisterFormController::accessWithToken'
Expand All @@ -97,6 +107,8 @@ civiremote_event.registration_update_token_form:
parameters:
event_token:
type: civiremote_event_token
profile:
type: string
context:
type: string

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,21 @@ public static function create(ContainerInterface $container) {
*
* @see \Drupal\civiremote_event\Routing\EventTokenConverter
*/
public function formWithToken(RouteMatch $route_match, string $context, stdClass $event_token) {
public function formWithToken(RouteMatch $route_match, string $context, stdClass $event_token, string $profile = NULL) {
return self::form(
$route_match,
$context,
$event_token,
$route_match->getRawParameter('event_token')
$route_match->getRawParameter('event_token'),
$profile
);
}

public function form(RouteMatch $route_match, string $context, stdClass $event, string $raw_event_token = NULL, string $profile = NULL) {
// Retrieve the form definition.
try {
$form = $this->cmrf->getForm(
(isset($event) ? $event->id : NULL),
$event->id,
$profile,
$raw_event_token,
$context
Expand All @@ -116,11 +117,12 @@ public function form(RouteMatch $route_match, string $context, stdClass $event,
}
}
}
catch (Exception $exception) {
catch (\Exception $exception) {
Drupal::messenger()->addMessage(
$exception->getMessage(),
MessengerInterface::TYPE_ERROR
);
return [];
}

// Retrieve implementation for building the form.
Expand Down

0 comments on commit 4fca028

Please sign in to comment.