tripal_entities.module 7.0 KB

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