Ok so I am running Drupal 6.20, and need the hierarchical_select api to generate some form fields in a ctools wizard form.

Ran into major issues with server errors getting returned in the json call to 'hierarchical_select_json'. Here's what I discovered about the error:

  • An "unsupported operand types" error is getting thrown from line 2946 in Drupal's /includes/common.inc (using Drupal 6.20)
  • Upon further investigation, I found that this error is getting triggered by a drupal_render() call inside of the hierarchical_select_json() function.
  • When I ran a dpm() call on the cached data retrieved in this function, I found that the form id and the parameters were missing from the cached array.
  • The result is that empty data was being sent to drupal_render() and causing the error.

Here's how I solved it:

  • I call out to a new hook inside of hierarchical_select_after_build, the function that sets the cached form info that hierarchical_select_json() expects
  • This hook is called hook_hs_parameters_alter, and expects an array of parameters. It also returns an array of parameters.
  • Inside my module's hook implementation, I manually set the form id and the 'form_load_files' array.

There was one slight complication relating to ctools.

The ctools form wizard step functions have a different signature than drupal's form api exects from a form builder function.
The expected FAPI signature is my_form(&$form_state, $params....)
The form wizard expects something like this: my_form(&$form, &$form_state)

So... I had to create a wrapper function and specify the wrapper function in my hook_hs_parameters_alter() implementation.

SO, tying it all together, here's what I have.

Change to hierarchical_select.module, within hierarchical_select_after_build():

    $parameters = (isset($form['#parameters'])) ? $form['#parameters'] : array();
    $menu_item = menu_get_item();

     // Here's the new code:
    foreach(module_list() as $module) {
      if (function_exists($module . "_hs_parameters_alter")) {
        $parameters = call_user_func_array($module . "_hs_parameters_alter", array($parameters));
      }
    }

    // Collect information in this array, which will be used in dynamic form
    // updates, to …
    $storage = array(

my_module/includes/wizard_step_1.inc

function wizard_step_1_form(&$form, &$form_state) {
   // Define hierarchical select element, among other things, here.
}

// Here's my wrapper that hierarchical_select_json() will invoke
function wizard_step_1_form_wrapper(&$form_state) {
   $form = array();
   wizard_step_1_form($form, $form_state);
  return $form;
}

my_module/my_module.module:

function my_module_hs_parameters_alter(&$parameters) {
  $parameters[0] = 'wizard_step_1_form_wrapper';
  $parameters[1]['form_load_files'][] = drupal_get_path('module', 'my_module') . "/includes/wizard_step_1.inc";
  return $parameters;
}

Comments

noahlively’s picture

StatusFileSize
new1.04 KB

And... here's the patch!

nicholasthompson’s picture

Hi Noah,

Thanks for this patch - it's certainly helped clear up the retreive form errors for me...

Two things:
1) The code in the patch could be achieved with call to drupal_alter couldn't it? Ie, instead of

    foreach(module_list() as $module) {
      if (function_exists($module . "_hs_parameters_alter")) {
        $parameters = call_user_func_array($module . "_hs_parameters_alter", array($parameters));
      }
    }

use

  drupal_alter('hs_parameters', $parameters);

Then there is no need to return $parameters as you're altering by reference.

2) Were you getting this error too?

warning: uasort() [function.uasort]: The argument should be an array in /var/www/html/d6/includes/common.inc on line 2945.
borys’s picture

Hi noahlively!
Thanks for the solution!
But i have another issue when trying to add new HS field throw AHAH in Ctools Multistep Form Wizard. After new HS fields added, previous stop to work and new HS field occurs the same error as we have before (An "unsupported operand types" error).
I think that this is ocurred by wrong HS JS settings, It's adds new "hsid" to settings and in a result it's stop working.
Have you any thoughts how to fix that?
Thanks!

kars-t’s picture

Status: Active » Fixed

Dear fellow Drupal enthusiasts,

this issue is now lasting for a very long time in the issue queue and was unfortunately never solved. As Drupal is a open source project everyone is helping on voluntary basis. So that this is was not solved is nothing personal and means no harm. But perhaps no one had time to deal with this issue, maybe it is too complex or did not describe the problem comprehensibly.

But this issue is not the only one. There are thousands of issues on Drupal.org that have never been worked on or could not be processed. This means that we are building a wave that is unmanageable and just a problem for the Drupal project as a whole. Please help us keep the issue queue smaller and more manageable.

Please read again, "Making an issue report" and see if you can improve the issue. Test the problem with the current Core and modules. Maybe the problem doesn't exist anymore, is a duplicate or has even been solved within this issue but never closed.

Help can also be found for it on IRC and in the user groups.

In order to remove this issue, I have set this issue to "fixed"

If there is new information, please re-open the issue.

Status: Fixed » Closed (fixed)
Issue tags: -form API

Automatically closed -- issue fixed for 2 weeks with no activity.

cosolom’s picture

Who need solution may find it here.