My current process for outputting custom field data in a plug-in is:
Get a list of custom fields assigned to the channel of interest, including field_id and field_name.
Go fetch the field_id_X and field_ft_X data using the list of field_ids.
Assemble the data into a variables array (keying by field_name, adding extra data to format by field_id_X via the Typography class where necessary).
Invoke parse_variables() to replace the tags in the tagdata.
ALAS, this doesn’t work if the custom field data belongs to a Fieldtype that needs extra formatting or does special rendering stuff in its replace_tag() or replace_X() methods.
This shortfall applies to popular add-ons like Matrix, Playa, SafeCracker… and any field that doesn’t use a plug-in or standard Typography option for formatting… and any Fieldtype that allows tag pairs with params or tag modifiers.
When you need to process custom field data outside of the Channel Module, what’s the right/best strategy?
Michael,
Unfortunately I don’t think there is a standard best practice for this. As you likely are aware of, the logic that controls how this work is buried in different places, and the fields model is just simple crud operations.
For your method, have you tried going to the source and loading/running the replace_tag and other methods?
It would be nice to get an open source API version out there that people can use for modules because I think it is an issue that comes up in module development quite often.
Adam
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.