If I have a custom field and I need to alter it's content on load(not display) I have three options I can use within field_attach_load:
- hook_field_storage_pre_load()
- hook_field_storage_load()
- field-type module's hook_field_load()
- hook_field_attach_load()
which gives me a good options BUT! after all has been done, the resulted data gets cached. I understand the approach, but In few situations I really could use an option to not cache the field's data.
So I propose another hook(hook_field_attach_load_uncached) that would be placed at the end of the field_attach_load function and could alter the data on the fly. Sure, it's only for those who know what they're doing but since the only way around current situation is to use hook_entity_load and scan for fields to alter, this is much better and more Drupal way to do it.
Since this design is still present in Drupal 8 I'm assigning this to D8 version and I hope it gets backported(if implemented).
Comments
Comment #1
swentel CreditAttribution: swentel commentedWhat's the use case ? There are plenty of other hooks to alter things in Field API, especially at runtime while rendering.
Comment #2
Anonymous (not verified) CreditAttribution: Anonymous commentedLet's say you have a field that stores all it's data in separate table(or maybe not even on the same host) and the field itself only holds ID of the entry in that table. If you want to work with entity that has this field attached to it programatically you always have to manually load the data(of course you have to check if the data wasn't loaded before, and this is PIN if yo uare working with serialized data objects). If you are using UI to alter the data you can use field widget hooks(or formatter hooks depending on operation) but if yo uare not, you always have to check the availability of the data and always load it on demand insted of it being loaded with the entity in the first place.
Comment #3
swentel CreditAttribution: swentel commentedI guess if you have a field that stores different data, you've just created your own field right ? Can't you just manage that in hook_field_load() ? There's also always hook_entity_load - just thinking along. Because adding another load hook, uncached, can lead to performance penalties which we really don't want.
Comment #4
Anonymous (not verified) CreditAttribution: Anonymous commentedAs I've mention in my initial post, after hook_field_load(and other avialable hooks) all data gets cached, which is not always wanted behavior. It's OK statically but not "permanently" in DB.