When the modal login block content is fetched from the cache, the form is not generated again. So it does not run through hook_form_alter().

Therefore, the additional ajax parameters, added to $form['#prefix'], $form['#suffix'] and $form['actions'] in bootstrap_login_modal_form_user_login_alter() and bootstrap_login_modal_form_user_register_form_alter() will not get called when the form is retrieved from the cache.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

leon.nk created an issue. See original summary.

Leon Kessler’s picture

I can't think of a better way to do this than setting the block to not cache.

We might be able to move everything into theme_bootstrap_login_modal_output(), so that it's all stored in the cache.
However, the $form['actions']['submit']['#ajax'] would be difficult, and would have to mimic how Drupal core adds this to the page.

2pha’s picture

This issue is confusing me.
Are you trying to add stuff in `bootstrap_login_modal_form_user_login_alter()` depending on the page but it getting a cached version?

Just changing it to not cache is not an answer as the module seems to be working fine as is for many sites.

Leon Kessler’s picture

Nope not adding anything to bootstrap_login_modal_form_user_login_alter().

The problem is the necessary changes to the form to ensure it runs with ajax are added there, are only run when the cache is cold.

Steps to reproduce:
Visit a new page with the login modal, the form should submit via ajax.
Refresh the page, now re-launch the modal. The form will now submit back to the page, and not via ajax. You can see this by submitting the form with an error, it will not be displayed on the current modal as it should do.

2pha’s picture

WOW, you are right, how did no one report this before. I suppose they thought it must have just been meant to work that way. Or they didn't test properly, same as me.

  • 2pha committed cb92f87 on
    Issue #2662460 by leon.nk: Caching prevents the modal from using ajax
    
2pha’s picture

Status: Active » Needs review

Had a look at how the user module handles it's login block and it uses DRUPAL_NO_CACHE, so we'll just go with that then.
Committed DRUPAL_NO_CACHE

Status: Needs review » Needs work

The last submitted patch, 2: caching_prevents_the-2662460-2.patch, failed testing.

2pha’s picture

Status: Needs work » Needs review
2pha’s picture

Status: Needs review » Closed (fixed)