tripal_ds.field_formatter.inc 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Implements hook_field_group_formatter_info().
  4. */
  5. function tripal_ds_field_group_formatter_info() {
  6. return array(
  7. 'form' => array(
  8. 'tripalpane' => array(
  9. 'label' => t('Tripal Pane'),
  10. 'description' => t('This fieldgroup renders the inner content in a Tripal Pane with the title as legend.'),
  11. 'instance_settings' => array('description' => '', 'classes' => '', 'id' => '', 'hide' => 1),
  12. ),
  13. ),
  14. 'display' => array(
  15. 'tripalpane' => array(
  16. 'label' => t('Tripal Pane'),
  17. 'description' => t('This fieldgroup renders the inner content in a Tripal Pane with the title as legend.'),
  18. 'instance_settings' => array('description' => '', 'classes' => '', 'id' => '', 'hide' => 1),
  19. ),
  20. ),
  21. );
  22. }
  23. /**
  24. * Implements hook_field_group_format_settings().
  25. *
  26. * @params Object $group The group object.
  27. * @return Array $form The form element for the format settings.
  28. */
  29. function tripal_ds_field_group_format_settings($group) {
  30. // Add a wrapper for extra settings to use by others.
  31. $form = array(
  32. 'instance_settings' => array(
  33. '#tree' => TRUE,
  34. '#weight' => 2,
  35. ),
  36. );
  37. $field_group_types = field_group_formatter_info();
  38. $mode = $group->mode == 'form' ? 'form' : 'display';
  39. $formatter = $field_group_types [$mode][$group->format_type];
  40. // Add optional instance_settings.
  41. switch ($group->format_type) {
  42. case 'tripalpane':
  43. $form['instance_settings']['hide'] = array(
  44. '#title' => t('Hide panel on page load'),
  45. '#type' => 'checkbox',
  46. '#default_value' => isset($group->format_settings['instance_settings']['hide']) ? $group->format_settings['instance_settings']['hide'] : $formatter['instance_settings']['hide'],
  47. '#weight' => 2,
  48. );
  49. break;
  50. }
  51. return $form;
  52. }
  53. /*
  54. * Implements field_group_pre_render_<format-type>.
  55. * Format type: Tripalpane.
  56. *
  57. * @param $element The field group form element.
  58. * @param $group The Field group object prepared for pre_render.
  59. * @param $form The root element or form.
  60. */
  61. function tripal_ds_field_group_pre_render(&$element, $group, &$form) {
  62. switch ($group->format_type) {
  63. case 'tripalpane':
  64. $group_name = $group->group_name;
  65. //Hide the tripal panes here if there are no children.
  66. $description = $group->format_settings['instance_settings']['description'];
  67. $hide = isset($group->format_settings['instance_settings']['hide']) ? $group->format_settings['instance_settings']['hide'] : 'none';
  68. $classes = $group->format_settings['instance_settings']['classes'];
  69. if ($hide == '1') {
  70. $element['#prefix'] = '<div class="tripal_pane-fieldset-'.$group_name.' '.$group_name.' tripal_pane '.$classes.' hideTripalPane"> <span class="field-group-format-title">' . check_plain(t($group->label)) . '</span>';
  71. }
  72. else {
  73. $element['#prefix'] = '<div class="tripal_pane-fieldset-'.$group_name.' '.$group_name.' tripal_pane '.$classes.'"> <span class="field-group-format-title">' . check_plain(t($group->label)) . '</span>';
  74. }
  75. if (!empty($description)) {
  76. $element['#prefix'] .= '<div class="description">' . $description . '</div>';
  77. }
  78. $element['#suffix'] = '</div>';
  79. break;
  80. }
  81. }