In my module routing I have a custom access callback for a payment page.
It checks if the user:
- is allowed to make the payment (it's their own)
- actually needs to (has it already been paid)
It works fine, but in the latter case, whilst I can give them an explanatory warning:
\Drupal::messenger()->addWarning('Fee already paid or no fee to pay.'); return AccessResult::forbidden();
it'd be nicer to redirect them to a page that's friendlier than:
Access Denied - you are not authorised to access the page.
Drupal / Symfony insists on returning something that implements AccessResult - so I can't return a RedirectResponse. Any suggestions? Moving the checks to buildForm() seems a bad idea.