Greets!

I'm trying to cache some data in hook_field_widget_form. The data has to be cached on a per form build basis, but it doesn't appear that the form build_id is available in any variables that are passed to that function (although interestingly enough, it is passed both $form and $form_state -- it just appears that at the time the function is called, neither of these variables contains the actual form id).

What I'm trying to do is query a view for a list of field option checkboxes. Unfortunately, if the output of the view changes between when the form is initially rendered and when it is submitted, the value of the widget ends up being completely wrong because the order of the options has changed. So what I need to do is cache the output of the view from when the form is first rendered, but I don't have any thing that uniquely identifies that particular form build to use as a cache key, and since I can't cache anything, none of the data is carrying over to when the form is submitted. I could enable $form['#cache'], but that would cause it to cache *everything*, which isn't what I want either.

At any rate, I've kind of got a chicken/egg problem here. Even if I assign a random ID to the form, I don't know of a good way to save it. Can anyone think of a solution to this problem?

Thanks,
Bart K.
http://opengameart.org

Comments

bartk’s picture

bump

judahtanthony’s picture

Well, I don't know if I can full understand your problem, but the $form and $form_state objects don't have the $form_build_id, then have you thought about creating the options during a #after_build, #process, or even #pre_render hook?