tripal_ds.ds.inc 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. _overview_field_group_info($bundle_name, $region_top);
  63. //add the fields to the regions
  64. array_unshift($region_top, 'group_summary_tripalpane', 'group_summary', 'group_summary_table');
  65. $fields_with_regions += [ 'group_summary_tripalpane' =>'top', 'group_summary' => 'top', 'group_summary_table' => 'top' ];
  66. }
  67. if (!empty($prop_fields)){
  68. _prop_field_group_info($bundle_name, $prop_fields);
  69. array_unshift($prop_fields, 'group_prop_tripalpane', 'group_prop', 'group_prop_table');
  70. //add the fields to the regions
  71. $region_right = array_merge($prop_fields, $region_right);
  72. $fields_with_regions += [ 'group_prop_tripalpane' => 'right', 'group_prop' => 'right', 'group_prop_table' => 'right' ];
  73. }
  74. if (!empty($data_sequence_fields)){
  75. _data_sequence_field_group_info($bundle_name, $data_sequence_fields);
  76. array_unshift($data_sequence_fields, 'group_sequence_tripalpane', 'group_sequence', 'group_sequence_table');
  77. //add the fields to the regions
  78. $region_right = array_merge($data_sequence_fields, $region_right);
  79. $fields_with_regions += [ 'group_sequence_tripalpane' => 'right', 'group_sequence' => 'right', '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. $fieldset_field_name = 'fieldset_'.$other_field['field_name'];
  87. //need to truncate the names because of database field size restrictions, updating fields here to ensure name consistency
  88. $group_field_name = substr($group_field_name, 0, 15);
  89. $fieldset_field_name = substr($fieldset_field_name, 0, 15);
  90. //build the field group
  91. _additional_fields_field_group_info($bundle_name, $other_field['label'], $group_field_name, $fieldset_field_name, $other_field['field_name']);
  92. //update arrays
  93. array_push($temporary_field, $group_field_name, $fieldset_field_name, $other_field['field_name']);
  94. $region_right = array_merge($region_right, $temporary_field);
  95. $fields_with_regions+= [ $group_field_name => 'right', $fieldset_field_name => 'right' ];
  96. }
  97. }
  98. //build the ds layout
  99. $record = new stdClass;
  100. $record->id ='TripalEntity|' . $bundle_name . '|default';
  101. $record->entity_type = 'TripalEntity';
  102. $record->bundle = $bundle_name;
  103. $record->view_mode = 'default';
  104. $record->layout = 'tripal_ds_feature';
  105. $settings = array(
  106. 'regions' => array(
  107. 'top' =>
  108. $region_top,
  109. 'left' =>
  110. $region_left,
  111. 'right' =>
  112. $region_right,
  113. 'bottom' =>
  114. $region_bottom,
  115. ),
  116. 'fields' =>
  117. $fields_with_regions,
  118. 'classes' => array(),
  119. 'wrappers' => array(
  120. 'top' => 'div',
  121. 'left' => 'div',
  122. 'right' => 'div',
  123. 'bottom' => 'div',
  124. ),
  125. 'layout_wrapper' => 'div',
  126. 'layout_attributes' => '',
  127. 'layout_attributes_merge' => 1,
  128. 'layout_link_attribute' => '',
  129. 'layout_link_custom' => '',
  130. 'layout_disable_css' => 0,
  131. );
  132. $record->settings = $settings;
  133. drupal_write_record('ds_layout_settings', $record);
  134. }