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.
Problem/Motivation
There are various form_alters in the token.module to add tree links or other processing for various forms. Some of these alters have been carried over from Drupal 7 and those form id's may have changed. We should either fix them or remove them if they are not valid anymore.
List of form alters
- token_form_alter - Adds a submit handler to forms which could affect the tokens available on the site. It affects forms 'profile_field_form', 'profile_field_delete', 'system_add_date_format_type_form', 'system_delete_date_format_type_form'.
- token_form_block_form_alter - Adds a label and validation for tokens.
- token_field_widget_form_alter - Process tokens in field descriptions.
- token_form_field_config_edit_form_alter - Adds tree link to field config form.
- token_form_system_actions_configure_alter - Alters the configure action form to add token context validation and adds the token tree for a better token UI and selection.
- token_form_user_admin_settings_alter - Alters the user e-mail fields to add token context validation and adds the token tree for a better token UI and selection.
Proposed resolution
Determine if the alters are necessary, fix or remove them.
Remaining tasks
User interface changes
None
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#17 | fix_or_remove_unused_form_alter-2641226-17.patch | 7.21 KB | hussainweb |
| |||
#17 | interdiff-15-17.txt | 506 bytes | hussainweb |
Comments
Comment #2
hussainwebThe patch removes form alters for:
It fixes form id's for others. I also verified each form change manually.
Comment #3
hussainwebFor those reviewing, this alter is not necessary anymore. I verified that Drupal core replaces tokens even without this function. In fact, due to a check on is_string, it never actually does anything.
Comment #4
BerdirConfirmed, token replacement for field descriptions is done in core.
However, I did find a small bug in a form alter function, lets fix this here too. token_form_user_admin_settings_alter() has the original string that it replaces (which makes sense, so it works for translated strings). But that string changed in core, so that doesn't work anymore.
Also tagging with needs tests. It should be relatively easy to write some very basic test coverage, visit that form and ensure that the link/text shows up.
The user picture option is gone from the UI, that's just a field now that exists or doesn't. So I think we can remove this.
Thinking about this, date formats are config entities now. And they might also be imported through config sync. Lets convert this to hook_date_format_insert()/delete() hooks.
I think nothing will be left here anymore then.
Comment #5
hussainwebJust doing a reroll so that we have something to refer to later.
Comment #6
hussainwebBack to needs work for comments in #4.
There are already tests for this in TokenFieldUiTest. Do you want to test each and every form we alter?
Comment #7
BerdirI think basic test coverage for those would be good. As the example with the user form shows, only a tiny change in the translatable string can break our functionality.
I'm OK if we don't add test coverage for e.g. the actions. And instead of working on tests for the date tokens and cache clearing in token.module, we could just improve the referenced core patch and write tests there and push it for 8.1. That's something we should do anyway I think. Try to move more tokens and features from this module into core.
Comment #8
hussainwebAddressing comments in #4. Tests pending.
Comment #9
Berdirneeds work for some basic tests, paragraph #2 from comment #4 about the user form is also not addressed yet.
Comment #10
hussainwebPoint 2 from #4 is done:
This is what you had in mind, right?
Comment #11
BerdirThat part is fine, I meant paragraph 2, not point 2:
Comment #12
hussainwebOh, I changed that as well. It seems I lost it in patches. I will add that too. Thanks for reminding. :)
Comment #13
hussainwebJust FYI, I found a related issue in core here. I filed #2642674: Tokens not replaced in file/widget field descriptions.
Comment #14
hussainwebComment #15
hussainwebAdding a few tests and fixing the comment in #11.
Comment #17
hussainwebFixing...
Comment #18
BerdirNice work, committed.