tripal_ds.ds.inc 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. * Implements hook_ds_layout_settings_info().
  4. */
  5. function _ds_layout_settings_info($bundle_name, $instances) {
  6. $region_right = array();
  7. $region_left = array();
  8. $region_top = array();
  9. $region_bottom = array();
  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($region_top, $instance_name);
  19. $fields_with_regions[$instance_name]= 'top';
  20. } else {
  21. $instance_base_table = $instance['settings']['base_table'];
  22. $instance_base_chado = $instance['settings']['chado_table'];
  23. $prop_table = strpos($instance_base_chado, 'prop');
  24. $data_sequence = strpos($instance_name, 'data__sequence');
  25. if ($instance_base_chado && $instance_base_table){
  26. if ($instance_base_chado == $instance_base_table){
  27. if ($prop_table !== FALSE){
  28. //Properties section instances
  29. array_push($prop_fields, $instance_name);
  30. $fields_with_regions[$instance_name]= 'right';
  31. } elseif ($data_sequence !== FALSE) {
  32. //data sequence section instances
  33. array_push($data_sequence_fields, $instance_name);
  34. $fields_with_regions[$instance_name] = 'right';
  35. }else {
  36. //overview section instances
  37. array_push($region_top, $instance_name);
  38. $fields_with_regions[$instance_name] = 'top';
  39. }
  40. } elseif ($instance_base_chado != $instance_base_table){
  41. if ($prop_table !== FALSE){
  42. //Properties section instances
  43. array_push($prop_fields, $instance_name);
  44. $fields_with_regions[$instance_name]= 'right';
  45. } elseif ($data_sequence !== FALSE){
  46. //data sequence section instances
  47. array_push($data_sequence_fields, $instance_name);
  48. $fields_with_regions[$instance_name]= 'right';
  49. } else {
  50. //Linker section instances
  51. //array_push($region_right, $instance_name);
  52. array_push($all_other_fields, $instance);
  53. $fields_with_regions[$instance_name]= 'right';
  54. }
  55. }
  56. }
  57. }
  58. $i++;
  59. }
  60. //add the field sets to the region arrays
  61. if(!empty($region_top)){
  62. tripal_ds_overview_field_group_info($bundle_name, $region_top);
  63. array_unshift($region_top, 'group_overview', 'group_overview_table');
  64. $fields_with_regions['group_summary']= 'top';
  65. $fields_with_regions['group_summary_table']= 'top';
  66. }
  67. if (!empty($prop_fields)){
  68. tripal_ds_prop_field_group_info($bundle_name, $prop_fields);
  69. array_unshift($prop_fields, 'group_prop', 'group_prop_table');
  70. $region_right = array_merge($prop_fields, $region_right);
  71. $fields_with_regions['group_prop']= 'right';
  72. $fields_with_regions['group_prop_table']= 'right';
  73. }
  74. if (!empty($data_sequence_fields)){
  75. tripal_ds_data_sequence_field_group_info($bundle_name, $data_sequence_fields);
  76. array_unshift($data_sequence_fields, 'group_sequence', 'group_sequence_table');
  77. $region_right = array_merge($data_sequence_fields, $region_right);
  78. $fields_with_regions['group_sequence']= 'right';
  79. $fields_with_regions['group_sequence_table']= 'right';
  80. }
  81. if (!empty($all_other_fields)){
  82. foreach ($all_other_fields as $key => $other_field) {
  83. //temporary fields
  84. $temporary_field = array();
  85. $group_field_name = 'group_'.$other_field['field_name'];
  86. watchdog('debug', '<pre>_ds_layout_settings_info $group_field_name: '. print_r($group_field_name, TRUE) .'</pre>');
  87. //build the field group
  88. tripal_ds_additional_fields_field_group_info($bundle_name, $other_field['label'], $other_field['field_name']);
  89. //update arrays
  90. array_push($temporary_field, $group_field_name, $other_field['field_name']);
  91. $region_right = array_merge($region_right, $temporary_field);
  92. watchdog('debug', '<pre>_ds_layout_settings_info $temporary_field: '. print_r($temporary_field, TRUE) .'</pre>');
  93. $fields_with_regions[$group_field_name]= 'right';
  94. }
  95. }
  96. //build the ds layout
  97. $record = new stdClass;
  98. $record->id ='TripalEntity|' . $bundle_name . '|default';
  99. $record->entity_type = 'TripalEntity';
  100. $record->bundle = $bundle_name;
  101. $record->view_mode = 'default';
  102. $record->layout = 'tripal_ds_feature';
  103. $settings = array(
  104. 'regions' => array(
  105. 'top' =>
  106. $region_top,
  107. 'left' =>
  108. $region_left,
  109. 'right' =>
  110. $region_right,
  111. 'bottom' =>
  112. $region_bottom,
  113. ),
  114. 'fields' =>
  115. $fields_with_regions,
  116. 'classes' => array(),
  117. 'wrappers' => array(
  118. 'top' => 'div',
  119. 'left' => 'div',
  120. 'right' => 'div',
  121. 'bottom' => 'div',
  122. ),
  123. 'layout_wrapper' => 'div',
  124. 'layout_attributes' => '',
  125. 'layout_attributes_merge' => 1,
  126. 'layout_link_attribute' => '',
  127. 'layout_link_custom' => '',
  128. 'layout_disable_css' => 0,
  129. );
  130. $record->settings = $settings;
  131. watchdog('debug', '<pre>_ds_layout_settings_info $record: '. print_r($record, TRUE) .'</pre>');
  132. drupal_write_record('ds_layout_settings', $record);
  133. }