tripal_ds.module 4.8 KB

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