I am currently integrating Ctools into custom breadcrumbs module, so I can export and include as a feature.

I have followed this posting: http://drupal.org/node/928026, and it works. Now with Custom Breadcrumbs there are multiple submodule that need to be included.

What I want on the add/edit form is for the user to select the type (radio form element), then using ajax load another form element (dropdown or textfield) base on the type. (see first attached image).

For ajax, I hae followed the ahah_example module in: http://drupal.org/project/examples, ahah_example module

Heres some code

custom_breadcrumbs_ctools_export_ui.inc in


/**
* Define the preset add/edit form.
*/
function custom_breadcrumbs_ctools_export_ui_form(&$form, &$form_state) {
  // Grab variables from ctools
  $breadcrumb = $form_state['item'];
  
  // get the list of types to popular radio buttons
  $cb_types = _custom_breadcrumbs_get_types();
  
  //select the type, or default to node_type 
  $cb_selection = !empty($breadcrumb->cb_type) ? $breadcrumb->cb_type : 'node';
  
   // make sure container is the first item 
  $form['cb_types_wrapper'] = array(
    '#tree' => TRUE,
    '#weight' => -49,
  );
  
  //add 'field' that is unique for each submodule
  _custom_breadcrumbs_get_types_field($form, $cb_selection);
  
  $form['cb_type'] = array(
    '#type' => 'radios',
    '#options' => $cb_types,
    '#title' =>  t('Breadcrumb Type'),
    '#description' => t('Choose the type of custom breadcrumb.  For every addon module, there will be another selection added.'),
    '#default_value' => $cb_selection,
    '#weight' => -50,
    '#ahah' => array(
      'path' => 'admin/settings/custom_breadcrumbs/callback',
      'wrapper' => 'cb-field-wrapper',
      'method' => 'replace',
      'effect' => 'fade',
    ),
  );
  ...
}

/**
 * The AHAH callback. It processes the form using custom_breadcrumbs_callback_helper()
 * and then
 */
function custom_breadcrumbs_type_callback() {


  $form = custom_breadcrumbs_callback_helper();
  
  // TODO?? I think I may need an if statement here
 _custom_breadcrumbs_get_types_field($form, $cb_selection);
  
  $changed_elements = $form['cb_types_wrapper'];

  // Prevent duplicate wrappers.
  unset($changed_elements['#prefix'], $changed_elements['#suffix']);

  $output = theme('status_messages') . drupal_render($changed_elements);
 
  drupal_json(array(
    'status'   => TRUE,
    'data'     => $output,
  ));
}

in custom_breadcrumbs.module


/**
 * Implements hook_menu().
 */
function custom_breadcrumbs_menu() {
  ...
  $items['admin/settings/custom_breadcrumbs/callback'] = array(
    'page callback' => 'custom_breadcrumbs_type_callback',
    'access callback' => TRUE,
    'file' => 'plugins/export_ui/custom_breadcrumbs_ctools_export_ui.inc',
    'type' => MENU_CALLBACK,
  );
  return $items;

/**
 * Does the very standard things that must be done in any normal callback.
 */
function custom_breadcrumbs_callback_helper() {
  //ctools_include('export');

  $form_state = array('storage' => NULL, 'submitted' => FALSE);
  $form_build_id = $_POST['form_build_id'];
  $form = form_get_cache($form_build_id, $form_state);
  $args = $form['#parameters'];
  $form_id = array_shift($args);
  $form_state['post'] = $form['#post'] = $_POST;
  // Enable the submit/validate handlers to determine whether AHAH-submittted.
  $form_state['ahah_submission'] = TRUE;
  $form['#programmed'] = $form['#redirect'] = FALSE;
  drupal_process_form($form_id, $form, $form_state);

  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
  return $form;
}

When I click on a different breadcrumb type, to invoke this (see attached image), I get this error
warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'ctools_export_ui_edit_item_form' was given in /var/www/vhosts/iongs.com/httpdocs/includes/form.inc on line 376.

I can tell the problem occurs because ctool_export_ui object/class is not load and the 'ctools_export_ui_edit_item_form' function has not been defined yet.

any ideas how I can fix this? am I running the ajax/ahah right?

CommentFileSizeAuthor
form1.png9.49 KBistryker

Comments

istryker’s picture

I would like to also say, I do not need to use the FormAPI AHAH, in the code above. If there is a way of doing this with Ctools Ajax then I'm all ears. I have looked at the code in the AJAX example module that comes with Ctools, as well as, the advance help that come with the module. The AJAX page is currently blank. And the example code doesn't help me at all.

vgoodvin’s picture

I have same problem. Subscribe.

g089h515r806’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

I have similar issue when using Drupal 7

g089h515r806’s picture

It works with Drupal 7. I make a mistake.

Ashlar’s picture

g089h515r806 implies that this is working in version 7 and the original support request has not been active for more than two months. In an effort to clean-up the issue queue this item has been closed. If all modules are up-dated and the request is still a concern please feel free to change the Status back to active.

Ashlar’s picture

Status: Active » Closed (won't fix)