tripal_ds.field_formatter.inc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. 'format_types' => array('open', 'collapsible', 'collapsed'),
  12. 'instance_settings' => array('description' => '', 'classes' => '', 'required_fields' => 1, 'id' => ''),
  13. 'default_formatter' => 'collapsible',
  14. ),
  15. ),
  16. 'display' => array(
  17. 'tripalpane' => array(
  18. 'label' => t('Tripal Pane'),
  19. 'description' => t('This fieldgroup renders the inner content in a Tripal Pane with the title as legend.'),
  20. 'format_types' => array('open', 'collapsible', 'collapsed'),
  21. 'default_formatter' => 'collapsible',
  22. 'instance_settings' => array('description' => '', 'classes' => '', 'id' => ''),
  23. ),
  24. ),
  25. );
  26. }
  27. /**
  28. * Implements hook_field_group_format_settings().
  29. * If the group has no format settings, default ones will be added.
  30. * @params Object $group The group object.
  31. * @return Array $form The form element for the format settings.
  32. */
  33. function tripal_ds_field_group_format_settings($group) {
  34. $form = array();
  35. // Add instance_settings.
  36. switch ($group->format_type) {
  37. case 'tripalpane':
  38. $form['label']['#description'] = t('Please enter a label for collapsible elements');
  39. break;
  40. }
  41. return $form;
  42. }
  43. /**
  44. * Implements field_group_pre_render_<format-type>.
  45. * Format type: Tripalpane.
  46. *
  47. * @param $element The field group form element.
  48. * @param $group The Field group object prepared for pre_render.
  49. * @param $form The root element or form.
  50. */
  51. function field_group_pre_render_tripalpane(&$element, $group, &$form) {
  52. $element += array(
  53. '#type' => 'tripalpane',
  54. '#title' => check_plain(t($group->label)),
  55. '#collapsible' => $group->collapsible,
  56. '#collapsed' => $group->collapsed,
  57. '#pre_render' => array(),
  58. '#attributes' => array('class' => explode(' ', $group->classes)),
  59. '#description' => $group->description,
  60. );
  61. if ($group->collapsible || $group->collapsed) {
  62. $element['#attached']['library'][] = array('system', 'drupal.collapse');
  63. }
  64. }
  65. /**
  66. * Implements hook_field_group_build_pre_re2 nder_alter().
  67. * @param Array $elements by address.
  68. */
  69. function tripal_ds_field_group_build_pre_render_alter(&$element) {
  70. // While custom fields and groups are present at the root level of the form
  71. // e.g. $element['field_custom_field'] they will later be moved into
  72. // $element['additional_settings']['group']['#groups']['additional_settings']['field_custom_field']
  73. // which is where we need to alter them.
  74. // Use the states API to set the visibility of a fieldset within a vertical
  75. // tab based on the value of a custom checkbox field.
  76. if (isset($element['group_parent_vertical_tab'])) {
  77. $element['additional_settings']['group']['#groups']['additional_settings']['group_parent_vertical_tab']['group_child_fieldset']['#states'] = array(
  78. 'visible' => array(
  79. ':input[name="field_custom_checkbox[' . LANGUAGE_NONE . ']"]' => array('checked' => TRUE),
  80. ),
  81. );
  82. }
  83. }
  84. /**
  85. * Implements hook_field_group_format_summary().
  86. */
  87. function tripal_ds_field_group_format_summary($group) {
  88. }