wit's end: altering options for an optionwidgets_select element - OR - life without #DANGEROUS_SKIP_CHECK
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. Maybe I could use AHAH, but that would be very hacky as I do not need any input from the user in order to generate my options, just data from the node itself. The upgrade doc says to look here for alternatives to #DANGEROUS_SKIP_CHECK: http://drupal.org/node/182310 - yet that issue supplies no examples of a workaround. I understand the reason for removal of #DANGEROUS_SKIP_CHECK, but this use case is the type that the option was truly created for (I think :) I'm posting this question to the list after several days of trying every solution I could think of. If there is a solution, surely it will help others as well. -- Harry Slaughter Web Developer Devbee - Effective Drupal http://devbee.com/ 619-249-8780
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 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 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkm1pIcACgkQfg6TFvELooSflQCfR3l1d13rdfaqvM43M5Y4PXZW jd4AoIYuo3Dgzp+eVBLECh8Hc5Y8AASl =7cT/ -----END PGP SIGNATURE-----
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
participants (2)
-
Gerhard Killesreiter -
Harry Slaughter