Raise 404 if quick form does not exist

This commit is contained in:
Paul Weidner 2023-08-11 08:58:25 -07:00 committed by Michael Stenta
parent f89e155f0a
commit 4fcc647115
2 changed files with 10 additions and 3 deletions

View File

@ -11,6 +11,7 @@ use Drupal\Core\Session\AccountInterface;
use Drupal\farm_quick\Plugin\QuickForm\ConfigurableQuickFormInterface;
use Drupal\farm_quick\QuickFormInstanceManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
/**
* Form that renders quick form configuration forms.
@ -87,10 +88,10 @@ class ConfigureQuickForm extends EntityForm {
$quick_form = $this->getQuickFormInstance($quick_form);
}
// Deny access if no quick form exists. This is the case with a quick form
// Raise 404 if no quick form exists. This is the case with a quick form
// ID that is not a valid quick form plugin ID.
if ($quick_form === NULL) {
return AccessResult::forbidden();
throw new ResourceNotFoundException();
}
// Deny access if the quick form plugin is not configurable.

View File

@ -8,6 +8,7 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\farm_quick\QuickFormInstanceManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
/**
* Form that renders quick forms.
@ -93,7 +94,12 @@ class QuickForm extends FormBase implements BaseFormIdInterface {
* The access result.
*/
public function access(AccountInterface $account, string $quick_form) {
return $this->quickFormInstanceManager->createInstance($quick_form)->getPlugin()->access($account);
if ($quick_form = $this->quickFormInstanceManager->createInstance($quick_form)) {
return $quick_form->getPlugin()->access($account);
}
// Raise 404 if the quick form does not exist.
throw new ResourceNotFoundException();
}
/**