Allow drupal_alter() on the various Field API declarative hooks
| Project: | Drupal |
| Version: | 7.x-dev |
| Component: | field system |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Attached patch adds the following drupal_alter hooks.
It's a D7 equivalent of quicksketch's #417122: Allow drupal_alter() on Field and Widget Settings for CCK D6.
- hook_fieldable_info_alter()
example: if #460320: Standarized, pluggable entity loading (nodes, users, taxonomy, files, comments) gets in, node-level cache is doable in contrib. The module will then need to change the 'cacheable' property of node fieldable_infos
- hook_field_info_alter()
example: #501404: Field Permissions in Core mentions "selectively enable access control for a field to avoid UI bloat on the access page". That would require field_permissions module to add an 'access_control' setting to all field types.
or : change the default widget, default formatter...
- hook_field_widget_info_alter(), hook_field_formatter_info_alter()
examples:
1) let a 3rd party module 'enrich' a widget or formatter by adding new settings
That's the original reason for quicksketch's similar patch for CCK D6 in #417122: Allow drupal_alter() on Field and Widget Settings : allow fieldfield widget enhancers (JS crop, browse existing files...) to cohabitate.
Also, from #394720-16: Migrate profile module data to field API: "a generic link builder for formatters, similar to the one added in Views 2.2 or 2.3, would be super useful (link to the object, link to a custom path with a pattern...). But we don't want each formatter (for text fields, for number fields, for image fields...) to reimplement this".
2) let a contrib field type reuse an existing widget (e.g optionwidgets)
- hook_field_schema_alter()
No actual use case I can think of right now, but I see no reason not to add this...
This will also require additional alter hooks in the UI to allow form elements for the alter-added settings in the field config screens.
| Attachment | Size | Status | Test result | Operations |
|---|---|---|---|---|
| field_alter.patch | 4.55 KB | Idle | Unable to apply patch field_alter.patch | View details |

#1
er, s/fieldfield/filefield in the OP...
#2
Nice explanation. Nice docs. RTBC.
#3
I do not think we should provide hook_field_schema_alter() because and for the same reason there is no hook_schema_alter(). Too dangerous, not clear what the use cases are.
#4
Barry, are you sure? http://api.drupal.org/api/function/hook_schema_alter
#5
Hm, Barry is probably right.
Quicksketch's patch for CCK D6 has a hook to alter field columns.
- I'm not sure he has actual use cases for it, or if was just for consistency. I'll ask over there.
- CCK D6 had code for on-the-fly db migration, which we chose not to support in D7 (no field_update()). So alter field columns is possibly OK in D6, but more problematic in D7 (would only affect newly created fields, not updating existing ones)
Meanwhile, it's probably best to remove hook_field_schema_alter.
I'll reroll shortly.
#6
Without hook_field_schema_alter(), and with actual sample code for the hooks (illustrating the examples from the OP)
#7
Fixed capitalization typo.
#8
These examples look great. I agree with leaving _schema_alter() to another patch (or out completely).
We don't normally prefix the inline comments on example hook implementations with example though - I think we should just drop that and make them look like regular inline comments. Otherwise RTBC.
#9
Fair enough.
#10
Works for me. We're going to have actual implementations of these hooks in upcoming patches so don't think we need special tests here. RTBC as long as the test bot doesn't knock it back.
#11
This seems reasonable to me. Nice to finally have some Field API hook docs with examples. :)
There are a couple of minor things with the docs, such as "informations" and the summary should be in third-person, but I can clean those up prior to commit. However, I'm currently on a "commit freeze" until some folks on IRC do their magic. Marking for later.
#12
Grrr testing bot. Uploading patch again.
#13
There we go! Committed to HEAD!
#14
No
HOOK_widget_settings_alter()and
HOOK_field_settings_alter()for D7?
I don't know CCK in D7 so I'm just wondering about this. Because these are in quicksketch's #417122: Allow drupal_alter() on Field and Widget Settings patch and I'm using them now.
#15
@mattyoung: hook_field_settings() are hook_widget_settings() gone in D7, the list of settings and default values is provided in hook_field_info() and hook_field_widget_info(), and thus can be altered through the alter hooks that were committed.
#16
Automatically closed -- issue fixed for 2 weeks with no activity.