tripal_ds.module 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. require_once "includes/tripal_ds.inc";
  3. require_once "includes/tripal_ds.ds.inc";
  4. require_once "includes/tripal_ds.field_group.inc";
  5. require_once "includes/tripal_ds.field_formatter.inc";
  6. function tripal_ds_init() {
  7. drupal_add_css(drupal_get_path('module', 'tripal_ds') . '/theme/css/tripaldsfeature.css');
  8. drupal_add_js(drupal_get_path('module', 'tripal_ds') . '/theme/js/tripal_ds.js');
  9. $theme_dir = url(drupal_get_path('module', 'tripal_ds') . '/theme');
  10. drupal_add_js("var ds_theme_dir = '$theme_dir';", 'inline', 'header');
  11. }
  12. /**
  13. * Implements hook_views_api().
  14. */
  15. function tripal_ds_views_api() {
  16. return array(
  17. 'api' => 3,
  18. 'path' => drupal_get_path('module', 'tripal_ds') . '/includes/views',
  19. );
  20. }
  21. /**
  22. * Implements hook_menu().
  23. * Defines all menu items needed by Tripal DS
  24. *
  25. */
  26. function tripal_ds_menu() {
  27. $items = array();
  28. // Adds a +Apply Tripal Display Suite option to 'Tripal Content Types' page.
  29. $items['admin/structure/bio_data/manage/%/display/apply'] = array(
  30. 'title' => 'Apply Default Tripal Layout (will reset current layout)',
  31. 'description' => t('Apply the Tripal Display Suite settings to this content type.'),
  32. 'page callback' => 'tripal_ds_apply',
  33. 'access arguments' => array('administer tripal'),
  34. 'page arguments' => array(4),
  35. 'type' => MENU_LOCAL_ACTION,
  36. );
  37. return $items;
  38. }
  39. /**
  40. * Implements hook_bundle_postcreate().
  41. *
  42. * This is a Triapl defined hook and is called in the TripalBundle::create()
  43. * function to allow modules to perform tasks when a bundle is created.
  44. */
  45. function tripal_ds_bundle_postcreate($bundle) {
  46. $bundle_name = $bundle->name;
  47. $instances = field_info_instances('TripalEntity', $bundle_name);
  48. _ds_layout_settings_info($bundle_name, $instances);
  49. }
  50. function tripal_ds_table_column_delete($bundle){
  51. $bundle_name = $bundle->name;
  52. db_delete('tripal_ds')
  53. ->condition('bundle', $bundle_name, '=')
  54. ->execute();
  55. }
  56. function tripal_ds_bundle_delete($bundle){
  57. tripal_ds_table_column_delete($bundle);
  58. }
  59. /*
  60. * Implements hook_ds_layout_info() to define layouts from code in a module for
  61. * display suite
  62. */
  63. function tripal_ds_ds_layout_info() {
  64. $path = drupal_get_path('module', 'tripal_ds');
  65. $layouts = array(
  66. 'tripal_ds_feature' => array(
  67. 'label' => t('Tripal Feature Layout'),
  68. 'path' => $path . '/theme/templates',
  69. 'regions' => array(
  70. 'left' => t('Left'),
  71. 'right' => t('Right'),
  72. ),
  73. 'css' => TRUE,
  74. ),
  75. );
  76. return $layouts;
  77. }
  78. /**
  79. *
  80. * @param $bundle_name
  81. */
  82. function tripal_ds_apply($bundle_name) {
  83. //Build the identifier to check against ds_layout_settings.
  84. $ds_identifier = 'TripalEntity|'.$bundle_name.'|default';
  85. //Check to see if the layout already exists.
  86. $result = db_select('ds_layout_settings', 'ds')
  87. ->fields('ds')
  88. ->condition('id', $ds_identifier, '=')
  89. ->execute()
  90. ->fetchField();
  91. //Check to see if there are any field groups associated with the bundle.
  92. $result_fg = db_select('field_group', 'fg')
  93. ->fields('fg')
  94. ->condition('bundle', $bundle_name, '=')
  95. ->execute()
  96. ->fetchField();
  97. //Check to see if there are any tripal ds fields associated with the bundle.
  98. $result_tds = db_select('tripal_ds', 'tds')
  99. ->fields('tds')
  100. ->condition('bundle', $bundle_name, '=')
  101. ->execute();
  102. //Check to see if there are any field settings associated with the bundle.
  103. $result_fs = db_select('ds_field_settings', 'fs')
  104. ->fields('fs')
  105. ->condition('bundle', $bundle_name, '=')
  106. ->execute();
  107. //If the layout exists, delete it.
  108. if(!empty($result)) {
  109. db_delete('ds_layout_settings')
  110. ->condition('id', $ds_identifier, '=')
  111. ->execute();
  112. }
  113. //Then delete the field_group_fields associated with the identifier.
  114. if(!empty($result_fg)) {
  115. db_delete('field_group')
  116. ->condition('bundle', $bundle_name, '=')
  117. ->execute();
  118. }
  119. //Then delete the ds_field_settings associated with the identifier.
  120. if(!empty($result_tds)) {
  121. db_delete('ds_field_settings')
  122. ->condition('bundle', $bundle_name, '=')
  123. ->execute();
  124. }
  125. //Then delete the tripal_ds menu item.
  126. if(!empty($result_fs)) {
  127. db_delete('tripal_ds')
  128. ->condition('bundle', $bundle_name, '=')
  129. ->execute();
  130. }
  131. //Now you can build the layout fresh.
  132. $instances = field_info_instances('TripalEntity', $bundle_name);
  133. $success = _ds_layout_settings_info($bundle_name, $instances);
  134. if ($success) {
  135. drupal_set_message("Layout applied successfully and saved.");
  136. }
  137. else {
  138. drupal_set_message("Could not apply layout.", 'error');
  139. }
  140. drupal_goto("admin/structure/bio_data/manage/$bundle_name/display");
  141. }
  142. /*
  143. * Code for the view of the menu items
  144. //get tripal entity id from url then run it against tripal entity db
  145. //and grab the bundle id, then pass bundle id to view
  146. $url = current_path();
  147. $url_exploded = explode("/", $url);
  148. $tripal_entity_id = (int)$url_exploded[1];
  149. $result = db_select('tripal_entity', 'te')
  150. ->fields('te', array('bundle'))
  151. ->condition('id', $tripal_entity_id, '=')
  152. ->execute()
  153. ->fetchField();
  154. */