[development] wit's end: altering options for an optionwidgets_select element - OR - life without #DANGEROUS_SKIP_CHECK
Harry Slaughter
harry at devbee.com
Mon Mar 9 23:49:40 UTC 2009
Gerhard Killesreiter wrote:
> Harry Slaughter schrieb:
>> I want to alter the options for a cck optionwidgets_select element based on data
>> in the node itself.
>
>> I can't use a function in the cck widget configuration page because that's
>> called before the node is loaded, so I don't know what the options should be yet.
>
>> I can't do it in hook_form_alter() because optionwidgets_select elements have
>> not yet been fully rendered (the actual options for the select have not been set
>> yet).
>
>> I can make the alteration using #pre_render, but then form validation has run
>> already so I've corrupted the form and I fail _form_validate() and get the
>> 'illegal choice...' error. And I cannot use the
>> drupal_process_form()/drupal_rebuild_form() trick (as seen in AHAH) because the
>> #pre_render callback does not have access to $form_state.
>
>> I can't use #DANGEROUS_SKIP_CHECK because it has been removed.
>
>
> Have you considere to add a #process function that runs after the
> optionwidget one? Look at the flexifield module how to add one.
>
> Cheers,
> Gerhard
Thanks for the response. I did look into #process but was unable to quickly
figure out what the heck it does :) I was quite frustrated.
Shortly after sending out this message, I figured out that the options for an
optionwidgets_select element are accessible from hook_form_alter(), but not in
the place one would expect ($form['my_cck_select_field'][#options]) but instead
are stored as a string in
$form['#field_info']['my_cck_select_field']['allowed_values']. I can set a
string value of options there and it will show up in the rendered form. Not at
all pretty, but it works.
--
Harry Slaughter
Web Developer
Devbee - Effective Drupal
http://devbee.com/
619-249-8780
More information about the development
mailing list