tripal_entities.module 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <?php
  2. require_once "api/tripal_entities.api.inc";
  3. require_once "includes/tripal_entities.field_storage.inc";
  4. require_once "includes/tripal_entities.fields.inc";
  5. require_once "includes/TripalData.inc";
  6. require_once "includes/TripalDataController.inc";
  7. require_once "includes/TripalDataUIController.inc";
  8. require_once "includes/TripalDataType.inc";
  9. require_once "includes/TripalDataTypeController.inc";
  10. require_once "includes/TripalDataTypeUIController.inc";
  11. /**
  12. * Implements hook_views_api().
  13. */
  14. function tripal_entities_views_api() {
  15. return array(
  16. 'api' => 3,
  17. );
  18. }
  19. /**
  20. * Implements hook_menu().
  21. */
  22. function tripal_entities_menu() {
  23. $items = array();
  24. // the administative settings menu
  25. $items['admin/tripal/data_types'] = array(
  26. 'title' => 'Manage Data Types',
  27. 'description' => 'Tools for publishing, configurating and managing biological data.',
  28. 'page callback' => 'tripal_entities_admin_view',
  29. 'access arguments' => array('administer tripal data types'),
  30. 'file' => 'includes/tripal_entities.admin.inc',
  31. 'type' => MENU_NORMAL_ITEM,
  32. );
  33. $items['admin/tripal/data_types/publish'] = array(
  34. 'title' => 'Publish',
  35. 'description' => 'Publish Data',
  36. 'page callback' => 'drupal_get_form',
  37. 'page arguments' => array('tripal_entities_admin_publish_form'),
  38. 'access arguments' => array('administer tripal data types'),
  39. 'file' => 'includes/tripal_entities.admin.inc',
  40. 'type' => MENU_LOCAL_TASK,
  41. 'weight' => 2
  42. );
  43. $items['admin/tripal/data_types/access'] = array(
  44. 'title' => 'Access',
  45. 'description' => 'Set default access permissions for collections of data.',
  46. 'page callback' => 'drupal_get_form',
  47. 'page arguments' => array('tripal_entities_admin_access_form'),
  48. 'access arguments' => array('administer tripal data types'),
  49. 'file' => 'includes/tripal_entities.admin.inc',
  50. 'type' => MENU_LOCAL_TASK,
  51. 'weight' => 3
  52. );
  53. return $items;
  54. }
  55. /**
  56. * Implements hook_permission().
  57. */
  58. function tripal_entities_permission() {
  59. // We set up permisssions to manage entity types, manage all entities and the
  60. // permissions for each individual entity
  61. $permissions = array(
  62. 'administer tripal data types' => array(
  63. 'title' => t('Administer Tripal data types'),
  64. 'description' => t('Create and delete fields for Tripal data types, and set their permissions.'),
  65. ),
  66. 'administer tripal data' => array(
  67. 'title' => t('Administer Tripal data'),
  68. 'description' => t('Edit and delete all tripal data'),
  69. ),
  70. );
  71. // Generate permissions per each data type.
  72. foreach (tripal_data_get_types() as $type) {
  73. $type_name = check_plain($type->type);
  74. $permissions += array(
  75. "edit any $type_name data" => array(
  76. 'title' => t('%type_name: Edit any', array('%type_name' => $type->label)),
  77. ),
  78. "view any $type_name data" => array(
  79. 'title' => t('%type_name: View any', array('%type_name' => $type->label)),
  80. ),
  81. );
  82. }
  83. return $permissions;
  84. }
  85. /**
  86. * Implements hook_theme().
  87. */
  88. function tripal_entities_theme($existing, $type, $theme, $path) {
  89. return array(
  90. 'tripal_data' => array(
  91. 'render element' => 'elements',
  92. 'template' => 'tripal_data',
  93. 'path' => "$path/theme/templates"
  94. ),
  95. );
  96. }
  97. /**
  98. * https://api.drupal.org/api/drupal/modules!rdf!rdf.module/group/rdf/7
  99. */
  100. function tripal_entities_rdf_mapping() {
  101. return array();
  102. /* return array(
  103. 'type' => 'tripal_data',
  104. 'bundle' => 'gene',
  105. 'mapping' => array(
  106. 'rdftype' => array('sioc:Item', 'foaf:Document'),
  107. 'title' => array(
  108. 'predicates' => array('dc:title'),
  109. ),
  110. 'uid' => array(
  111. 'predicates' => array('sioc:has_creator'),
  112. 'type' => 'rel',
  113. ),
  114. 'name' => array(
  115. 'predicates' => array('foaf:name'),
  116. ),
  117. 'uniquename' => array(
  118. 'predicates' => array('foaf:name'),
  119. ),
  120. 'organism_id' => array(
  121. 'predicates' => array('sioc:has_parent'),
  122. 'type' => 'rel'
  123. )
  124. ),
  125. ); */
  126. }
  127. // http://www.bluespark.com/blog/drupal-entities-part-3-programming-hello-drupal-entity
  128. // http://dikini.net/31.08.2010/entities_bundles_fields_and_field_instances
  129. /**
  130. * Implement hook_entity_info().
  131. */
  132. function tripal_entities_entity_info() {
  133. $entities = array();
  134. $entities['tripal_data'] = array(
  135. // A human readable label to identify our entity.
  136. 'label' => t('Tripal Data'),
  137. 'plural label' => t('Tripal Data'),
  138. // The entity class and controller class extend the classes provided by the
  139. // Entity API.
  140. 'entity class' => 'TripalData',
  141. 'controller class' => 'TripalDataController',
  142. // The table for this entity defined in hook_schema()
  143. 'base table' => 'tripal_data',
  144. // Returns the uri elements of an entity.
  145. 'uri callback' => 'tripal_entities_vocbulary_term_uri',
  146. // IF fieldable == FALSE, we can't attach fields.
  147. 'fieldable' => TRUE,
  148. // entity_keys tells the controller what database fields are used for key
  149. // functions. It is not required if we don't have bundles or revisions.
  150. // Here we do not support a revision, so that entity key is omitted.
  151. 'entity keys' => array(
  152. 'id' => 'id',
  153. 'bundle' => 'type',
  154. ),
  155. 'bundle keys' => array(
  156. 'bundle' => 'type',
  157. ),
  158. // Callback function for access to this entity.
  159. 'access callback' => 'tripal_data_access',
  160. // FALSE disables caching. Caching functionality is handled by Drupal core.
  161. 'static cache' => FALSE,
  162. // Bundles are added in the hook_entities_info_alter() function.
  163. 'bundles' => array(),
  164. 'label callback' => 'entity_class_label',
  165. 'creation callback' => 'tripal_data_create',
  166. // The information below is used by the TripalDataUIController
  167. // (which extends the EntityDefaultUIController). The admin_ui
  168. // key here is mean to appear on the 'Find Content' page of the
  169. // administrative menu.
  170. 'admin ui' => array(
  171. 'path' => 'admin/content/data',
  172. 'controller class' => 'TripalDataUIController',
  173. 'menu wildcard' => '%tripal_data',
  174. 'file' => 'includes/TripalDataUIController.inc',
  175. ),
  176. 'view modes' => array(
  177. 'full' => array(
  178. 'label' => t('Full content'),
  179. 'custom settings' => FALSE,
  180. ),
  181. 'teaser' => array(
  182. 'label' => t('Teaser'),
  183. 'custom settings' => TRUE,
  184. ),
  185. ),
  186. );
  187. // The entity that holds information about the entity types
  188. $entities['tripal_data_type'] = array(
  189. 'label' => t('Tripal Data Type'),
  190. 'entity class' => 'TripalDataType',
  191. 'controller class' => 'TripalDataTypeController',
  192. 'base table' => 'tripal_data_type',
  193. 'fieldable' => FALSE,
  194. // If this entity can be used as a bundle of another entity then
  195. // that can be specified via the 'bundle of' key.
  196. 'bundle of' => 'tripal_data',
  197. 'exportable' => TRUE,
  198. 'entity keys' => array(
  199. 'id' => 'id',
  200. 'name' => 'type',
  201. 'label' => 'label',
  202. ),
  203. 'access callback' => 'tripal_data_type_access',
  204. 'module' => 'tripal_entities',
  205. // Enable the entity API's admin UI.
  206. 'admin ui' => array(
  207. 'path' => 'admin/structure/data_types',
  208. 'controller class' => 'TripalDataTypeUIController',
  209. 'file' => 'includes/TripalDataTypeUIController.inc',
  210. ),
  211. );
  212. return $entities;
  213. }
  214. /**
  215. * Implements hook_entity_info_alter().
  216. *
  217. * We are adding the info about the tripal data types via a hook to avoid a
  218. * recursion issue as loading the model types requires the entity info as well.
  219. *
  220. */
  221. function tripal_entities_entity_info_alter(&$entity_info) {
  222. // Bundles are alternative groups of fields or configuration
  223. // associated with a base entity type.
  224. // We want to dynamically add the bundles (or term types) to the entity.
  225. $values = array(
  226. 'cv_id' => array(
  227. 'name' => 'sequence'
  228. ),
  229. 'name' => 'gene',
  230. );
  231. $cvterm = chado_generate_var('cvterm', $values);
  232. $label = preg_replace('/_/', ' ', ucwords($cvterm->name));
  233. $type = $cvterm->dbxref_id->db_id->name . '_' . $cvterm->dbxref_id->accession;
  234. $entity_info['tripal_data']['bundles'][$type] = array(
  235. 'label' => $label,
  236. 'admin' => array(
  237. 'path' => 'admin/structure/data_types/manage/%tripal_data_type',
  238. 'real path' => 'admin/structure/data_types/manage/' . $type,
  239. 'bundle argument' => 4,
  240. 'access arguments' => array('administer tripal data types'),
  241. ),
  242. );
  243. }