Allow drupal_alter() on the various Field API declarative hooks

yched - June 25, 2009 - 23:37
Project:Drupal
Version:7.x-dev
Component:field system
Category:task
Priority:normal
Assigned:Unassigned
Status:closed
Description

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.

AttachmentSize
field_alter.patch4.55 KB
Testbed results
field_alter.patchre-testing

#1

yched - June 25, 2009 - 23:53
Status:active» needs review

er, s/fieldfield/filefield in the OP...

#2

moshe weitzman - June 26, 2009 - 05:27
Status:needs review» reviewed & tested by the community

Nice explanation. Nice docs. RTBC.

#3

bjaspan - June 26, 2009 - 17:00
Status:reviewed & tested by the community» needs review

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

catch - June 26, 2009 - 17:05

#5

yched - June 26, 2009 - 17:32

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

yched - June 26, 2009 - 17:55

Without hook_field_schema_alter(), and with actual sample code for the hooks (illustrating the examples from the OP)

AttachmentSize
field_alter-502522-5.patch 4.19 KB
Testbed results
field_alter-502522-5.patchre-testing

#7

yched - June 26, 2009 - 17:57

Fixed capitalization typo.

AttachmentSize
field_alter-502522-6.patch 4.19 KB
Testbed results
field_alter-502522-6.patchre-testing

#8

catch - June 26, 2009 - 18:28

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

yched - June 26, 2009 - 18:34

Fair enough.

AttachmentSize
field_alter-502522-9.patch 4.13 KB
Testbed results
field_alter-502522-9.patchre-testing

#10

catch - June 26, 2009 - 18:49
Status:needs review» reviewed & tested by the community

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

webchick - June 27, 2009 - 02:45

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

webchick - June 29, 2009 - 23:51

Grrr testing bot. Uploading patch again.

AttachmentSize
field_alter-502522-9.patch 4.13 KB
Testbed results
field_alter-502522-9.patchpassedPassed: 11789 passes, 0 fails, 0 exceptions Detailed results

#13

webchick - June 30, 2009 - 03:12
Status:reviewed & tested by the community» fixed

There we go! Committed to HEAD!

#14

mattyoung - July 9, 2009 - 02:22

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

yched - July 10, 2009 - 21:17

@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

System Message - July 24, 2009 - 21:20
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.