[development] read-only / remote CCK field

Chris Johnson cxjohnson at gmail.com
Mon Jan 5 23:05:14 UTC 2009

I'm building (or at least, trying to) a module which will provide a
CCK field which will display data acquired from a remote web service.
I was able to make it work, but only by horribly abusing the CCK
interface and field/widget distinction.

I have a read-only field, which has no form widget, and hence is only
displayed when a node is viewed, not edited.

I'm having difficulties doing it the right way because of 2 hurdles:

1.  The content of $element as passed into theme_XXX_formatter_YYY()
as the only argument.

This variable is a huge array containing all kinds of stuff, including
the complete node.  My content type fields are in the node, but since
they have user-specified names, I don't have any way to reference them
without lots of  ugly SQL.  My fields are also there with numbered
keys in the top-level array, but those numbers have no guaranteed
correlation, so again, I can't reference them reliably.

Is there some better way of coding hook_field() (or other hook) so
that the resultant $element array has more easily referenced values?
Or am I going about this all wrong?

2.  Getting the value into the database.

What's the best way to do this?  I need to have a local copy in
Drupal's CCK tables so that Views can function and as a caching
mechanism, so that the remote web service does not need to be hit (and
waited for) with each node view.  (Perhaps I'll add a hook_cron() to
update it periodically.)

Any suggestions on how to do this, where to better ask or where to
look for documentation and code that might help would be a
appreciated.  I'm well aware of the drupal.org docs -- I'm editing
them as I go along learning how to make this work.


More information about the development mailing list