Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
forms system
Priority:
Normal
Category:
Task
Reporter:
Created:
25 Jul 2008 at 15:15 UTC
Updated:
14 Mar 2010 at 23:00 UTC
Jump to comment: Most recent, Most recent file
This has been available since Drupal 6, but on a quick grep, I can't seem to find an example in core. Either way we still have some large hook_form_alter() implementations which could benefit from it - i.e. http://api.drupal.org/api/function/comment_form_alter/7 and probably many others. There's was some conversion in #79551: Multiply form alter but the conversion parts in that patch never got committed after FAPI 3 added the feature.
Incidentally, there's also a '@todo, remove in Drupal 7' in the section of drupal_prepare_form() which deals with this.
One last thing, I can't seem to find any documentation about hook_form_alter_$form_id() anywhere.
| Comment | File | Size | Author |
|---|---|---|---|
| #26 | default.profile.patch | 1.01 KB | seutje |
| #25 | default.profile.patch | 1.02 KB | seutje |
| #25 | expert.profile.patch | 1020 bytes | seutje |
| #14 | openid_form_id.patch | 542 bytes | dawehner |
| #12 | openid_form_id.patch | 539 bytes | dawehner |
Comments
Comment #1
catchComment #2
marcp commentedSee #331832: Document hook_form_FORM_ID_alter() for documentation.
Comment #3
Anonymous (not verified) commentedi'll take a look at this. as a consequence of reviving #332003: cut the fat out of _drupal_bootstrap_full, i noticed that drupal_prepare_form --> drupal_alter('form', $data, $form_id) --> loads lots of modules that don't care most of the time, because they are interested in 1 or 2 forms only.
another bit of drupal that has been loading too much code too much of the time, but nobody noticed because we load all modules at bootstrap anyway, so what's some more function calls between friends? its the $op code again, but in a different bucket.
Comment #4
Anonymous (not verified) commentedpatch attached.
not as great an improvement as i'd hoped re. loading less code, as many form_alter hooks interrogate $form rather than look at a specific $form_id.
Comment #5
catchAll the changes look good, tests pass. RTBC.
Comment #6
webchickJustin, could you share your before/after number comparisons? You said it was "not as great as you'd hoped" but does it buy us something? If so, how much?
Comment #7
dawehneri reviewed the code and saw $form_id = NULL
is there a reasion why to do it, the argument is not there always, there was even a php error when using openid module
there was also some spaces left
PS: whats about left spaces in all drupal core?
Comment #8
dawehnersometimes i don't understand it, the patch was there
Comment #9
Anonymous (not verified) commented@dereine: thanks for updating the patch.
@webchick: i didn't do any performance comparisons, but i don't think that's necessary - IMHO just moving to smaller, simpler functions is enough of a gain, as with the $op patches. its also unlikely to show any improvement, memory or speed wise, until we make drupal load less code in via #345118: Performance: Split .module files by moving hooks and #340723: Make modules and installation profiles only require .info.yml files. i won't be getting back to those until i've successfully settled in to Philadelphia in a few weeks, but they are on my TODO list.
Comment #10
Anonymous (not verified) commentedoh, the testbot likes it, so RTBC.
Comment #11
webchickOk, fair enough. :)
Committed to HEAD. Thanks!
Comment #12
dawehner_openid_user_login_form_alter uses $form_id to distinc between the width of the field.
so there has to be set the $form_id, or it does not work
Comment #13
dave reidThe code that uses $form_id in _openid_user_login_form_alter is:
What might be a better method is:
Since on user_login, the size is 60, and on user_login_block, the size is 15.
Comment #14
dawehnerwow there is so much wisdom in drupal community!
is there needed to write a test for this?
Comment #15
webchickYes, it would be nice to make a couple baseline tests to ensure that the OpenID login works. This is exactly the kind of thing that our testing suite should have found, and will continue not to find until we have test coverage for it.
The fix looks nice and elegant, though. :) But I'm wondering why we need to be -2? Could we make it simple and just use the same width as the user_login form?
Comment #16
dawehneri'm just guessing, its because of the openid icon.
But both lines (normal user name and openidname) should have the same width,
is it possible to figure out who wrote this code?
Comment #17
swentel commentedThe 'Comment settings' is now completely underneath the 'Save content type' submit button. Weird thing is, adding #weight to the fieldset doesn't affect anything ... not sure if it's because of this patch or not though, just mentioning ...
Comment #18
dave reidFollowup with comment settings weight in #364484: Comment settings are below the Save content type button.
Comment #19
BrightLoudNoise commentedI have successfully applied the patch from #14 and have manually tested.
Should we create a separate issue to get this particular patch commited? Or is the intent to wait until tests are also built?
Comment #20
mgiffordI ran the patch and tested it. Worked fine for me. I'd like to apply it before the testing so that the error above can be eliminated:
Mike
Comment #21
mgiffordSorry, changed the overall title. Just wanted to bring attention to this warning:
Notice: Undefined variable: form_id in _openid_user_login_form_alter() (line 117 of /home/dm7/modules/openid/openid.module).
Comment #22
webchickGrumble, mutter...
Yeah, I guess I can commit this. It's bothering me a lot that I'm committing a bug fix without a test to back up that it's fixed. Just means we'll break things again in the future. :( Hope to see you guys at #251245: openid.module needs tests, as eager to help out there and get those committed. ;)
I can't really see a good reason to remove 2 from the size of the parent field, so I removed this from the patch and committed it. If someone finds an instance where this is break (I didn't in clicking through in Garland), let's fix it in CSS, not in the form definition.
Comment #24
seutje commentedsome functions now take &$form_state instead of $form_state due to patches in this issue, yet I can't find anywhere why this was changed and the functions in question don't change anything in $form_state, so is there any reason to pass it as reference?
-> #503892: hook_form_alter() and hook_form_FORM_ID_alter() take $form_state as reference
also extracted the node_type form for upload to upload_form_node_type_form_alter -> http://drupal.org/node/503780#comment-1748732
Comment #25
seutje commentednot sure if this also applies to profiles, but I don't rly see any reason why not
Comment #26
seutje commentedforgot to remove the $form_id from the default profile
Comment #27
effulgentsia commenteddefault.profile is now standard.profile. Because of this, I considered setting this to "needs work", but given the age of the issue, I'm setting it to fixed as per #22. Please open new issues for specific changes, such as
standard_form_alter()tostandard_form_install_configure_form_alter(), or re-open this issue if you're including a full sweep of many places.