2

I am writing a module that adds fields to Simplenews forms, including a custom submit handler. This is working fine on my test site, but when i migrate to my production site, I get the following error:

Recoverable fatal error: Argument 2 passed to simple_conreg_simplenews_form_submit() must be an instance of FormStateInterface, instance of Drupal\\Core\\Form\\FormState given in /var/www/drupal/sites8/all/modules/simple_conreg/simple_conreg.module on line 193

My handler is defined as:

function simple_conreg_simplenews_form_submit ($form, FormStateInterface $form_state)

I can get it to work on my production site by changing to:

function simple_conreg_simplenews_form_submit ($form, $form_state)

However, it would be nice to have type checking enforced.

Any idea why this is happening when the same definition works on the test site?

  • 4
    Have you actually aliased FormStateInterface in that context? What does the use statement look like? Drupal\Core\Form\FormState is an instance of Drupal\Core\Form\FormStateInterface so assuming you're referencing the right classes/interfaces in the right namespaces, you won't have a problem – Clive Jun 4 '16 at 11:20
  • Thanks, Clive. I should have thought to check the use statement! I had no use statement for FormStateInterface. My hook_form_alter had the full path to FormStateInterface, so perhaps on the test site that was enough for the submit function to find it. I've added a use statement, and everything seems to be good now. – James Shields Jun 4 '16 at 12:58
  • @JamesShields you should work with an IDE. It will notify you of such mistakes. – Eyal Jun 6 '16 at 21:35
  • Good point. Last time I tried to set one up, it didn't go well, so I've just been using a text editor. I should try again. – James Shields Jun 6 '16 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.