Posted by sadashiv on March 8, 2013 at 2:15pm
1 follower
Jump to:
| Project: | Drupal core |
| Version: | 7.20 |
| Component: | forms system |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (works as designed) |
Issue Summary
I tried creating a tableselect similar to admin page user list admin/people in drupal 7. I am getting empty message displayed on the screen even though the records are passed to the tableselect as options.
<?php
function MY_MODULE_menu() {
$items = array();
$items['MY_MODULE/manage'] = array(
'page callback' => 'MY_MODULE_selector',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
function MY_MODULE_selector() {
$header = array(
'plugin' => t('Plugin'),
'status' => t('Status'),
);
$params = array(
'username' => "foo",
'password' => "bar",
);
$pluginsRecords = ///fetching data from db
foreach ($pluginsRecords as $key=>$plugin) {
$options[$key] = array(
'plugin' => $plugin['Name'],
'status' => $plugin['is_active']?'Activated':'Deactivated',
);
}
$form['table'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#empty' => t('No plugins available.'),
'#multiple' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Activate'),
);
$form['pager'] = array('#markup' => theme('pager'));
return $form;
}
?>I debugged the working and found that "form_process_tableselect" in form.inc gets invoked when the core user list page is build up but is not called when my form is invoked.
I also tried copying the same code as that of the user.admin.inc in my module file but the function didn't got called.
Comments
#1
I found my mistake
I need to pass the page callback drupal_get_form
so the code becomes
<?phpfunction MY_MODULE_menu() {
$items = array();
$items['MY_MODULE/manage'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => 'MY_MODULE_selector',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
?>