tripal_ds.ds.inc 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /**
  3. * Implements hook_ds_layout_settings_info().
  4. */
  5. function _ds_layout_settings_info($bundle_name, $instances) {
  6. //$all_fields= array(); //was region_right
  7. $prop_fields = array(); // was region_left
  8. $summary_fields = array(); // was region_top
  9. $data_sequence_fields = array(); //was region_bottom
  10. //$prop_fields = array();
  11. //$data_sequence_fields = array();
  12. $all_other_fields = array();
  13. //$fields_with_regions = array();
  14. $i = 0;
  15. foreach ($instances as $key => $instance){
  16. $instance_name = $instance['field_name'];
  17. if($instance_name=="rdfs__type"){
  18. array_push($summary_fields, $instance_name);
  19. //$fields_with_regions[$instance_name]= 'top';
  20. }
  21. else {
  22. //TODO: How do we handle non-chado dbs, placement of fields within tripal panes might need to be done in a hook.
  23. $instance_base_table = $instance['settings']['base_table'];
  24. $instance_base_chado = $instance['settings']['chado_table'];
  25. $prop_table = strpos($instance_base_chado, 'prop');
  26. $data_sequence = strpos($instance_name, 'data__sequence');
  27. if ($instance_base_chado && $instance_base_table){
  28. if ($instance_base_chado == $instance_base_table){
  29. if ($prop_table !== FALSE){
  30. //Properties section instances
  31. array_push($prop_fields, $instance_name);
  32. //$fields_with_regions[$instance_name]= 'right';
  33. }
  34. elseif ($data_sequence !== FALSE) {
  35. //data sequence section instances
  36. array_push($data_sequence_fields, $instance_name);
  37. // $fields_with_regions[$instance_name] = 'right';
  38. }
  39. else {
  40. //overview section instances
  41. array_push($summary_fields, $instance_name);
  42. // $fields_with_regions[$instance_name] = 'top';
  43. }
  44. }
  45. elseif ($instance_base_chado != $instance_base_table){
  46. if ($prop_table !== FALSE){
  47. //Properties section instances
  48. array_push($prop_fields, $instance_name);
  49. // $fields_with_regions[$instance_name]= 'right';
  50. }
  51. elseif ($data_sequence !== FALSE){
  52. //data sequence section instances
  53. array_push($data_sequence_fields, $instance_name);
  54. // $fields_with_regions[$instance_name]= 'right';
  55. }
  56. else {
  57. //Linker section instances
  58. array_push($all_other_fields, $instance);
  59. // $fields_with_regions[$instance_name]= 'right';
  60. //update the display settings so that the title is hidden
  61. $instance['display']['default']['label'] = 'hidden';
  62. field_update_instance($instance);
  63. }
  64. }
  65. }
  66. }
  67. $i++;
  68. }
  69. //consolidate the field sets
  70. if(!empty($summary_fields)){
  71. _summary_field_group_info($bundle_name, $summary_fields);
  72. //add the fields to the regions
  73. //array_unshift($summary_fields, 'group_summary_tripalpane', 'group_summary', 'group_summary_table');
  74. //$fields_with_regions += [ 'group_summary_tripalpane' =>'top', 'group_summary' => 'top', 'group_summary_table' => 'top' ];
  75. }
  76. if (!empty($prop_fields)){
  77. _prop_field_group_info($bundle_name, $prop_fields);
  78. //array_unshift($prop_fields, 'group_prop_tripalpane', 'group_prop', 'group_prop_table');
  79. //add the fields to the regions
  80. //$region_right = array_merge($prop_fields, $region_right);
  81. //$fields_with_regions += [ 'group_prop_tripalpane' => 'right', 'group_prop' => 'right', 'group_prop_table' => 'right' ];
  82. }
  83. if (!empty($data_sequence_fields)){
  84. _data_sequence_field_group_info($bundle_name, $data_sequence_fields);
  85. //array_unshift($data_sequence_fields, 'group_sequence_tripalpane', 'group_sequence', 'group_sequence_table');
  86. //add the fields to the regions
  87. //$region_right = array_merge($data_sequence_fields, $region_right);
  88. //$fields_with_regions += [ 'group_sequence_tripalpane' => 'right', 'group_sequence' => 'right', 'group_sequence_table' => 'right' ];
  89. }
  90. if (!empty($all_other_fields)){
  91. foreach ($all_other_fields as $key => $other_field) {
  92. //temporary field names
  93. $temporary_field = array();
  94. $group_field_name = 'gp_'.$other_field['field_name'];
  95. $fieldset_field_name = 'ft_'.$other_field['field_name'];
  96. //need to truncate the names because of database field size restrictions, updating fields here to ensure name consistency
  97. $group_field_name = substr($group_field_name, 0, 27);
  98. $fieldset_field_name = substr($fieldset_field_name, 0, 27);
  99. //add randomm numbers to ensure the field name is unique within the 32 character limit of the field
  100. $group_field_name = $group_field_name.rand(0, 99999);
  101. $fieldset_field_name = $fieldset_field_name.rand(0, 99999);
  102. //build the field group
  103. _additional_fields_field_group_info($bundle_name, $other_field['label'], $group_field_name, $fieldset_field_name, $other_field['field_name']);
  104. //update arrays
  105. //array_push($temporary_field, $group_field_name, $fieldset_field_name, $other_field['field_name']);
  106. //$region_right = array_merge($region_right, $temporary_field);
  107. //$fields_with_regions+= [ $group_field_name => 'right', $fieldset_field_name => 'right' ];
  108. }
  109. }
  110. /*
  111. //build the ds layout
  112. $record = new stdClass;
  113. $record->id ='TripalEntity|' . $bundle_name . '|default';
  114. $record->entity_type = 'TripalEntity';
  115. $record->bundle = $bundle_name;
  116. $record->view_mode = 'default';
  117. $record->layout = 'tripal_ds_feature';
  118. $settings = array(
  119. 'regions' => array(
  120. 'top' =>
  121. $region_top,
  122. 'left' =>
  123. $region_left,
  124. 'right' =>
  125. $region_right,
  126. 'bottom' =>
  127. $region_bottom,
  128. ),
  129. 'fields' =>
  130. $fields_with_regions,
  131. 'classes' => array(),
  132. 'wrappers' => array(
  133. 'top' => 'div',
  134. 'left' => 'div',
  135. 'right' => 'div',
  136. 'bottom' => 'div',
  137. ),
  138. 'layout_wrapper' => 'div',
  139. 'layout_attributes' => '',
  140. 'layout_attributes_merge' => 1,
  141. 'layout_link_attribute' => '',
  142. 'layout_link_custom' => '',
  143. 'layout_disable_css' => 0,
  144. );
  145. $record->settings = $settings;
  146. drupal_write_record('ds_layout_settings', $record);
  147. */
  148. }