FormAjaxException.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Drupal\Core\Form;
  3. /**
  4. * Custom exception to break out of AJAX form processing.
  5. */
  6. class FormAjaxException extends \Exception {
  7. /**
  8. * The form definition.
  9. *
  10. * @var array
  11. */
  12. protected $form;
  13. /**
  14. * The form state.
  15. *
  16. * @var \Drupal\Core\Form\FormStateInterface
  17. */
  18. protected $formState;
  19. /**
  20. * Constructs a FormAjaxException object.
  21. *
  22. * @param array $form
  23. * The form definition.
  24. * @param \Drupal\Core\Form\FormStateInterface $form_state
  25. * The form state.
  26. * @param string $message
  27. * (optional) The exception message.
  28. * @param int $code
  29. * (optional) A user defined exception code.
  30. * @param \Exception $previous
  31. * (optional) The previous exception for nested exceptions.
  32. */
  33. public function __construct(array $form, FormStateInterface $form_state, $message = "", $code = 0, \Exception $previous = NULL) {
  34. parent::__construct($message, $code, $previous);
  35. $this->form = $form;
  36. $this->formState = $form_state;
  37. }
  38. /**
  39. * Gets the form definition.
  40. *
  41. * @return array
  42. * The form structure.
  43. */
  44. public function getForm() {
  45. return $this->form;
  46. }
  47. /**
  48. * Gets the form state.
  49. *
  50. * @return \Drupal\Core\Form\FormStateInterface
  51. * The current state of the form.
  52. */
  53. public function getFormState() {
  54. return $this->formState;
  55. }
  56. }