tripal_entities.module 6.9 KB

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