nfcbiblio.module 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Implements hook_nodeformcols_variants_alter().
  4. *
  5. * Implement this hook to supply information about form variants that can be
  6. * configured.
  7. *
  8. * @param array $variants
  9. * The current variants of the form
  10. * @param string $type
  11. * The node type
  12. * @return void
  13. */
  14. function nfcbiblio_nodeformcols_variants_alter(&$variants, $type) {
  15. if ($type == 'biblio') {
  16. $res = db_query('SELECT tid, name
  17. FROM {biblio_types}
  18. WHERE tid >= :tid
  19. AND visible = :visible
  20. ORDER BY weight ASC', array(':tid' => 0, ':visible' => 1));
  21. while ($option = db_fetch_object($res)) {
  22. $variants[$option->tid] = $option->name;
  23. }
  24. }
  25. }
  26. /**
  27. * Utility function to get a default biblio type
  28. *
  29. * @return int
  30. * The id of a default biblio type
  31. */
  32. function _nfcbiblio_top_visible_type() {
  33. return db_query_range("SELECT tid
  34. FROM {biblio_types}
  35. WHERE visible = :visible
  36. AND tid> = :tid>
  37. ORDER BY weight ASC", array(':visible' => 1, ':tid>' => 0))->fetchField();
  38. }
  39. /**
  40. * Implements hook_nodeformcols_pre_form_alter().
  41. *
  42. * Implement this hook to tell nodeformcols what variant the form is before
  43. * any alterations to the form is made.
  44. *
  45. * @param array $form
  46. * The form.
  47. * @return void
  48. */
  49. function nfcbiblio_nodeformcols_pre_form_alter(&$form) {
  50. if ($form['#node']->type == 'biblio') {
  51. if (!empty($form['biblio_type']['#value'])) {
  52. $form['#nodeformcols_variant'] = $form['biblio_type']['#value'];
  53. }
  54. }
  55. }
  56. /**
  57. * Implements hook_nodeformcols_base_form_alter().
  58. *
  59. * Implement this hook if you want to alter the node creation form that
  60. * nodeformcols uses to construct the configuration interface before
  61. * nodeformcols reads field information from it.
  62. *
  63. * @param array $form
  64. * The programatically created node creation form.
  65. * @param string $variant
  66. * The variant of the form that's being configured.
  67. * @return void
  68. */
  69. function nfcbiblio_nodeformcols_base_form_alter(&$form, $variant) {
  70. if ($form['#node']->type == 'biblio') {
  71. if ($variant == 'default') {
  72. $variant = _nfcbiblio_top_visible_type();
  73. }
  74. $biblio_form_state = array();
  75. $biblio_form_state['post']['biblio_type'] = $variant;
  76. foreach (biblio_form($form['#node'], $biblio_form_state) as $name => $def) {
  77. $form[$name] = $def;
  78. }
  79. }
  80. }