tripal_helper_form.module 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * taken from http://www.akchauhan.com/create-drupal-form-using-theme_table-like-module-list-form/
  4. * following as function theme_featured_product_form($form)
  5. *
  6. * to be run as a regular function, within a module's theme function implementation
  7. */
  8. function tripal_helper_form_themeform(&$form, $field_keys){
  9. $rows = array();
  10. foreach (element_children($form) as $key) {
  11. $row = array();
  12. if (isset($form[$key]['name'])) {
  13. $status = drupal_render($form['featured'][$key]);
  14. $row[] = array(’data’ => $status, ‘class’ => ‘checkbox’);
  15. $bool_first = TRUE;
  16. foreach ($field_keys as $field_key => $value) {
  17. if($bool_first){
  18. $row[] = ‘‘. drupal_render($form[$key][$field_keys[$field_key]]) .’‘;//for "bold style"
  19. $bool_first = FALSE;
  20. }
  21. else{
  22. $row[] = array(’data’ => drupal_render($form[$key][$field_keys[$field_key]]),);
  23. }
  24. }
  25. $rows[] = $row;
  26. }
  27. }
  28. // Individual table headers.
  29. $header = array();
  30. $header[] = array(’data’ => t(’Featured’), ‘class’ => ‘checkbox’);
  31. foreach ($field_keys as $key => $value) {
  32. $header[] = t($key);
  33. }
  34. $output = theme(’table’, $header, $rows);
  35. $output .= drupal_render($form);
  36. return $output;
  37. }
  38. // function tripal_helper_form_createformdata