tripal_entities.module 6.8 KB

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