Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Form arrays should never be altered after a form array is returned by drupal_get_form(). hook_forms+hook_form_[$form_id]_alter is made for this. As such I've moved some new user_block_view code around to be saner. This code was introduced by #1772584: Get rid of user_login_block() & user_login() in favour of user_login_form().
Hopefully this makes sense to everyone.
Eclipse
Comment | File | Size | Author |
---|---|---|---|
#10 | drupal8.user-login-block-form.10.patch | 2.69 KB | sun |
#7 | 1826452-do-not-test.patch | 2.11 KB | EclipseGc |
#5 | 1826452.patch | 2.1 KB | EclipseGc |
#1 | 1826452.patch | 2.17 KB | EclipseGc |
Comments
Comment #1
EclipseGc CreditAttribution: EclipseGc commentedHere's the patch!
Comment #2
EclipseGc CreditAttribution: EclipseGc commentedneed testing
Comment #3
Damien Tournoud CreditAttribution: Damien Tournoud commentedThat looks slightly redundant.
Comment #4
EclipseGc CreditAttribution: EclipseGc commentedI was asked to explain a bit more why this was needed, so here goes:
When you have two forms that are virtually identical, except slightly different, hook_forms becomes really useful. Historically if you look at node_forms() this was how individual form elements could easily be added per form_id. User module provides the user_login_form form, but then the block wants to use ALMOST that form with a few alterations. As such, instead of providing a completely different form, or doing something like altering the form elements after drupal_get_form is called (which cannot be undone or altered out no matter how hard you try) implementing hook_forms simply gave us an alias for the form we cared about, where by we could now apply typical form_alteration methodology.
Hopefully this makes sense of the patch.
Comment #5
EclipseGc CreditAttribution: EclipseGc commentedChanges from #3
Comment #6
amateescu CreditAttribution: amateescu commentedImplements hook_form_FORM_ID_alter() :/
Comment #7
EclipseGc CreditAttribution: EclipseGc commentedIf 5 passes this will pass, just changed the docblock from 6.
Comment #8
sunThe downside of hook_form_alter() is that it runs only after retrieval of the form definition and is not cached with it.
So why don't we take the hook_forms() approach suggested here and skip the alter? I.e.:
The reason for still using hook_forms() with this would be to automatically leverage Form API's built-in base form ID mechanisms (invoking hook_form_alter() additionally for the base form ID, likewise for #validate, #submit, and #theme).
Comment #9
andypostAny reason to make another form? Original issue was about removal of 2 forms #1772584: Get rid of user_login_block() & user_login() in favour of user_login_form()
Originally @catch suggested this approach with customization in block, suppose it needs his review
Comment #10
sunHere's what I suggested in #8, but skipping the hook_forms() workaround.
Comment #11
EclipseGc CreditAttribution: EclipseGc commented@sun,
This feels more arcane than what I did to begin with and that felt pretty freaking arcane. Forgive me for not understanding all the dynamics at play here, but is the caching of this sort of alteration a consideration? especially since this is anonymous user facing only?
I guess I'm fine with the approach, but it does seem very arcane, I've never seen this done anywhere (not to say it isn't just that I've not seen it). Any core maintainer want to weigh in on this?
Eclipse
Comment #12
effulgentsia CreditAttribution: effulgentsia commentedHuh? We cache not the retrieved form, but the prepared form, so alters are included.
I like #5 except for user.module altering its own form, and I prefer alters to be limited to a module altering something of another module. Ideally, we should change hook_forms() to decouple 'base form id' from 'callback', but I don't think it's worth making that part of the scope of this issue. Can we go with #5 for this issue, and have a follow up for improving hook_forms()?
Well, the original issue was about removing it as 2 totally disconnected forms: this issue is about making a form that's a customization of a base form, which seems the correct approach to me. I don't see comments in that issue which are incompatible with this issue, but please point one out if I missed something.
Comment #13
andypostSo #7 or #10 approach is a better?
Comment #14
jibranPing!
Comment #15
jhedstromComment #16
drupaldrop CreditAttribution: drupaldrop commentedDuring rerolling this patch , the functions mentioned in the patch doesnot exist in the current 8.0.x branch . Hence this patch cannot be rerolled i guess .
Any thoughts?, otherwise we can close this issue.
I am removing the tag need reroll and changing status needs work to needs review.
Comment #17
jhedstromIndeed--if the underlying logic has not been fixed already, this issue needs a summary update.
Comment #25
pameeela CreditAttribution: pameeela commentedThanks everyone who contributed to this issue.
Given that the latest comments were seeking additional information and none has been provided, I am marking this issue Closed (cannot reproduce).
If anyone believes this issue should not be closed, please provide specific steps to reproduce when reopening it.