tripal_ds.ds.inc 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. $prop_fields = array();
  9. $summary_fields = array();
  10. $data_sequence_fields = array();
  11. $all_other_fields = array();
  12. $fields_with_regions = array();
  13. $i = 0;
  14. foreach ($instances as $key => $instance){
  15. $instance_name = $instance['field_name'];
  16. if($instance_name=="rdfs__type"){
  17. array_push($summary_fields, $instance_name);
  18. $fields_with_regions[$instance_name]= 'right';
  19. }
  20. else {
  21. //TODO: How do we handle non-chado dbs, placement of fields within tripal panes might need to be done in a hook.
  22. $instance_base_table = $instance['settings']['base_table'];
  23. $instance_base_chado = $instance['settings']['chado_table'];
  24. $prop_table = strpos($instance_base_chado, 'prop');
  25. $data_sequence = strpos($instance_name, 'data__sequence');
  26. if ($instance_base_chado && $instance_base_table){
  27. if ($instance_base_chado == $instance_base_table){
  28. if ($prop_table !== FALSE){
  29. //Properties section instances
  30. array_push($prop_fields, $instance_name);
  31. $fields_with_regions[$instance_name]= 'right';
  32. }
  33. elseif ($data_sequence !== FALSE) {
  34. //data sequence section instances
  35. array_push($data_sequence_fields, $instance_name);
  36. $fields_with_regions[$instance_name] = 'right';
  37. }
  38. else {
  39. //overview section instances
  40. array_push($summary_fields, $instance_name);
  41. $fields_with_regions[$instance_name] = 'right';
  42. }
  43. }
  44. elseif ($instance_base_chado != $instance_base_table){
  45. if ($prop_table !== FALSE){
  46. //Properties section instances
  47. array_push($prop_fields, $instance_name);
  48. $fields_with_regions[$instance_name]= 'right';
  49. }
  50. elseif ($data_sequence !== FALSE){
  51. //data sequence section instances
  52. array_push($data_sequence_fields, $instance_name);
  53. $fields_with_regions[$instance_name]= 'right';
  54. }
  55. else {
  56. //Linker section instances
  57. array_push($all_other_fields, $instance);
  58. $fields_with_regions[$instance_name]= 'right';
  59. //update the display settings so that the title is hidden
  60. $instance['display']['default']['label'] = 'hidden';
  61. field_update_instance($instance);
  62. }
  63. }
  64. }
  65. }
  66. $i++;
  67. }
  68. //consolidate the field sets
  69. if(!empty($summary_fields)){
  70. _summary_field_group_info($bundle_name, $summary_fields);
  71. //add the fields to the regions
  72. array_unshift($summary_fields, 'group_summary_tripalpane', 'group_summary', 'group_summary_table');
  73. $fields_with_regions += [ 'group_summary_tripalpane' =>'right', 'group_summary' => 'right', 'group_summary_table' => 'right' ];
  74. $region_right = array_merge($summary_fields, $region_right);
  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($region_right, $prop_fields);
  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($region_right, $data_sequence_fields);
  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. //add blocks to $region_left
  111. $position = count($region_right);
  112. $region_left[$position] = 'toc';
  113. $fields_with_regions += [ 'toc' => 'left'];
  114. //build the ds layout
  115. $record = new stdClass;
  116. $record->id ='TripalEntity|' . $bundle_name . '|default';
  117. $record->entity_type = 'TripalEntity';
  118. $record->bundle = $bundle_name;
  119. $record->view_mode = 'default';
  120. $record->layout = 'tripal_ds_feature';
  121. $settings = array(
  122. 'regions' => array(
  123. 'left' =>
  124. $region_left,
  125. 'right' =>
  126. $region_right,
  127. ),
  128. 'fields' =>
  129. $fields_with_regions,
  130. 'classes' => array(),
  131. 'wrappers' => array(
  132. 'left' => 'div',
  133. 'right' => 'div',
  134. ),
  135. 'layout_wrapper' => 'div',
  136. 'layout_attributes' => '',
  137. 'layout_attributes_merge' => 1,
  138. 'layout_link_attribute' => '',
  139. 'layout_link_custom' => '',
  140. 'layout_disable_css' => 0,
  141. );
  142. $record->settings = $settings;
  143. drupal_write_record('ds_layout_settings', $record);
  144. }
  145. /*
  146. * Implements hook_ds_fields_info().
  147. */
  148. function tripal_ds_ds_fields_info($entity_type) {
  149. $fields = array();
  150. $fields['toc'] = array(
  151. 'title' => t('Table of Contents'),
  152. 'field_type' => DS_FIELD_TYPE_FUNCTION,
  153. 'function' => 'tripal_ds_toc_block',
  154. );
  155. return array('TripalEntity' => $fields);
  156. }
  157. function tripal_ds_toc_block($entity_type) {
  158. $bundle_name = $entity_type['bundle'];
  159. $toc = views_embed_view('tripal_content_type_toc', 'block', $bundle_name);
  160. return $toc;
  161. }