tripal_ds.ds.inc 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <?php
  2. /**
  3. * Implements hook_ds_layout_settings_info().
  4. */
  5. /*function tripal_ds_ds_layout_settings_info() {
  6. $export = array();
  7. //$bundle_name = $bundle;
  8. $region_fields_right;
  9. $fields_string;
  10. //build the string for the regions and fields section from the $fields array
  11. $total_fields = count($fields[1][0]);
  12. $fields_string = implode(",", $fields[1][0]);
  13. for ($i=0; $i < $total_fields; $i++) {
  14. //watchdog('debug', '<pre>_ds_layout_settings_info $fields_string: '. print_r($fields[1][0][$i], TRUE) .'</pre>');
  15. $region_fields_right .= $i ." => ". $fields[1][0][$i].", ";
  16. $fields_string .= $fields[1][0][$i] ." => 'right', ";
  17. }
  18. $ds_layout = new stdClass();
  19. $ds_layout->api_version = 1;
  20. $ds_layout->id = 'TripalEntity|bio_data_78|default';
  21. $ds_layout->entity_type = 'TripalEntity';
  22. $ds_layout->bundle = 'bio_data_78';
  23. $ds_layout->view_mode = 'default';
  24. $ds_layout->layout = 'tripal_ds_feature';
  25. $ds_layout->settings = array(
  26. 'regions' => array(
  27. 'top' => array(),
  28. 'left' => array(),
  29. 'right' => array(
  30. 0 => 'project_contact',
  31. 1 => 'rdfs__type',
  32. 2 => 'sbo__database_cross_reference',
  33. 3 => 'sbo__relationship',
  34. 4 => 'schema__description',
  35. 5 => 'schema__name',
  36. 6 => 'schema__publication',
  37. ),
  38. 'bottom' => array(),
  39. ),
  40. 'fields' => array(
  41. 'project_contact' => 'right',
  42. 'rdfs__type' => 'right',
  43. 'sbo__database_cross_reference' => 'right',
  44. 'sbo__relationship' => 'right',
  45. 'schema__description' => 'right',
  46. 'schema__name' => 'right',
  47. 'schema__publication' => 'right',
  48. ),
  49. 'classes' => array(),
  50. 'wrappers' => array(
  51. 'top' => 'div',
  52. 'left' => 'div',
  53. 'right' => 'div',
  54. 'bottom' => 'div',
  55. ),
  56. 'layout_wrapper' => 'div',
  57. 'layout_attributes' => '',
  58. 'layout_attributes_merge' => 1,
  59. 'layout_link_attribute' => '',
  60. 'layout_link_custom' => '',
  61. 'layout_disable_css' => 0,
  62. );
  63. $export['TripalEntity|bio_data_78|default'] = $ds_layout;
  64. if($export){
  65. // Insert the layout.
  66. db_insert('ds_layout_settings')
  67. ->fields(array(
  68. 'id' => $ds_layout->id,
  69. 'entity_type' => 'TripalEntity',
  70. 'bundle' => $ds_layout->bundle,
  71. 'view_mode' => 'default',
  72. 'layout' => 'tripal_ds_feature',
  73. ))
  74. ->execute();
  75. }
  76. watchdog('debug', '<pre>_ds_layout_settings_info $$ds_layout->settings: '. print_r($ds_layout->settings, TRUE) .'</pre>');
  77. if($ds_layout->settings ){
  78. $record = new stdClass;
  79. $record->id ='TripalEntity|bio_data_73|default';
  80. $record->entity_type = 'TripalEntity';
  81. $record->bundle = ;
  82. $record->view_mode = 'default';
  83. $record->settings = $ds_layout->settings;
  84. drupal_write_record('ds_field_settings', $record);
  85. }
  86. return $export;
  87. }*/
  88. /**
  89. * Implements hook_ds_layout_settings_info().
  90. */
  91. function _ds_layout_settings_info($bundle_name, $fields) {
  92. $export = array();
  93. //$bundle_name = $bundle;
  94. $region_fields_right;
  95. $fields_string;
  96. //build the string for the regions and fields section from the $fields array
  97. $total_fields = count($fields[1][0]);
  98. $fields_string = implode(",", $fields[1][0]);
  99. for ($i=0; $i < $total_fields; $i++) {
  100. //watchdog('debug', '<pre>_ds_layout_settings_info $fields_string: '. print_r($fields[1][0][$i], TRUE) .'</pre>');
  101. $region_fields_right .= $i ." => ". $fields[1][0][$i].", ";
  102. $fields_string .= $fields[1][0][$i] ." => 'right', ";
  103. }
  104. $ds_layout = new stdClass();
  105. $ds_layout->api_version = 1;
  106. $ds_layout->id = 'TripalEntity|'.$bundle_name.'|default';
  107. $ds_layout->entity_type = 'TripalEntity';
  108. $ds_layout->bundle = $bundle_name;
  109. $ds_layout->view_mode = 'default';
  110. $ds_layout->layout = 'tripal_ds_feature';
  111. $ds_layout->settings = array(
  112. 'regions' => array(
  113. 'top' => array(),
  114. 'left' => array(),
  115. 'right' => array(
  116. 0 => 'project_contact',
  117. 1 => 'rdfs__type',
  118. 2 => 'sbo__database_cross_reference',
  119. 3 => 'sbo__relationship',
  120. 4 => 'schema__description',
  121. 5 => 'schema__name',
  122. 6 => 'schema__publication',
  123. ),
  124. 'bottom' => array(),
  125. ),
  126. 'fields' => array(
  127. 'project_contact' => 'right',
  128. 'rdfs__type' => 'right',
  129. 'sbo__database_cross_reference' => 'right',
  130. 'sbo__relationship' => 'right',
  131. 'schema__description' => 'right',
  132. 'schema__name' => 'right',
  133. 'schema__publication' => 'right',
  134. ),
  135. 'classes' => array(),
  136. 'wrappers' => array(
  137. 'top' => 'div',
  138. 'left' => 'div',
  139. 'right' => 'div',
  140. 'bottom' => 'div',
  141. ),
  142. 'layout_wrapper' => 'div',
  143. 'layout_attributes' => '',
  144. 'layout_attributes_merge' => 1,
  145. 'layout_link_attribute' => '',
  146. 'layout_link_custom' => '',
  147. 'layout_disable_css' => 0,
  148. );
  149. $export['TripalEntity|'.$bundle_name.'|default'] = $ds_layout;
  150. module_load_include('inc', 'ds', 'ds.registry');
  151. _ds_entity_type_update('TripalEntity', $export, 'update');
  152. /*if($export){
  153. // Insert the layout.
  154. db_insert('ds_layout_settings')
  155. ->fields(array(
  156. 'id' => $ds_layout->id,
  157. 'entity_type' => 'TripalEntity',
  158. 'bundle' => $ds_layout->bundle,
  159. 'view_mode' => 'default',
  160. 'layout' => 'tripal_ds_feature',
  161. ))
  162. ->execute();
  163. }
  164. watchdog('debug', '<pre>_ds_layout_settings_info $$ds_layout->settings: '. print_r($ds_layout->settings, TRUE) .'</pre>');
  165. if($ds_layout->settings ){
  166. $record = new stdClass;
  167. $record->id ='TripalEntity|bio_data_73|default';
  168. $record->entity_type = 'TripalEntity';
  169. $record->bundle = ;
  170. $record->view_mode = 'default';
  171. $record->settings = $ds_layout->settings;
  172. drupal_write_record('ds_field_settings', $record);
  173. }*/
  174. return $export;
  175. }
  176. function tripal_ds_content_type_fields($bundle_name){
  177. $base_fields = array();
  178. $all_fields = array();
  179. $custom_fields = array();
  180. $fields = db_select('field_config_instance', 'i')
  181. ->fields('i', array('field_name'))
  182. ->condition('bundle', $bundle_name)
  183. ->execute()
  184. ->fetchAll();
  185. //break apart each field to grab the base table identifiers
  186. foreach ($fields as $fields => $field) {
  187. $field_parts = explode('__', $field->field_name, 2);
  188. if(count($field_parts) > 1) {
  189. $base_field = $field_parts[0];
  190. $nonbase_field = $field_parts[1];
  191. } else {
  192. $base_field = $field_parts[0];
  193. }
  194. array_push($base_fields, $base_field);
  195. array_push($all_fields, $field->field_name);
  196. }
  197. //create the left base table fields based on the previous foreach loop
  198. if ($base_fields) {
  199. $base_fields = array_unique($base_fields);
  200. foreach($base_fields as $base_fields => $basefield){
  201. $custom_field = tripal_ds_ds_custom_fields_info($basefield);
  202. array_push($custom_fields, $custom_field);
  203. }
  204. }
  205. $all_fields = array(
  206. array($base_fields),
  207. array($all_fields),
  208. array($custom_fields),
  209. );
  210. //tripal_ds_ds_layout_settings_info($bundle_name, $all_fields);
  211. watchdog('debug', '<pre>tripal_ds_content_type_fields $all_fields: '. print_r($all_fields, TRUE) .'</pre>');
  212. return $all_fields;
  213. }
  214. /*
  215. * Implements hook_ds_custom_fields_info().
  216. */
  217. function tripal_ds_ds_custom_fields_info($field) {
  218. $export = array();
  219. $ds_field = new stdClass;
  220. $ds_field->api_version = 1;
  221. $ds_field->field = $field;
  222. $ds_field->label = $field;
  223. $ds_field->field_type = 6;
  224. $ds_field->entities = array(
  225. 'TripalEntity' => 'TripalEntity',
  226. );
  227. $ds_field->ui_limit = '';
  228. $ds_field->properties = array(
  229. 'block' => 'node|recent',
  230. 'block_render' => '2',
  231. );
  232. $export[$field] = $ds_field;
  233. return $export;
  234. }