tripal_entities.module 6.8 KB

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