tripal_chado.module 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601
  1. <?php
  2. // APPLICATION PROGRAMMER INTERFACE -------------
  3. // Chado API
  4. require_once "api/tripal_chado.api.inc";
  5. require_once 'api/tripal_chado.property.api.inc';
  6. require_once 'api/tripal_chado.query.api.inc';
  7. require_once 'api/tripal_chado.variables.api.inc';
  8. require_once 'api/tripal_chado.schema.api.inc';
  9. require_once 'api/tripal_chado.custom_tables.api.inc';
  10. require_once 'api/tripal_chado.mviews.api.inc';
  11. require_once 'api/tripal_chado.schema_v1.2.api.inc';
  12. require_once 'api/tripal_chado.schema_v1.11.api.inc';
  13. require_once 'api/modules/tripal_chado.analysis.api.inc';
  14. require_once 'api/modules/tripal_chado.contact.api.inc';
  15. require_once 'api/modules/tripal_chado.cv.api.inc';
  16. require_once 'api/modules/tripal_chado.db.api.inc';
  17. require_once 'api/modules/tripal_chado.feature.api.inc';
  18. require_once 'api/modules/tripal_chado.organism.api.inc';
  19. require_once 'api/modules/tripal_chado.pub.api.inc';
  20. require_once 'api/modules/tripal_chado.stock.api.inc';
  21. require_once "includes/tripal_chado.entity.inc";
  22. require_once "includes/tripal_chado.schema.inc";
  23. require_once "includes/tripal_chado.term_storage.inc";
  24. require_once "includes/tripal_chado.field_storage.inc";
  25. tripal_chado_set_globals();
  26. /**
  27. * This function is used to set the global Chado variables
  28. *
  29. * @ingroup tripal_chado
  30. */
  31. function tripal_chado_set_globals() {
  32. // these global variables are meant to be accessed by all Tripal
  33. // modules to find the chado version installed and if Chado is local.
  34. // these variables are stored as globals rather than using the drupal_set_variable
  35. // functions because the Drupal functions make databaes queries and for long
  36. // running loaders we don't want those queries repeatedly.
  37. $GLOBALS["chado_is_installed"] = chado_is_installed();
  38. if ($GLOBALS["chado_is_installed"]) {
  39. $GLOBALS["chado_is_local"] = chado_is_local();
  40. $GLOBALS["chado_version"] = chado_get_version();
  41. $GLOBALS["exact_chado_version"] = chado_get_version(TRUE);
  42. }
  43. }
  44. /**
  45. * Implements hook_init().
  46. * Used to set the search_path, create default content and set default variables.
  47. *
  48. * @ingroup tripal_chado
  49. */
  50. function tripal_chado_init() {
  51. if ($GLOBALS["chado_is_installed"]) {
  52. // Check to see if the Chado and Drupal have been prepared
  53. if (!variable_get('tripal_chado_is_prepared', FALSE)) {
  54. drupal_set_message('Chado is installed but Tripal has not yet prepared Drupal and Chado. Please ' .
  55. l('prepare both Drupal and Chado', 'admin/tripal/storage/chado/chado_prepare') .
  56. ' before continuing.', 'warning');
  57. }
  58. }
  59. else {
  60. drupal_set_message('Tripal cannot find a Chado installation. Please ' .
  61. l('install Chado', 'admin/tripal/storage/chado/chado_install') .
  62. ' before continuing.', 'warning');
  63. }
  64. }
  65. /**
  66. * Implements hook_views_api().
  67. *
  68. * Essentially this hook tells drupal that there is views support for
  69. * for this module which then includes tripal_db.views.inc where all the
  70. * views integration code is
  71. *
  72. * @ingroup tripal_feature
  73. */
  74. function tripal_chado_views_api() {
  75. return array(
  76. 'api' => 3.0,
  77. );
  78. }
  79. /**
  80. * Implements hook_menu().
  81. */
  82. function tripal_chado_menu() {
  83. $items = array();
  84. $items['admin/tripal/storage/term/%/%'] = array(
  85. 'page callback' => 'tripal_autocomplete_cvterm',
  86. 'page arguments' => array(4, 5),
  87. 'access arguments' => array('administer content'),
  88. 'type' => MENU_CALLBACK,
  89. );
  90. //////////////////////////////////////////////////////////////////////////////
  91. // Chado Storage Backend
  92. //////////////////////////////////////////////////////////////////////////////
  93. $items['admin/tripal/storage/chado'] = array(
  94. 'title' => 'Chado',
  95. 'description' => t("Integrates Chado with Tripal and includes tools to
  96. load data, and extend the chado schema through custom tables &
  97. materialized views."),
  98. 'weight' => -100,
  99. 'access arguments' => array('administer tripal'),
  100. );
  101. $items['admin/tripal/storage/chado/chado_install'] = array(
  102. 'title' => 'Install Chado',
  103. 'description' => t('Installs the Chado database tables, views, etc., inside the current Drupal database'),
  104. 'page callback' => 'drupal_get_form',
  105. 'page arguments' => array('tripal_chado_install_form'),
  106. 'type' => MENU_NORMAL_ITEM,
  107. 'access arguments' => array('install chado'),
  108. 'file' => 'includes/tripal_chado.setup.inc',
  109. 'file path' => drupal_get_path('module', 'tripal_chado'),
  110. 'weight' => -100
  111. );
  112. $items['admin/tripal/storage/chado/chado_prepare'] = array(
  113. 'title' => 'Prepare Chado',
  114. 'description' => t('Prepares Drupal to use Chado.'),
  115. 'page callback' => 'drupal_get_form',
  116. 'page arguments' => array('tripal_chado_prepare_form'),
  117. 'type' => MENU_NORMAL_ITEM,
  118. 'access arguments' => array('install chado'),
  119. 'file' => 'includes/tripal_chado.setup.inc',
  120. 'file path' => drupal_get_path('module', 'tripal_chado'),
  121. 'weight' => -99
  122. );
  123. $items['admin/tripal/storage/chado/publish'] = array(
  124. 'title' => 'Publish',
  125. 'description' => t('Publish data that is present in Chado but which does
  126. not yet have a page on this site for viewing. In Tripal v2.0 or
  127. earlier this was refered to as "syncing".'),
  128. 'page callback' => 'drupal_get_form',
  129. 'page arguments' => array('tripal_chado_publish_form'),
  130. 'type' => MENU_NORMAL_ITEM,
  131. 'access arguments' => array('administer tripal'),
  132. 'file' => 'includes/tripal_chado.publish.inc',
  133. 'file path' => drupal_get_path('module', 'tripal_chado'),
  134. 'weight' => -99
  135. );
  136. //////////////////////////////////////////////////////////////////////////////
  137. // Materialized Views
  138. //////////////////////////////////////////////////////////////////////////////
  139. $items['admin/tripal/storage/chado/mviews'] = array(
  140. 'title' => 'Materialized Views',
  141. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  142. 'page callback' => 'tripal_mview_admin_view',
  143. 'access arguments' => array('administer tripal'),
  144. 'type' => MENU_NORMAL_ITEM,
  145. 'file' => 'includes/tripal_chado.mviews.inc',
  146. 'file path' => drupal_get_path('module', 'tripal_chado'),
  147. 'weight' => -10
  148. );
  149. $items['admin/tripal/storage/chado/mviews/help'] = array(
  150. 'title' => 'Help',
  151. 'description' => t('Help for the materialized views management system'),
  152. 'page callback' => 'theme',
  153. 'page arguments' => array('tripal_mviews_help'),
  154. 'access arguments' => array('administer tripal'),
  155. 'type' => MENU_LOCAL_TASK,
  156. 'file' => 'includes/tripal_chado.mviews.inc',
  157. 'file path' => drupal_get_path('module', 'tripal_chado'),
  158. 'weight' => 10
  159. );
  160. $items['admin/tripal/storage/chado/mviews/report/%'] = array(
  161. 'title' => 'Materialized View',
  162. 'description' => t('Materialized views are used to improve speed of large or complex queries. These are database views as compared to Drupal views.'),
  163. 'page callback' => 'tripal_mview_report',
  164. 'page arguments' => array(6),
  165. 'access arguments' => array('administer tripal'),
  166. 'type' => MENU_CALLBACK,
  167. 'file' => 'includes/tripal_chado.mviews.inc',
  168. 'file path' => drupal_get_path('module', 'tripal_chado'),
  169. );
  170. $items['admin/tripal/storage/chado/mviews/new'] = array(
  171. 'title' => 'Create Materialized View',
  172. 'description' => t('Create a new materialized view.'),
  173. 'page callback' => 'drupal_get_form',
  174. 'page arguments' => array('tripal_mviews_form'),
  175. 'access arguments' => array('administer tripal'),
  176. 'type' => MENU_CALLBACK,
  177. 'file' => 'includes/tripal_chado.mviews.inc',
  178. 'file path' => drupal_get_path('module', 'tripal_chado'),
  179. );
  180. $items['admin/tripal/storage/chado/mviews/edit/%'] = array(
  181. 'title' => 'Edit Materialized View',
  182. 'page callback' => 'drupal_get_form',
  183. 'page arguments' => array('tripal_mviews_form', 6),
  184. 'access arguments' => array('administer tripal'),
  185. 'type' => MENU_CALLBACK,
  186. 'file' => 'includes/tripal_chado.mviews.inc',
  187. 'file path' => drupal_get_path('module', 'tripal_chado'),
  188. );
  189. $items['admin/tripal/storage/chado/mviews/update/%'] = array(
  190. 'title' => 'Create Materialized View',
  191. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  192. 'page callback' => 'tripal_mviews_add_populate_job',
  193. 'page arguments' => array(6),
  194. 'access arguments' => array('administer tripal'),
  195. 'type' => MENU_CALLBACK,
  196. 'file' => 'includes/tripal_chado.mviews.inc',
  197. 'file path' => drupal_get_path('module', 'tripal_chado'),
  198. );
  199. $items['admin/tripal/storage/chado/mviews/delete/%'] = array(
  200. 'title' => 'Create Materialized View',
  201. 'description' => t('Materialized views are used to improve speed of large or complex queries.'),
  202. 'page callback' => 'drupal_get_form',
  203. 'page arguments' => array('tripal_mviews_delete_form', 5),
  204. 'access arguments' => array('administer tripal'),
  205. 'type' => MENU_CALLBACK,
  206. 'file' => 'includes/tripal_chado.mviews.inc',
  207. 'file path' => drupal_get_path('module', 'tripal_chado'),
  208. );
  209. // TODO: complete the code for exporting and importing of MViews.
  210. // Need to address security issues of sharing SQL.
  211. $items['admin/tripal/storage/chado/mviews/import'] = array(
  212. 'title' => 'Import MView',
  213. 'description' => 'Import a materialized view from another Tripal instance.',
  214. 'page callback' => 'drupal_get_form',
  215. 'page arguments' => array('tripal_mviews_import_form'),
  216. 'access arguments' => array('administer tripal'),
  217. 'type' => MENU_CALLBACK,
  218. 'file' => 'includes/tripal_chado.mviews.inc',
  219. 'file path' => drupal_get_path('module', 'tripal_chado'),
  220. );
  221. $items['admin/tripal/storage/chado/mviews/%tblid/export'] = array(
  222. 'title' => 'Export MView',
  223. 'description' => 'Export a materialized view for use by another Tripal instance.',
  224. 'page callback' => 'drupal_get_form',
  225. 'page arguments' => array('tripal_mviews_export_form', 5),
  226. 'access arguments' => array('administer tripal'),
  227. 'type' => MENU_CALLBACK,
  228. 'file' => 'includes/tripal_chado.mviews.inc',
  229. 'file path' => drupal_get_path('module', 'tripal_chado'),
  230. );
  231. //////////////////////////////////////////////////////////////////////////////
  232. // Custom Tables
  233. //////////////////////////////////////////////////////////////////////////////
  234. $items['admin/tripal/storage/chado/custom_tables'] = array(
  235. 'title' => 'Custom Tables',
  236. 'description' => t('Creation of custom tables that are added to Chado database.'),
  237. 'page callback' => 'tripal_custom_table_admin_view',
  238. 'access arguments' => array('administer tripal'),
  239. 'type' => MENU_NORMAL_ITEM,
  240. 'file' => 'includes/tripal_chado.custom_tables.inc',
  241. 'file path' => drupal_get_path('module', 'tripal_chado'),
  242. 'weight' => -10
  243. );
  244. $items['admin/tripal/storage/chado/custom_tables/help'] = array(
  245. 'title' => 'Help',
  246. 'description' => t('Help for the tripal job management system'),
  247. 'page callback' => 'theme',
  248. 'page arguments' => array('tripal_job_help'),
  249. 'access arguments' => array('administer tripal'),
  250. 'type' => MENU_LOCAL_TASK,
  251. 'file' => 'includes/tripal_chado.custom_tables.inc',
  252. 'file path' => drupal_get_path('module', 'tripal_chado'),
  253. 'weight' => 10
  254. );
  255. $items['admin/tripal/storage/chado/custom_tables/view/%'] = array(
  256. 'title' => 'Custom Tables',
  257. 'description' => t('Custom tables are added to Chado.'),
  258. 'page callback' => 'tripal_custom_table_view',
  259. 'page arguments' => array(6),
  260. 'access arguments' => array('administer tripal'),
  261. 'file' => 'includes/tripal_chado.custom_tables.inc',
  262. 'file path' => drupal_get_path('module', 'tripal_chado'),
  263. 'type' => MENU_CALLBACK,
  264. );
  265. $items['admin/tripal/storage/chado/custom_tables/new'] = array(
  266. 'title' => 'Create Custom Table',
  267. 'description' => t('An interface for creating your own custom tables.'),
  268. 'page callback' => 'tripal_custom_table_new_page',
  269. 'access arguments' => array('administer tripal'),
  270. 'file' => 'includes/tripal_chado.custom_tables.inc',
  271. 'file path' => drupal_get_path('module', 'tripal_chado'),
  272. 'type' => MENU_CALLBACK,
  273. );
  274. $items['admin/tripal/storage/chado/custom_tables/edit/%'] = array(
  275. 'title' => 'Edit Custom Table',
  276. 'page callback' => 'drupal_get_form',
  277. 'page arguments' => array('tripal_custom_tables_form', 6),
  278. 'access arguments' => array('administer tripal'),
  279. 'file' => 'includes/tripal_chado.custom_tables.inc',
  280. 'file path' => drupal_get_path('module', 'tripal_chado'),
  281. 'type' => MENU_CALLBACK,
  282. );
  283. $items['admin/tripal/storage/chado/custom_tables/delete/%'] = array(
  284. 'title' => 'Create Custom Table',
  285. 'description' => t('Custom tables are added to Chado.'),
  286. 'page callback' => 'drupal_get_form',
  287. 'page arguments' => array('tripal_custom_tables_delete_form', 6),
  288. 'access arguments' => array('administer tripal'),
  289. 'file' => 'includes/tripal_chado.custom_tables.inc',
  290. 'file path' => drupal_get_path('module', 'tripal_chado'),
  291. 'type' => MENU_CALLBACK,
  292. );
  293. $items['admin/tripal/storage/chado/custom_tables/views/tables/enable'] = array(
  294. 'title' => 'Enable Custom Tables Administrative View',
  295. 'page callback' => 'tripal_enable_view',
  296. 'page arguments' => array('tripal_admin_custom_table', 'admin/tripal/storage/chado/custom_tables'),
  297. 'access arguments' => array('administer tripal'),
  298. 'file' => 'includes/tripal_chado.custom_tables.inc',
  299. 'file path' => drupal_get_path('module', 'tripal_chado'),
  300. 'type' => MENU_CALLBACK,
  301. );
  302. //////////////////////////////////////////////////////////////////////////////
  303. // Data Loaders
  304. //////////////////////////////////////////////////////////////////////////////
  305. $items['admin/tripal/storage/chado/loaders'] = array(
  306. 'title' => 'Data Loaders',
  307. 'description' => t('Tools facilitating data import.'),
  308. 'access arguments' => array('administer tripal'),
  309. 'type' => MENU_NORMAL_ITEM,
  310. 'weight' => 6
  311. );
  312. $items['admin/tripal/storage/chado/loaders/fasta_loader'] = array(
  313. 'title' => 'FASTA file Loader',
  314. 'description' => 'Load sequences from a multi-FASTA file into Chado',
  315. 'page callback' => 'drupal_get_form',
  316. 'page arguments' => array('tripal_feature_fasta_load_form'),
  317. 'access arguments' => array('administer tripal feature'),
  318. 'file' => 'includes/loaders/tripal_chado.fasta_loader.inc',
  319. 'file path' => drupal_get_path('module', 'tripal_chado'),
  320. 'type' => MENU_NORMAL_ITEM,
  321. );
  322. $items['admin/tripal/storage/chado/loaders/gff3_load'] = array(
  323. 'title' => 'GFF3 file Loader',
  324. 'description' => 'Import a GFF3 file into Chado',
  325. 'page callback' => 'drupal_get_form',
  326. 'page arguments' => array('tripal_feature_gff3_load_form'),
  327. 'access arguments' => array('administer tripal feature'),
  328. 'file' => 'includes/loaders/tripal_chado.gff_loader.inc',
  329. 'file path' => drupal_get_path('module', 'tripal_chado'),
  330. 'type' => MENU_NORMAL_ITEM,
  331. );
  332. //////////////////////////////////////////////////////////////////////////////
  333. // Auto Completes
  334. //////////////////////////////////////////////////////////////////////////////
  335. $items['admin/tripal/storage/chado/auto_name/dbxref/%/%'] = array(
  336. 'page callback' => 'tripal_autocomplete_dbxref',
  337. 'page arguments' => array(6, 7),
  338. 'access arguments' => array('access content'),
  339. 'file' => 'api/modules/tripal_chado.db.api.inc',
  340. 'file path' => drupal_get_path('module', 'tripal_chado'),
  341. 'type' => MENU_CALLBACK,
  342. );
  343. $items['admin/tripal/storage/chado/auto_name/cvterm/%/%'] = array(
  344. 'page callback' => 'tripal_autocomplete_cvterm',
  345. 'page arguments' => array(6, 7),
  346. 'access arguments' => array('access content'),
  347. 'file' => 'api/modules/tripal_chado.db.api.inc',
  348. 'file path' => drupal_get_path('module', 'tripal_chado'),
  349. 'type' => MENU_CALLBACK,
  350. );
  351. return $items;
  352. }
  353. /**
  354. * Implements hook_permission().
  355. *
  356. * Set the permission types that the chado module uses. Essentially we
  357. * want permissionis that protect creation, editing and deleting of chado
  358. * data objects
  359. *
  360. * @ingroup tripal
  361. */
  362. function tripal_chado_permission() {
  363. return array(
  364. 'install chado' => array(
  365. 'title' => t('Install Chado'),
  366. 'description' => t('Allow the user to install or upgrade a Chado database in the existing Drupal database.')
  367. ),
  368. 'view chado_ids' => array(
  369. 'title' => t('View Internal IDs'),
  370. 'description' => t('On content pages Tripal will typically provide
  371. a table of information pulled from the Chado database but the
  372. primary key IDs for that data is typically not shown. The
  373. default Tripal templates can show the primary key ID inside of a
  374. blue shaded table row if this permission is enabled. This can
  375. be useful for site developers who might want these IDs when working
  376. with the underlying database.'),
  377. 'restrict access' => TRUE,
  378. )
  379. );
  380. }
  381. /**
  382. * Implements hook_field_info().
  383. */
  384. function tripal_chado_field_info() {
  385. $fields = array(
  386. 'organism_id' => array(
  387. 'label' => t('Organism'),
  388. 'description' => t('A field for specifying an organism.'),
  389. 'default_widget' => 'tripal_chado_organism_select_widget',
  390. 'default_formatter' => 'tripal_chado_organism_formatter',
  391. 'settings' => array(),
  392. 'storage' => array(
  393. 'type' => 'field_chado_storage',
  394. 'module' => 'tripal_chado',
  395. 'active' => TRUE
  396. ),
  397. ),
  398. 'dbxref_id' => array(
  399. 'label' => t('Cross reference'),
  400. 'description' => t('This record can be cross referenced with a record in
  401. another online database. This field is intended for the most prominent
  402. reference. At a minimum, the database and accession must be provided.'),
  403. 'default_widget' => 'tripal_chado_dbxref_id_widget',
  404. 'default_formatter' => 'tripal_chado_dbxref_id_formatter',
  405. 'settings' => array(),
  406. 'storage' => array(
  407. 'type' => 'field_chado_storage',
  408. 'module' => 'tripal_chado',
  409. 'active' => TRUE
  410. ),
  411. ),
  412. 'residues' => array(
  413. 'label' => t('Residues'),
  414. 'description' => t('A field for managing nucleotide and protein residues.'),
  415. 'default_widget' => 'tripal_chado_residue_textarea_widget',
  416. 'default_formatter' => 'tripal_chado_residues_formatter',
  417. 'settings' => array(),
  418. 'storage' => array(
  419. 'type' => 'field_chado_storage',
  420. 'module' => 'tripal_chado',
  421. 'active' => TRUE
  422. ),
  423. ),
  424. 'md5checksum' => array(
  425. 'label' => t('MD5 checksum'),
  426. 'description' => t('A field for generating MD5 checksum for a sequence.'),
  427. 'default_widget' => 'tripal_chado_md5checksum_checkbox_widget',
  428. 'default_formatter' => 'tripal_chado_md5checksum_formatter',
  429. 'settings' => array(),
  430. 'storage' => array(
  431. 'type' => 'field_chado_storage',
  432. 'module' => 'tripal_chado',
  433. 'active' => TRUE
  434. ),
  435. ),
  436. 'seqlen' => array(
  437. 'label' => t('Sequence length'),
  438. 'description' => t('A field for calculating the length of a sequence.'),
  439. 'default_widget' => 'tripal_chado_seqlen_hidden_widget',
  440. 'default_formatter' => 'tripal_chado_seqlen_formatter',
  441. 'settings' => array(),
  442. 'storage' => array(
  443. 'type' => 'field_chado_storage',
  444. 'module' => 'tripal_chado',
  445. 'active' => TRUE
  446. ),
  447. ),
  448. // The field provides a widget for adding new properties
  449. // to an entity that is connected to a base table that has a prop table
  450. // in Chado.
  451. 'kvproperty_adder' => array(
  452. 'label' => t('Add a Property Type'),
  453. 'description' => t('This record may have any number of properties. Use
  454. this field to first add the type.'),
  455. 'default_widget' => 'tripal_chado_kvproperty_adder_widget',
  456. //'default_formatter' => 'tripal_chado_kvproperty_adder_formatter',
  457. 'default_formatter' => 'hidden',
  458. 'settings' => array(),
  459. 'storage' => array(
  460. 'type' => 'field_chado_storage',
  461. 'module' => 'tripal_chado',
  462. 'active' => TRUE
  463. ),
  464. ),
  465. // The field provides form elements for adding a property to an entity
  466. // that in turn gets stored in a prop table of Chado (e.g. featureprop,
  467. // stockprop, etc).
  468. 'kvproperty' => array(
  469. 'label' => t('Add a Property'),
  470. 'description' => t('Add details about this property.'),
  471. 'default_widget' => 'tripal_chado_kvproperty_widget',
  472. 'default_formatter' => 'tripal_chado_kvproperty_formatter',
  473. 'settings' => array(),
  474. 'storage' => array(
  475. 'type' => 'field_chado_storage',
  476. 'module' => 'tripal_chado',
  477. 'active' => TRUE
  478. ),
  479. ),
  480. // The field provides form elements for adding multiple dbxrefs to an
  481. // entity that in turn get stored in a [base]_dbxref table of Chado
  482. // (e.g. organism_dbxref, feature_dbxref). This is different
  483. // from the dbxref_id field as that is specific to a dbxref_id in
  484. // a base table.
  485. 'dbxref' => array(
  486. 'label' => t('Cross references'),
  487. 'description' => t('This record can be cross referenced with a record in
  488. another online database. This field is intended for one or more
  489. references. At a minimum, the database and accession must be provided.'),
  490. 'default_widget' => 'tripal_chado_dbxref_widget',
  491. 'default_formatter' => 'tripal_chado_dbxref_formatter',
  492. 'settings' => array(),
  493. 'storage' => array(
  494. 'type' => 'field_chado_storage',
  495. 'module' => 'tripal_chado',
  496. 'active' => TRUE
  497. ),
  498. ),
  499. // The field provides a widget for adding new vocabularies for cvterm
  500. // linker tables. This will allow cvterms to be grouped by vocabulary
  501. // ('category').
  502. 'cvterm_class_adder' => array(
  503. 'label' => t('Add an Annotation Type'),
  504. 'description' => t('This record may have any number of types of
  505. annotations. Use this field to first add the type.'),
  506. 'default_widget' => 'tripal_chado_cvterm_class_adder_widget',
  507. //'default_formatter' => 'tripal_chado_cvterm_class_adder_formatter',
  508. 'default_formatter' => 'hidden',
  509. 'settings' => array(),
  510. 'storage' => array(
  511. 'type' => 'field_chado_storage',
  512. 'module' => 'tripal_chado',
  513. 'active' => TRUE
  514. ),
  515. ),
  516. // The field provides form elements for adding multiple cvterms to an
  517. // entity that in turn get stored in a [base]_cvterm table of Chado
  518. // (e.g. feature_cvterm).
  519. 'cvterm' => array(
  520. 'label' => t('Annotations'),
  521. 'description' => t('This record can be annotated with terms
  522. from other vocabularies.'),
  523. 'default_widget' => 'tripal_chado_cvterm_widget',
  524. 'default_formatter' => 'tripal_chado_cvterm_formatter',
  525. 'settings' => array(),
  526. 'storage' => array(
  527. 'type' => 'field_chado_storage',
  528. 'module' => 'tripal_chado',
  529. 'active' => TRUE
  530. ),
  531. ),
  532. );
  533. return $fields;
  534. }
  535. /**
  536. * Implements hook_field_widget_info().
  537. */
  538. function tripal_chado_field_widget_info() {
  539. return array(
  540. 'tripal_chado_organism_select_widget' => array(
  541. 'label' => t('Organism Select'),
  542. 'field types' => array('organism_id')
  543. ),
  544. 'tripal_chado_dbxref_id_widget' => array(
  545. 'label' => t('Cross reference'),
  546. 'field types' => array('dbxref_id'),
  547. 'description' => t('This record can be cross referenced with a record in
  548. another online database. This field is intended for the most
  549. prominent reference. At a minimum, the database and accession
  550. must be provided.'),
  551. ),
  552. 'tripal_chado_dbxref_widget' => array(
  553. 'label' => t('Cross references'),
  554. 'field types' => array('dbxref'),
  555. 'description' => t('This record can be cross referenced with a record
  556. in another online database. This field is intended for the most
  557. prominent reference. At a minimum, the database and accession
  558. must be provided.'),
  559. ),
  560. 'tripal_chado_cvterm_class_adder_widget' => array(
  561. 'label' => t('Add an Annotation'),
  562. 'field types' => array('cvterm_class_adder'),
  563. ),
  564. 'tripal_chado_cvterm_widget' => array(
  565. 'label' => t('Annotations'),
  566. 'field types' => array('cvterm'),
  567. 'description' => t('This record can be annotated with terms
  568. from other vocabularies.'),
  569. ),
  570. 'tripal_chado_md5checksum_checkbox_widget' => array(
  571. 'label' => t('MD5 Checksum Checkbox'),
  572. 'field types' => array('md5checksum'),
  573. ),
  574. 'tripal_chado_residues_textarea_widget' => array(
  575. 'label' => t('Residues'),
  576. 'field types' => array('residues'),
  577. ),
  578. 'tripal_chado_seqlen_hidden_widget' => array(
  579. 'label' => t('Sequence Length'),
  580. 'field types' => array('seqlen'),
  581. ),
  582. 'tripal_chado_kvproperty_adder_widget' => array(
  583. 'label' => t('Add a Property'),
  584. 'field types' => array('kvproperty_adder'),
  585. ),
  586. 'tripal_chado_kvproperty_widget' => array(
  587. 'label' => t('Property'),
  588. 'field types' => array('kvproperty'),
  589. ),
  590. );
  591. }
  592. /**
  593. * Implements hook_field_formatter_info().
  594. */
  595. function tripal_chado_field_formatter_info() {
  596. return array(
  597. 'tripal_chado_organism_formatter' => array(
  598. 'label' => t('Organism'),
  599. 'field types' => array('organism_id')
  600. ),
  601. 'tripal_chado_dbxref_id_formatter' => array(
  602. 'label' => t('Cross reference'),
  603. 'field types' => array('dbxref_id')
  604. ),
  605. 'tripal_chado_dbxref_formatter' => array(
  606. 'label' => t('Cross references'),
  607. 'field types' => array('dbxref')
  608. ),
  609. 'tripal_chado_cvterm_class_adder_formatter' => array(
  610. 'label' => t('Add an Annotation'),
  611. 'field types' => array('cvterm_class_adder')
  612. ),
  613. 'tripal_chado_cvterm_formatter' => array(
  614. 'label' => t('Annotations'),
  615. 'field types' => array('cvterm')
  616. ),
  617. 'tripal_chado_md5checksum_formatter' => array(
  618. 'label' => t('MD5 checksum'),
  619. 'field types' => array('md5checksum')
  620. ),
  621. 'tripal_chado_residues_formatter' => array(
  622. 'label' => t('Residues'),
  623. 'field types' => array('residues')
  624. ),
  625. 'tripal_chado_seqlen_formatter' => array(
  626. 'label' => t('Sequence length'),
  627. 'field types' => array('seqlen')
  628. ),
  629. 'tripal_chado_kvproperty_adder_formatter' => array(
  630. 'label' => t('Add a Property'),
  631. 'field types' => array('kvproperty_adder')
  632. ),
  633. 'tripal_chado_kvproperty_formatter' => array(
  634. 'label' => t('Property'),
  635. 'field types' => array('kvproperty')
  636. ),
  637. );
  638. }
  639. /**
  640. * Implements hook_field_widget_form_alter().
  641. */
  642. function tripal_chado_field_widget_form_alter(&$element, &$form_state, $context) {
  643. if (array_key_exists('#field_name', $element)) {
  644. $field_name = $element['#field_name'];
  645. $matches = array();
  646. if (preg_match('/(.+?)__(.+?)$/', $field_name, $matches)) {
  647. $tablename = $matches[1];
  648. $colname = $matches[2];
  649. $schema = chado_get_schema($tablename);
  650. // The timelastmodified field exists in many Chado tables. We want
  651. // the form element to update to the most recent time rather than the time
  652. // in the database.
  653. if ($colname == 'timelastmodified' and $schema['fields'][$colname]['type'] == 'datetime') {
  654. // We want the default value for the field to be the current time.
  655. $element['#default_value']['value'] = format_date(time(), 'custom', "Y-m-d H:i:s", 'UTC');
  656. $element['#date_items']['value'] = $element['#default_value']['value'];
  657. }
  658. // We want the date combo fieldset to be collaspible so we will
  659. // add our own theme_wrapper to replace the one added by the date
  660. // module.
  661. if (array_key_exists($colname, $schema['fields']) and $schema['fields'][$colname]['type'] == 'datetime') {
  662. $element['#theme_wrappers'] = array('tripal_chado_date_combo');
  663. }
  664. }
  665. }
  666. }
  667. /**
  668. * Implements hook_field_formatter_view().
  669. */
  670. function tripal_chado_field_formatter_view($entity_type, $entity, $field,
  671. $instance, $langcode, $items, $display) {
  672. $element = array();
  673. switch ($display['type']) {
  674. case 'tripal_chado_organism_formatter':
  675. module_load_include('inc', 'tripal_chado', 'includes/fields/organism_id');
  676. tripal_chado_organism_select_formatter($element, $entity_type, $entity, $field,
  677. $instance, $langcode, $items, $display);
  678. break;
  679. case 'tripal_chado_dbxref_id_formatter':
  680. module_load_include('inc', 'tripal_chado', 'includes/fields/dbxref_id');
  681. tripal_chado_dbxref_id_formatter($element, $entity_type, $entity, $field,
  682. $instance, $langcode, $items, $display);
  683. break;
  684. case 'tripal_chado_dbxref_formatter':
  685. module_load_include('inc', 'tripal_chado', 'includes/fields/dbxref');
  686. tripal_chado_dbxref_formatter($element, $entity_type, $entity, $field,
  687. $instance, $langcode, $items, $display);
  688. break;
  689. case 'tripal_chado_cvterm_class_adder_formatter':
  690. module_load_include('inc', 'tripal_chado', 'includes/fields/cvterm_class_adder');
  691. tripal_chado_cvterm_class_adder_formatter($element, $entity_type, $entity, $field,
  692. $instance, $langcode, $items, $display);
  693. break;
  694. case 'tripal_chado_cvterm_formatter':
  695. module_load_include('inc', 'tripal_chado', 'includes/fields/cvterm');
  696. tripal_chado_cvterm_formatter($element, $entity_type, $entity, $field,
  697. $instance, $langcode, $items, $display);
  698. break;
  699. case 'tripal_chado_md5checksum_formatter':
  700. module_load_include('inc', 'tripal_chado', 'includes/fields/md5checksum');
  701. tripal_chado_md5checksum_checkbox_formatter($element, $entity_type, $entity, $field,
  702. $instance, $langcode, $items, $display);
  703. break;
  704. case 'tripal_chado_residues_formatter':
  705. module_load_include('inc', 'tripal_chado', 'includes/fields/residues');
  706. tripal_chado_residues_textarea_formatter($element, $entity_type, $entity, $field,
  707. $instance, $langcode, $items, $display);
  708. break;
  709. case 'tripal_chado_seqlen_formatter':
  710. module_load_include('inc', 'tripal_chado', 'includes/fields/seqlen');
  711. tripal_chado_seqlen_hidden_formatter($element, $entity_type, $entity, $field,
  712. $instance, $langcode, $items, $display);
  713. break;
  714. case 'tripal_chado_kvproperty_adder_formatter':
  715. module_load_include('inc', 'tripal_chado', 'includes/fields/kvproperty_adder');
  716. tripal_chado_kvproperty_adder_formatter($element, $entity_type, $entity, $field,
  717. $instance, $langcode, $items, $display);
  718. break;
  719. case 'tripal_chado_kvproperty_formatter':
  720. module_load_include('inc', 'tripal_chado', 'includes/fields/kvproperty');
  721. tripal_chado_kvproperty_formatter($element, $entity_type, $entity, $field,
  722. $instance, $langcode, $items, $display);
  723. break;
  724. }
  725. return $element;
  726. }
  727. /**
  728. * Implements hook_field_widget_form().
  729. */
  730. function tripal_chado_field_widget_form(&$form, &$form_state, $field,
  731. $instance, $langcode, $items, $delta, $element) {
  732. $widget = $element;
  733. switch ($instance['widget']['type']) {
  734. case 'tripal_chado_organism_select_widget':
  735. // Make sure the include files get parsed now and for the form submits.
  736. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/organism_id');
  737. module_load_include('inc', 'tripal_chado', 'includes/fields/organism_id');
  738. // Update the widget with the new field.
  739. tripal_chado_organism_select_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  740. break;
  741. case 'tripal_chado_dbxref_id_widget':
  742. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/dbxref_id');
  743. module_load_include('inc', 'tripal_chado', 'includes/fields/dbxref_id');
  744. tripal_chado_dbxref_id_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  745. break;
  746. case 'tripal_chado_dbxref_widget':
  747. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/dbxref');
  748. module_load_include('inc', 'tripal_chado', 'includes/fields/dbxref');
  749. tripal_chado_dbxref_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  750. break;
  751. case 'tripal_chado_cvterm_class_adder_widget':
  752. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/cvterm_class_adder');
  753. module_load_include('inc', 'tripal_chado', 'includes/fields/cvterm_class_adder');
  754. tripal_chado_cvterm_class_adder_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  755. break;
  756. case 'tripal_chado_cvterm_widget':
  757. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/cvterm');
  758. module_load_include('inc', 'tripal_chado', 'includes/fields/cvterm');
  759. tripal_chado_cvterm_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  760. break;
  761. case 'tripal_chado_md5checksum_checkbox_widget':
  762. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/md5checksum');
  763. module_load_include('inc', 'tripal_chado', 'includes/fields/md5checksum');
  764. tripal_chado_md5checksum_checkbox_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  765. break;
  766. case 'tripal_chado_residues_textarea_widget':
  767. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/residues');
  768. module_load_include('inc', 'tripal_chado', 'includes/fields/residues');
  769. tripal_chado_residues_textarea_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  770. break;
  771. case 'tripal_chado_seqlen_hidden_widget':
  772. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/seqlen');
  773. module_load_include('inc', 'tripal_chado', 'includes/fields/seqlen');
  774. tripal_chado_seqlen_hidden_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  775. break;
  776. case 'tripal_chado_kvproperty_adder_widget':
  777. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/kvproperty_adder');
  778. module_load_include('inc', 'tripal_chado', 'includes/fields/kvproperty_adder');
  779. tripal_chado_kvproperty_adder_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  780. break;
  781. case 'tripal_chado_kvproperty_widget':
  782. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/kvproperty');
  783. module_load_include('inc', 'tripal_chado', 'includes/fields/kvproperty');
  784. tripal_chado_kvproperty_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  785. break;
  786. }
  787. return $widget;
  788. }
  789. /**
  790. * Implements hook_form_FORM_ID_alter().
  791. *
  792. * The field_ui_display_overview_form is used for formatting the display
  793. * or layout of fields attached to an entity and shown on the entity view page.
  794. *
  795. * This function removes the cvterm class and property adder field as those are
  796. * really not meant for users to show or manage.
  797. */
  798. function tripal_chado_form_field_ui_display_overview_form_alter(&$form, &$form_state, $form_id) {
  799. // Remove the kvproperty_addr field as it isn't ever displayed. It's just used
  800. // on the add/edit form of an entity for adding new property fields.
  801. $fields_names = element_children($form['fields']);
  802. foreach ($fields_names as $field_name) {
  803. $field_info = field_info_field($field_name);
  804. if ($field_info['type'] == 'kvproperty_adder') {
  805. unset($form['fields'][$field_name]);
  806. }
  807. if ($field_info['type'] == 'cvterm_class_adder') {
  808. unset($form['fields'][$field_name]);
  809. }
  810. }
  811. }
  812. /**
  813. * Implements hook_form_FORM_ID_alter().
  814. *
  815. * The field_ui_field_overview_form is used for ordering and configuring the
  816. * fields attached to an entity.
  817. *
  818. * This function removes the property adder field as that is really not meant
  819. * for users to show or manage.
  820. */
  821. function tripal_chado_form_field_ui_field_overview_form_alter(&$form, &$form_state, $form_id) {
  822. // Remove the kvproperty_addr field as it isn't ever displayed. It's just used
  823. // on the add/edit form of an entity for adding new property fields.
  824. $fields_names = element_children($form['fields']);
  825. foreach ($fields_names as $field_name) {
  826. $field_info = field_info_field($field_name);
  827. if ($field_info['type'] == 'kvproperty_adder') {
  828. unset($form['fields'][$field_name]);
  829. }
  830. if ($field_info['type'] == 'cvterm_class_adder') {
  831. unset($form['fields'][$field_name]);
  832. }
  833. }
  834. }
  835. /**
  836. * Implements hook_field_is_empty().
  837. */
  838. function tripal_chado_field_is_empty($item, $field) {
  839. // If there is no value field then the field is empty.
  840. if (!array_key_exists('value', $item)) {
  841. return TRUE;
  842. }
  843. // Iterate through all of the fields and if at least one has a value
  844. // the field is not empty.
  845. foreach ($item as $form_field_name => $value) {
  846. if (isset($value) and $value != NULL and $value != '') {
  847. return FALSE;
  848. }
  849. }
  850. // Otherwise, the field is empty.
  851. return TRUE;
  852. }
  853. /**
  854. * Returns the values of the field from the $form_state.
  855. */
  856. function tripal_chado_get_field_form_values($field_name, $form_state, $delta = 0, $child = NULL) {
  857. $value = NULL;
  858. // The form_state must have the 'values' key. If not then just return.
  859. if (!array_key_exists('values', $form_state)) {
  860. return $value;
  861. }
  862. // If the field name is not in the form_state['values'] then return.
  863. if (!array_key_exists($field_name, $form_state['values'])) {
  864. return $value;
  865. }
  866. // Iterate through the values looking for the field_name provided.
  867. foreach ($form_state['values'][$field_name] as $langcode => $items) {
  868. if (!array_key_exists($delta, $items)) {
  869. continue;
  870. }
  871. $item = $items[$delta];
  872. if ($child){
  873. if(array_key_exists($child, $item) and $item[$child] != '') {
  874. $value = $item[$child];
  875. }
  876. }
  877. else {
  878. $value = $item['value'];
  879. }
  880. }
  881. return $value;
  882. }
  883. /**
  884. * Sets the values of the field from the $form_state.
  885. */
  886. function tripal_chado_set_field_form_values($field_name, &$form_state, $newvalue, $delta = 0, $child = NULL) {
  887. // The form_state must have the 'values' key. If not then just return.
  888. if (!array_key_exists('values', $form_state)) {
  889. return FALSE;
  890. }
  891. // If the field name is not in the form_state['values'] then reutrn.
  892. if (!array_key_exists($field_name, $form_state['values'])) {
  893. return FALSE;
  894. }
  895. foreach ($form_state['values'][$field_name] as $langcode => $items) {
  896. if ($child) {
  897. $form_state['values'][$field_name][$langcode][$delta][$child] = $newvalue;
  898. }
  899. else {
  900. $form_state['values'][$field_name][$langcode][$delta]['value'] = $newvalue;
  901. }
  902. }
  903. return TRUE;
  904. }
  905. /**
  906. * Implements hook_theme().
  907. */
  908. function tripal_chado_theme($existing, $type, $theme, $path) {
  909. return array(
  910. 'tripal_chado_dbxref_id_widget' => array(
  911. 'render element' => 'element',
  912. 'file' => 'includes/fields/dbxref_id.inc',
  913. ),
  914. 'tripal_chado_dbxref_widget' => array(
  915. 'render element' => 'element',
  916. 'file' => 'includes/fields/dbxref.inc',
  917. ),
  918. 'tripal_chado_cvterm_widget' => array(
  919. 'render element' => 'element',
  920. 'file' => 'includes/fields/cvterm.inc',
  921. ),
  922. 'tripal_chado_kvproperty_addr_widget' => array(
  923. 'render element' => 'element',
  924. 'file' => 'includes/fields/dbxref_id.inc',
  925. ),
  926. 'tripal_chado_date_combo' => array(
  927. 'render element' => 'element',
  928. 'file' => 'theme/tripal_chado.theme.inc',
  929. ),
  930. );
  931. }
  932. /**
  933. * Implements hook_add_bundle_fields().
  934. */
  935. function tripal_chado_add_bundle_fields($entity_type, $bundle, $term) {
  936. $bundle_name = $bundle->name;
  937. // This array will hold details that map the bundle to tables in Chado.
  938. $bundle_data = array();
  939. // Get the cvterm that corresponds to this TripalTerm object.
  940. $vocab = entity_load('TripalVocab', array($term->vocab_id));
  941. $vocab = reset($vocab);
  942. $match = array(
  943. 'dbxref_id' => array(
  944. 'db_id' => array(
  945. 'name' => $vocab->namespace,
  946. ),
  947. 'accession' => $term->accession
  948. ),
  949. );
  950. $cvterm = chado_generate_var('cvterm', $match);
  951. // The organism table does not have a type_id so we won't ever find
  952. // a record for it in the tripal_cv_defaults table.
  953. if ($cvterm->name == 'organism') {
  954. $bundle_data = array(
  955. 'cv_id' => $cvterm->cv_id->cv_id,
  956. 'cvterm_id' => $cvterm->cvterm_id,
  957. 'data_table' => 'organism',
  958. 'type_table' => 'organism',
  959. 'field' => '',
  960. );
  961. }
  962. // The analysis table does not have a type_id so we won't ever find
  963. // a record for it in the tripalcv_defaults table.
  964. else if ($cvterm->name == 'analysis') {
  965. $bundle_data = array(
  966. 'cv_id' => $cvterm->cv_id->cv_id,
  967. 'cvterm_id' => $cvterm->cvterm_id,
  968. 'data_table' => 'analysis',
  969. 'type_table' => 'analysis',
  970. 'field' => '',
  971. );
  972. }
  973. else if ($cvterm->name == 'project') {
  974. $bundle_data = array(
  975. 'cv_id' => $cvterm->cv_id->cv_id,
  976. 'cvterm_id' => $cvterm->cvterm_id,
  977. 'data_table' => 'project',
  978. 'type_table' => 'project',
  979. 'field' => '',
  980. );
  981. }
  982. else {
  983. // TODO: WHAT TO DO IF A VOCABULARY IS USED AS A DEFAULT FOR MULTIPLE
  984. // TABLES.
  985. // Look to see if this vocabulary is used as a default for any table.
  986. $default = db_select('tripal_cv_defaults', 't')
  987. ->fields('t')
  988. ->condition('cv_id', $cvterm->cv_id->cv_id)
  989. ->execute()
  990. ->fetchObject();
  991. if ($default) {
  992. $bundle_data = array(
  993. 'cv_id' => $cvterm->cv_id->cv_id,
  994. 'cvterm_id' => $cvterm->cvterm_id,
  995. 'data_table' => $default->table_name,
  996. 'type_table' => $default->table_name,
  997. 'field' => $default->field_name,
  998. );
  999. }
  1000. }
  1001. // Save the mapping information so that we can reuse it when we need to
  1002. // look things up for later for an entity
  1003. tripal_set_bundle_variable('chado_cvterm_id', $bundle->id, $bundle_data['cvterm_id']);
  1004. tripal_set_bundle_variable('chado_table', $bundle->id, $bundle_data['data_table']);
  1005. tripal_set_bundle_variable('chado_column', $bundle->id, $bundle_data['field']);
  1006. //////////////////////////////////////////////////////////////////////////////
  1007. // ADD FIELDS TO BUNDLE
  1008. ////////////////////////////////////////////////////////////////////////////
  1009. ////
  1010. //
  1011. // Base table fields.
  1012. //
  1013. // Adds the fields for the base table to the entity. Adds fields
  1014. // for all columns including FK fields. Excludes primary key and the
  1015. // type_id field (that's inherent in the bundle).
  1016. tripal_chado_add_bundle_base_fields($entity_type, $bundle_name, $bundle_data);
  1017. ////
  1018. //
  1019. // Property table fields.
  1020. //
  1021. // Check to see if there are any property tables with FKs to this
  1022. // base table. If so, add the fields for that type of table.
  1023. $prop_table = $bundle_data['data_table'] . 'prop';
  1024. if (chado_table_exists($prop_table)) {
  1025. tripal_chado_add_bundle_kvproperty_adder_field($entity_type, $bundle_name, $prop_table, $bundle_data['data_table']);
  1026. }
  1027. ////
  1028. //
  1029. // Dbxref table fields.
  1030. //
  1031. // Check to see if there are any dbxref tables with FKs to this
  1032. // base table. If so, add the fields for that type of table.
  1033. $dbxref_table = $bundle_data['data_table'] . '_dbxref';
  1034. if (chado_table_exists($dbxref_table)) {
  1035. tripal_chado_add_bundle_dbxref_field($entity_type, $bundle_name, $dbxref_table, $bundle_data['data_table']);
  1036. }
  1037. ////
  1038. //
  1039. // Cvterm table fields.
  1040. //
  1041. // Check to see if there are any cvterm tables with FKs to this
  1042. // base table. If so, add the fields for that type of table.
  1043. $cvterm_table = $bundle_data['data_table'] . '_cvterm';
  1044. if (chado_table_exists($cvterm_table)) {
  1045. tripal_chado_add_bundle_cvterm_class_adder_field($entity_type, $bundle_name, $cvterm_table, $bundle_data['data_table']);
  1046. }
  1047. }
  1048. /**
  1049. * Adds the fields for managing xrefs that are stored in a [base]_dbxref table.
  1050. *
  1051. * @param $entity_type
  1052. * @param $bundle_name
  1053. * @param $base_table
  1054. * @param $dbxref_table
  1055. */
  1056. function tripal_chado_add_bundle_dbxref_field($entity_type_name, $bundle_name, $dbxref_table, $base_table) {
  1057. // We already have a dbxref_id field.
  1058. $field_name = $dbxref_table;
  1059. $schema = chado_get_schema($dbxref_table);
  1060. $pkey = $schema['primary key'][0];
  1061. // Initialize the field array.
  1062. $field_info = array(
  1063. 'field_type' => 'dbxref',
  1064. 'widget_type' => 'tripal_fields_dbxfref_widget',
  1065. 'widget_settings' => array('display_label' => 1),
  1066. 'description' => '',
  1067. 'label' => 'Cross References',
  1068. 'is_required' => 0,
  1069. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  1070. 'storage' => 'field_chado_storage',
  1071. 'field_settings' => array(
  1072. // The Chado table that this field maps to.
  1073. 'chado_table' => $dbxref_table,
  1074. // The column in the chado table that this field maps to.
  1075. 'chado_column' => $pkey,
  1076. // The base table that this field is connected to.
  1077. 'base_table' => $base_table,
  1078. 'semantic_web' => array(
  1079. // The type is the term from a vocabulary that desribes this field..
  1080. 'type' => '',
  1081. // The namepsace for the vocabulary (e.g. 'foaf').
  1082. 'ns' => '',
  1083. // The URL for the namespace. It must be that the type can be
  1084. // appended to the URL.
  1085. 'nsurl' => '',
  1086. ),
  1087. ),
  1088. );
  1089. // If the base table has a 'dbxref_id' then change the label to
  1090. // indicate these are secondary cross references.
  1091. $schema = chado_get_schema($base_table);
  1092. if (array_key_exists('dbxref_id', $schema['fields'])) {
  1093. $field_info['label'] = 'Secondary Cross References';
  1094. }
  1095. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  1096. }
  1097. /**
  1098. * Adds the fields for managing properties that are stored in a prop table.
  1099. *
  1100. * @param $entity_type_name
  1101. * @param $bundle_name
  1102. * @param $kv_table
  1103. */
  1104. function tripal_chado_add_bundle_kvproperty_adder_field($entity_type_name, $bundle_name, $kv_table, $base_table) {
  1105. $field_name = $kv_table;
  1106. // Initialize the field array.
  1107. $field_info = array(
  1108. 'field_type' => 'kvproperty_adder',
  1109. 'widget_type' => 'tripal_fields_kvproperty_adder_widget',
  1110. 'field_settings' => array(
  1111. 'base_table' => $base_table,
  1112. ),
  1113. 'storage' => 'field_chado_storage',
  1114. 'widget_settings' => array('display_label' => 1),
  1115. 'description' => '',
  1116. 'label' => 'Additional Properties',
  1117. 'is_required' => 0,
  1118. );
  1119. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  1120. }
  1121. /**
  1122. * Adds the fields for managing properties that are stored in a prop table.
  1123. *
  1124. * @param $entity_type_name
  1125. * @param $bundle_name
  1126. * @param $kv_table
  1127. */
  1128. function tripal_chado_add_bundle_cvterm_class_adder_field($entity_type_name, $bundle_name, $cvterm_table, $base_table) {
  1129. // First add a generic property field so that users can add new property types.
  1130. $field_name = $cvterm_table;
  1131. // Initialize the field array.
  1132. $field_info = array(
  1133. 'field_type' => 'cvterm_class_adder',
  1134. 'widget_type' => 'tripal_fields_cvterm_class_adder_widget',
  1135. 'field_settings' => array(
  1136. 'base_table' => $base_table,
  1137. ),
  1138. 'storage' => 'field_chado_storage',
  1139. 'widget_settings' => array('display_label' => 1),
  1140. 'description' => '',
  1141. 'label' => 'Additional Annotation Types',
  1142. 'is_required' => 0,
  1143. );
  1144. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  1145. }
  1146. /**
  1147. * Adds the fields for the base table to the entity.
  1148. */
  1149. function tripal_chado_add_bundle_base_fields($entity_type_name, $bundle_name, $bundle_data) {
  1150. $table_name = $bundle_data['data_table'];
  1151. $type_table = $bundle_data['type_table'];
  1152. $type_field = $bundle_data['field'];
  1153. // Iterate through the columns of the table and see if fields have been
  1154. // created for each one. If not, then create them.
  1155. $schema = chado_get_schema($table_name);
  1156. $columns = $schema['fields'];
  1157. foreach ($columns as $column_name => $details) {
  1158. $field_name = $table_name . '__' . $column_name;
  1159. // Skip the primary key field.
  1160. if ($column_name == $schema['primary key'][0]) {
  1161. continue;
  1162. }
  1163. // Skip the type field.
  1164. if ($table_name == $type_table and $column_name == $type_field) {
  1165. continue;
  1166. }
  1167. // Get the field defaults for this column.
  1168. $field_info = tripal_chado_get_table_column_field_default($table_name, $schema, $column_name);
  1169. // TODO: add in a call to drupal_alter to allow other modules to change
  1170. // the field settings.
  1171. // Determine if the field is required.
  1172. if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
  1173. $field_info['is_required'] = array_key_exists('default', $details) ? 0 : 1;
  1174. }
  1175. // If we don't have a field type then we don't need to create a field.
  1176. if (!$field_info['field_type']) {
  1177. // If we don't have a field type but it is required and doesn't have
  1178. // a default value then we are in trouble.
  1179. if ($field_info['is_required'] and !array_key_exists('default', $details)) {
  1180. throw new Exception(t('The %table.%field type, %type, is not yet supported for Entity fields, but it is required,',
  1181. array('%table' => $table_name, '%field' => $column_name, '%type' => $details['type'])));
  1182. }
  1183. continue;
  1184. }
  1185. // If this field is a foreign key field then we will have a custom field.
  1186. $is_fk = FALSE;
  1187. if (array_key_exists('foreign keys', $schema)) {
  1188. foreach ($schema['foreign keys'] as $remote_table => $fk_details) {
  1189. if (array_key_exists($column_name, $fk_details['columns'])) {
  1190. $is_fk = TRUE;
  1191. }
  1192. }
  1193. }
  1194. // Add the field to the bundle.
  1195. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  1196. }
  1197. }
  1198. /**
  1199. * Returns a $field_info array for a field based on a database column.
  1200. *
  1201. */
  1202. function tripal_chado_get_table_column_field_default($table_name, $schema, $column_name) {
  1203. $details = $schema['fields'][$column_name];
  1204. // Create an array with information about this field.
  1205. $field = array(
  1206. 'field_type' => '',
  1207. 'widget_type' => '',
  1208. 'description' => '',
  1209. 'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
  1210. 'is_required' => 0,
  1211. 'storage' => 'field_chado_storage',
  1212. 'widget_settings' => array(
  1213. 'display_label' => 1
  1214. ),
  1215. 'field_settings' => array(
  1216. // The table in Chado where this field maps to.
  1217. 'chado_table' => $table_name,
  1218. // The column in the Chado table that this field maps to.
  1219. 'chado_column' => $column_name,
  1220. 'semantic_web' => array(
  1221. // The type is the term from a vocabulary that desribes this field..
  1222. 'type' => '',
  1223. // The namepsace for the vocabulary (e.g. 'foaf').
  1224. 'ns' => '',
  1225. // The URL for the namespace. It must be that the type can be
  1226. // appended to the URL.
  1227. 'nsurl' => '',
  1228. ),
  1229. ),
  1230. );
  1231. // Alter the field info array depending on the column details.
  1232. switch($details['type']) {
  1233. case 'char':
  1234. $field['field_type'] = 'text';
  1235. $field['widget_type'] = 'text_textfield';
  1236. $field['field_settings']['max_length'] = $details['length'];
  1237. break;
  1238. case 'varchar':
  1239. $field['field_type'] = 'text';
  1240. $field['widget_type'] = 'text_textfield';
  1241. $field['field_settings']['max_length'] = $details['length'];
  1242. break;
  1243. case 'text':
  1244. $field['field_type'] = 'text';
  1245. $field['widget_type'] = 'text_textarea';
  1246. $field['field_settings']['max_length'] = 17179869184;
  1247. $field['field_settings']['text_processing'] = 1;
  1248. $field['format'] = filter_default_format();
  1249. break;
  1250. case 'blob':
  1251. // not sure how to support a blob field.
  1252. continue;
  1253. break;
  1254. case 'int':
  1255. $field['field_type'] = 'number_integer';
  1256. $field['widget_type'] = 'number';
  1257. break;
  1258. case 'float':
  1259. $field['field_type'] = 'number_float';
  1260. $field['widget_type'] = 'number';
  1261. $field['field_settings']['precision'] = 10;
  1262. $field['field_settings']['scale'] = 2;
  1263. $field['field_settings']['decimal_separator'] = '.';
  1264. break;
  1265. case 'numeric':
  1266. $field['field_type'] = 'number_decimal';
  1267. $field['widget_type'] = 'number';
  1268. break;
  1269. case 'serial':
  1270. // Serial fields are most likely not needed as a field.
  1271. break;
  1272. case 'boolean':
  1273. $field['field_type'] = 'list_boolean';
  1274. $field['widget_type'] = 'options_onoff';
  1275. $field['field_settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
  1276. break;
  1277. case 'datetime':
  1278. // Use the Drupal Date and Date API to create the field/widget
  1279. $field['field_type'] = 'datetime';
  1280. $field['widget_type'] = 'date_select';
  1281. $field['widget_settings']['increment'] = 1;
  1282. $field['widget_settings']['tz_handling'] = 'none';
  1283. $field['widget_settings']['collapsible'] = TRUE;
  1284. // TODO: Add settings so that the minutes increment by 1.
  1285. // And turn off the timezone, as the Chado field doesn't support it.
  1286. break;
  1287. }
  1288. // Set some default semantic web information
  1289. if ($column_name == 'name') {
  1290. $field['field_settings']['semantic_web']['type'] = 'name';
  1291. $field['field_settings']['semantic_web']['ns'] = 'foaf';
  1292. $field['field_settings']['semantic_web']['nsurl'] = 'http://xmlns.com/foaf/0.1/';
  1293. }
  1294. if ($column_name == 'description' or $column_name == 'definition' or
  1295. $column_name == 'comment') {
  1296. $field['field_settings']['semantic_web']['type'] = 'description';
  1297. $field['field_settings']['semantic_web']['ns'] = 'hydra';
  1298. $field['field_settings']['semantic_web']['nsurl'] = 'http://www.w3.org/ns/hydra/core#';
  1299. }
  1300. //
  1301. // GENERIC COLUMNS
  1302. //
  1303. if ($field['field_settings']['chado_column'] =='organism_id') {
  1304. $field['field_type'] = 'organism_id';
  1305. $field['widget_type'] = 'tripal_chado_organism_select_widget';
  1306. $field['label'] = 'Organism';
  1307. $field['description'] = 'Select an organism.';
  1308. }
  1309. elseif ($field['field_settings']['chado_column'] =='dbxref_id') {
  1310. $field['field_type'] = 'dbxref_id';
  1311. $field['widget_type'] = 'tripal_chado_primary_dbxref_widget';
  1312. $field['label'] = 'Cross Reference';
  1313. $field['description'] = 'This record can be cross referenced with a ' .
  1314. 'record in another online database. The primary reference is for the ' .
  1315. 'most prominent reference. At a minimum, the database and accession ' .
  1316. 'must be provided. To remove a set reference, change the database ' .
  1317. 'field to "Select a Database".';
  1318. }
  1319. elseif ($field['label'] == 'Timeaccessioned') {
  1320. $field['label'] = 'Time Accessioned';
  1321. $field['description'] = 'Please enter the time that this record was first added to the database.';
  1322. }
  1323. elseif ($field['label'] == 'Timelastmodified') {
  1324. $field['label'] = 'Time Last Modified';
  1325. $field['description'] = 'Please enter the time that this record was last modified. The default is the current time.';
  1326. }
  1327. //
  1328. // ORGANISM TABLE
  1329. //
  1330. elseif ($field['field_settings']['chado_table'] == 'organism' and $field['field_settings']['chado_column'] == 'comment') {
  1331. $field['label'] = 'Description';
  1332. }
  1333. //
  1334. // FEATURE TABLE
  1335. //
  1336. elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'uniquename') {
  1337. $field['field_type'] = 'text';
  1338. $field['widget_type'] = 'text_textfield';
  1339. $field['field_settings']['text_processing'] = 0;
  1340. $field['field_settings']['semantic_web']['type'] = 'name';
  1341. $field['field_settings']['semantic_web']['ns'] = 'foaf';
  1342. $field['field_settings']['semantic_web']['nsurl'] = 'http://xmlns.com/foaf/0.1/';
  1343. }
  1344. elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'md5checksum') {
  1345. $field['field_type'] = 'md5checksum';
  1346. $field['widget_type'] = 'tripal_chado_md5checksum_checkbox_widget';
  1347. $field['label'] = 'MD5 Checksum';
  1348. $field['description'] = 'Generating MD5 checksum for the sequence.';
  1349. }
  1350. elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'seqlen') {
  1351. $field['field_type'] = 'seqlen';
  1352. $field['widget_type'] = 'tripal_chado_seqlen_hidden_widget';
  1353. $field['label'] = 'Seqlen';
  1354. $field['description'] = 'The length of the residues.';
  1355. }
  1356. elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'residues') {
  1357. $field['field_type'] = 'residues';
  1358. $field['widget_type'] = 'tripal_chado_residues_textarea_widget';
  1359. $field['label'] = 'Residues';
  1360. $field['description'] = 'Please provide an IUPAC compatible residues for this feature. Spaces and new lines are allowed.';
  1361. }
  1362. //
  1363. // ANALYSIS TABLE
  1364. //
  1365. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'program') {
  1366. $field['field_settings']['semantic_web']['type'] = 'SoftwareApplication';
  1367. $field['field_settings']['semantic_web']['ns'] = 'schema';
  1368. $field['field_settings']['semantic_web']['nsurl'] = 'https://schema.org/';
  1369. $field['description'] = 'The program name (e.g. blastx, blastp, sim4, genscan. If the analysis was not derived from a software package then provide a very brief description of the pipeline, workflow or method.';
  1370. $field['label'] = 'Program, Pipeline, Workflow or Method Name.';
  1371. }
  1372. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'sourceuri') {
  1373. $field['field_type'] = 'text';
  1374. $field['widget_type'] = 'text_textfield';
  1375. $field['field_settings']['text_processing'] = 0;
  1376. $field['label'] = 'Source URL';
  1377. $field['description'] = 'The URL where the original source data was derived. Ideally, this should link to the page where more information about the source data can be found.';
  1378. }
  1379. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'sourcename') {
  1380. $field['label'] = 'Source Name';
  1381. $field['description'] = 'The name of the source data. This could be a file name, data set or a small description for how the data was collected. For long descriptions use the larger description field.';
  1382. }
  1383. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'sourceversion') {
  1384. $field['label'] = 'Source Version';
  1385. $field['description'] = 'If hte source data set has a version include it here.';
  1386. }
  1387. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'algorithm') {
  1388. $field['label'] = 'Source Version';
  1389. $field['description'] = 'The name of the algorithm used to produce the dataset if different from the program.';
  1390. }
  1391. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'programversion') {
  1392. $field['label'] = 'Program Version';
  1393. $field['description'] = 'The version of the program used to perform this analysis. (e.g. TBLASTX 2.0MP-WashU [09-Nov-2000]. Enter "n/a" if no version is available or applicable.';
  1394. }
  1395. return $field;
  1396. }
  1397. /**
  1398. * Implements hook_exclude_type_by_default()
  1399. *
  1400. * This hooks allows fields of a specified type that match a specified criteria
  1401. * to be excluded by default from any table when chado_generate_var() is called.
  1402. * Keep in mind that if fields are excluded by default they can always be
  1403. * expanded at a later date using chado_expand_var().
  1404. *
  1405. * Criteria are php strings that evaluate to either TRUE or FALSE. These
  1406. * strings are evaluated using drupal_eval() which suppresses syntax errors and
  1407. * throws watchdog entries of type php. There are also watchdog entries of type
  1408. * tripal stating the exact criteria evaluated. Criteria can
  1409. * contain the following tokens:
  1410. * - <field_name>
  1411. * Replaced by the name of the field to be excluded
  1412. * - <field_value>
  1413. * Replaced by the value of the field in the current record
  1414. * Also keep in mind that if your criteria doesn't contain the
  1415. * &gt;field_value&lt; token then it will be evaluated before the query is
  1416. * executed and if the field is excluded it won't be included in the
  1417. * query.
  1418. *
  1419. * @return
  1420. * An array of type => criteria where the type is excluded if the criteria
  1421. * evaluates to TRUE
  1422. *
  1423. * @ingroup tripal
  1424. */
  1425. function tripal_chado_exclude_type_by_default() {
  1426. return array('text' => 'strlen("<field_value> ") > 250');
  1427. }
  1428. /**
  1429. * Implements hook_job_describe_args().
  1430. *
  1431. * Describes the arguements for the tripal_populate_mview job to allow for
  1432. * greater readability in the jobs details pages.
  1433. *
  1434. * @param $callback
  1435. * The callback of the current tripal job (this is the function that will be
  1436. * executed when tripal_launch_jobs.php is run.
  1437. * @param $args
  1438. * An array of arguments passed in when the job was registered.
  1439. *
  1440. * @return
  1441. * A more readable $args array
  1442. *
  1443. * @ingroup tripal
  1444. */
  1445. function tripal_chado_job_describe_args($callback, $args) {
  1446. $new_args = array();
  1447. if ($callback == 'tripal_populate_mview') {
  1448. // get this mview details
  1449. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = :mview_id ";
  1450. $results = db_query($sql, array(':mview_id' => $args[0]));
  1451. $mview = $results->fetchObject();
  1452. $new_args['View Name'] = $mview->name;
  1453. }
  1454. elseif ($callback == 'tripal_install_chado') {
  1455. $new_args['Action'] = $args[0];
  1456. }
  1457. return $new_args;
  1458. }
  1459. /**
  1460. * Implements hook_entity_property_info_alter().
  1461. *
  1462. * This is being implemented to ensure chado fields are exposed for search api indexing.
  1463. * All fields are available for index by default but the getter function set by default
  1464. * is not actually capable of getting the value from chado. Thus we change the getter
  1465. * function to one that can :-).
  1466. */
  1467. function tripal_chado_entity_property_info_alter(&$info) {
  1468. // Get a list of fields with the chado storage backend.
  1469. // Loop through all of the bundles.
  1470. if (isset($info['TripalEntity']['bundles'])) {
  1471. foreach ($info['TripalEntity']['bundles'] as $bundle_id => $bundle) {
  1472. // Loop through each of the fields for a given bundle.
  1473. foreach ($bundle['properties'] as $field_name => $field_info) {
  1474. // If the field is a chado field, then change the callback.
  1475. // @todo check this properly.
  1476. if (preg_match('/(\w+)__(\w+)/', $field_name, $matches)) {
  1477. $info['TripalEntity']['bundles'][$bundle_id]['properties'][$field_name]['getter callback'] =
  1478. 'tripal_chado_entity_property_get_value';
  1479. }
  1480. }
  1481. }
  1482. }
  1483. }
  1484. /**
  1485. * Provides a way for the search api to grab the value of a chado field.
  1486. *
  1487. * @param $entity
  1488. * The fully-loaded entity object to be indexed.
  1489. * @param $options
  1490. * Options that can be ued when retrieving the value.
  1491. * @param $field_name
  1492. * The machine name of the field we want to retrieve.
  1493. * @param $entity_type
  1494. * The type of entity (ie: TripalEntity).
  1495. *
  1496. * @return
  1497. * The rendered value of the field specified by $field_name.
  1498. */
  1499. function tripal_chado_entity_property_get_value($entity, $options, $field_name, $entity_type) {
  1500. $display = array(
  1501. 'type' => '',
  1502. 'label' => 'hidden',
  1503. );
  1504. $langcode = LANGUAGE_NONE;
  1505. $items = field_get_items($entity_type, $entity, $field_name);
  1506. if (count($items) == 1) {
  1507. $render_array = field_view_value($entity_type, $entity, $field_name, $items[0], $display, $langcode);
  1508. }
  1509. // @todo: handle fields with multiple values.
  1510. else {
  1511. $render_array = field_view_value($entity_type, $entity, $field_name, $items[0], $display, $langcode);
  1512. drupal_set_message('Tripal Chado currently only supports views integration for single value fields. The first value has been shown.', 'warning');
  1513. }
  1514. return drupal_render($render_array);
  1515. }