My Duration field uses duration_field('load', ...) to convert an ISO duration string to a Duration object, and store that object in $item['duration'] (in addition to the other two properties that are already loaded from the database). That works pretty nicely for node views, but doesn't work when being displayed inside a Views listing, because content_handler_field() does not invoke hook_field('load', ...), which causes Duration fields to stay empty in a view because they rely on the Duration object being added to the item.
sevi has identified this issue and posted a patch that causes my field to load the object during $op='sanitize' (which is called even from a view), but I'm unsure if that is the appropriate solution. After all, I thought $op='load' ensures that I can rely on the added fields to actually exist, and if that's not the case then I'd be questioning the purpose of $op='load' on the whole.
Here's a simple patch to call $op='load' from content_handler_field->render(), as a proposal how CCK might be able to fix it. Maybe you want to enhance this by reusing the cache (as is done in content_load() which we can't use there as it takes just a node as parameter), but I wanted to see if you even view this as an actual problem, or if I should just get lost and use $op='sanitize' as a hackish workaround instead.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | cck-invoke-load-for-views.diff | 1.18 KB | jpetso |
Comments
Comment #1
karens commentedNo patch.
Comment #2
jpetso commentedEr, oops? Sorry, forgot to attach.
Comment #3
karens commentedMy concern about this is that I don't know that we want to do hook_field() on every item in a view. We don't do node_load() on them for a reason. There could be dozens or hundreds of affected items, which could make a real performance problem. Most fields will never want or need this.
I think a better way of going about this would be for your module to create its own Views handlers to do whatever wonderfulness you need. Then use the 'views data' option in your field settings to swap your custom handler in instead of the normal CCK handlers. See the Nodereference and Date modules for a couple examples of modules that use 'views data' to add their own Views handling to the default handling provided by the Content module.
If you think I'm wrong and you think there's some compelling reason to have that overhead on every item in every field, you can reopen and make your case :)
Comment #4
jpetso commentedNothing wrong, that sounds just fine :)
I even did those custom 'views data' handlers, I just didn't think meta enough to get outside of the hook_field() box. Thanks for the review and suggestion!