0

I am trying to open either the simplenews subsription block or the corresponding form in a modal. I tried with both the form using the formBuilder service or the exising plugin-block and in both cases I can successfully load and display the subsription block/form in the modal. The problem now is, that when I enter an email address and try to subscribe i.e. submit the form it doesn't work. I am redirected to my controller ajax callback.

How can I make the form/block work correctly inside the modal?

1
  • can you add more info like code regarding how you load the form/block that seems working fine however on submission of form in modal not working , may be by analysing code , others can suggest solution of it Commented Jun 2 at 8:50

1 Answer 1

0

The standard approach is old-style Drupal with a form alter hook adding a submit handler where you redirect to a different Drupal route:

$form_state->setRedirect('<front>');

You'll find plenty of examples by searching this site or others.

However, looking at the module's code, the form is OOP style, so it would be a better approach to extend the contrib form class and override the submit method:

public function submitExtra(array $form, FormStateInterface $form_state)  {
  parent::submitExtra($form, $form_state);
  $form_state->setRedirect('<front>');
}

Then you can override other things, too, to make a perfect form to place it in modals, like the variants you've already tried for pages and blocks.

1
  • I tried as you suggested: I extended the contrib form class and overwrote the submitExtra method as above. I used hook_pentity_type_build() to add my extended form class. This works. But the result is still the same. When submitting the form in the modal I get redirected to my controller ajax callback.
    – Mike
    Commented May 24 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.