tripal_chado.fields.inc 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534
  1. <?php
  2. /**
  3. * Implements hook_bundle_fields_info().
  4. *
  5. * This is a Tripal defined hook that supports integration with the
  6. * TripalEntity field.
  7. */
  8. function tripal_chado_bundle_fields_info($entity_type, $bundle) {
  9. $chado_bundle = db_select('chado_bundle', 'cb')
  10. ->fields('cb')
  11. ->condition('bundle_id', $bundle->id)
  12. ->execute()
  13. ->fetchObject();
  14. // Get the details about the mapping of this bundle to the Chado table:
  15. $details = array(
  16. 'chado_cvterm_id' => $chado_bundle->type_id,
  17. 'chado_table' => $chado_bundle->data_table,
  18. 'chado_type_table' => $chado_bundle->type_linker_table,
  19. 'chado_type_column' => $chado_bundle->type_column,
  20. 'chado_type_value' => $chado_bundle->type_value,
  21. );
  22. $info = array();
  23. // Create the fields for each column in the table.
  24. tripal_chado_bundle_fields_info_base($info, $details, $entity_type, $bundle);
  25. // Create custom fields.
  26. tripal_chado_bundle_fields_info_custom($info, $details, $entity_type, $bundle);
  27. // Create fields for linking tables.
  28. tripal_chado_bundle_fields_info_linker($info, $details, $entity_type, $bundle);
  29. return $info;
  30. }
  31. /**
  32. *
  33. * @param unknown $details
  34. */
  35. function tripal_chado_bundle_fields_info_base(&$info, $details, $entity_type, $bundle) {
  36. $table_name = $details['chado_table'];
  37. $type_table = $details['chado_type_table'];
  38. $type_column = $details['chado_type_column'];
  39. $cvterm_id = $details['chado_cvterm_id'];
  40. $type_value = $details['chado_type_value'];
  41. // Iterate through the columns of the table and see if fields have been
  42. // created for each one. If not, then create them.
  43. $schema = chado_get_schema($table_name);
  44. if (!$schema) {
  45. return;
  46. }
  47. $pkey = $schema['primary key'][0];
  48. // Get the list of columns for this table and create a new field for each one.
  49. $columns = $schema['fields'];
  50. foreach ($columns as $column_name => $details) {
  51. // Skip the source columns in the analysis table. We have a custom
  52. // field for those columns
  53. if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
  54. $column_name == 'sourceversion' or $column_name == 'sourcename')) {
  55. continue;
  56. }
  57. // Skip the infraspecific type_id and name from the organism table as we
  58. // have a special field for those.
  59. if ($table_name == 'organism' and ($column_name == 'type_id' or
  60. $column_name == 'infraspecific_name')) {
  61. continue;
  62. }
  63. // Skip the cvterm.is_relationshptype.
  64. if ($table_name == 'cvterm' and $column_name == 'is_relationshiptype') {
  65. continue;
  66. }
  67. // The biosourceprovider_id and taxon_id are handled by custom fields.
  68. if ($table_name == 'biomaterial' and (
  69. $column_name == 'biosourceprovider_id' or $column_name == 'taxon_id')) {
  70. continue;
  71. }
  72. // Don't create base fields for the primary key and the type_id field.
  73. if ($column_name == $pkey or $column_name == $type_column) {
  74. continue;
  75. }
  76. $cvterm = tripal_get_chado_semweb_term($table_name, $column_name, array('return_object' => TRUE));
  77. if (!$cvterm) {
  78. tripal_report_error('tripal', TRIPAL_ERROR,
  79. 'Cannot create field for "%table_name.%column_name". Missing an appropriate vocabulary term',
  80. array('%table_name' => $table_name, '%column_name' => $column_name));
  81. drupal_set_message(t('Cannot create field for "%table_name.%column_name". Missing an appropriate vocabulary term',
  82. array('%table_name' => $table_name, '%column_name' => $column_name)), 'error');
  83. continue;
  84. }
  85. $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/[^\w]/', '_', $cvterm->name));
  86. $field_name = substr($field_name, 0, 32);
  87. // Skip the primary key field.
  88. if ($column_name == $schema['primary key'][0]) {
  89. continue;
  90. }
  91. // If the type_id defines the content type and it's part of the
  92. // base table and this column is the type_id then skip it.
  93. if (!$type_table and $type_column and $column_name == $type_column) {
  94. continue;
  95. }
  96. // Skip the type ID as it will be handled by a custom field.
  97. if ($column_name == 'type_id') {
  98. continue;
  99. }
  100. // Set some defaults for the field.
  101. $base_info = array(
  102. 'field_name' => $field_name,
  103. 'type' => '',
  104. 'cardinality' => 1,
  105. 'locked' => FALSE,
  106. 'storage' => array(
  107. 'type' => 'field_chado_storage',
  108. 'sql' => array(),
  109. ),
  110. );
  111. // Alter the field info array depending on the column details.
  112. switch($details['type']) {
  113. case 'char':
  114. $base_info['type'] = 'text';
  115. $base_info['settings']['max_length'] = $details['length'];
  116. break;
  117. case 'varchar':
  118. $base_info['type'] = 'text';
  119. $base_info['settings']['max_length'] = $details['length'];
  120. break;
  121. case 'text':
  122. $base_info['type'] = 'text';
  123. $base_info['settings']['max_length'] = 17179869184;
  124. $base_info['settings']['text_processing'] = 1;
  125. break;
  126. case 'blob':
  127. // not sure how to support a blob field.
  128. continue;
  129. break;
  130. case 'int':
  131. $base_info['type'] = 'number_integer';
  132. break;
  133. case 'float':
  134. $base_info['type'] = 'number_float';
  135. $base_info['settings']['precision'] = 10;
  136. $base_info['settings']['scale'] = 2;
  137. $base_info['settings']['decimal_separator'] = '.';
  138. break;
  139. case 'numeric':
  140. $base_info['type'] = 'number_decimal';
  141. break;
  142. case 'serial':
  143. // Serial fields are most likely not needed as a field.
  144. break;
  145. case 'boolean':
  146. $base_info['type'] = 'list_boolean';
  147. $base_info['settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
  148. break;
  149. case 'datetime':
  150. // Use the Drupal Date and Date API to create the field/widget
  151. $base_info['type'] = 'datetime';
  152. break;
  153. }
  154. // Set some defaults for biomaterial table
  155. if ($table_name == 'biomaterial' and $column_name == 'name') {
  156. $base_info['type'] = 'text';
  157. $base_info['settings']['max_length'] = '2048';
  158. $base_info['settings']['text_processing'] = 0;
  159. }
  160. // Set some default semantic web information
  161. if ($column_name == 'uniquename') {
  162. $base_info['settings']['text_processing'] = 0;
  163. }
  164. //
  165. // PUB TABLE
  166. //
  167. if ($table_name == 'pub' and (
  168. $column_name == 'uniquename' or $column_name == 'title' or
  169. $column_name == 'volumetitle')) {
  170. $base_info['type'] = 'text';
  171. $base_info['settings']['text_processing'] = 0;
  172. }
  173. $info[$field_name] = $base_info;
  174. }
  175. }
  176. /**
  177. *
  178. * @param unknown $details
  179. */
  180. function tripal_chado_bundle_fields_info_custom(&$info, $details, $entity_type, $bundle) {
  181. $table_name = $details['chado_table'];
  182. $type_table = $details['chado_type_table'];
  183. $type_column = $details['chado_type_column'];
  184. $cvterm_id = $details['chado_cvterm_id'];
  185. $type_value = $details['chado_type_value'];
  186. $schema = chado_get_schema($table_name);
  187. // Handle type_id fields that are not the type_column.
  188. if (array_key_exists('type_id', $schema['fields']) and 'type_id' != $type_column) {
  189. $field_name = 'schema__additional_type';
  190. $field_type = 'schema__additional_type';
  191. $info[$field_name] = array(
  192. 'field_name' => $field_name,
  193. 'type' => $field_type,
  194. 'cardinality' => 1,
  195. 'locked' => FALSE,
  196. 'storage' => array(
  197. 'type' => 'field_chado_storage',
  198. ),
  199. );
  200. }
  201. // BASE ORGANISM_ID
  202. if ($table_name != 'organism' and
  203. (array_key_exists('organism_id', $schema['fields']) or
  204. array_key_exists('taxon_id', $schema['fields']))) {
  205. $field_name = 'obi__organism';
  206. $field_type = 'obi__organism';
  207. $info[$field_name] = array(
  208. 'field_name' => $field_name,
  209. 'type' => $field_type,
  210. 'cardinality' => 1,
  211. 'locked' => FALSE,
  212. 'storage' => array(
  213. 'type' => 'field_chado_storage',
  214. ),
  215. );
  216. }
  217. if ($table_name == 'biomaterial') {
  218. $field_name = 'biomaterial__provider_id';
  219. $field_type = 'local__contact';
  220. $info[$field_name] = array(
  221. 'field_name' => $field_name,
  222. 'type' => $field_type,
  223. 'cardinality' => 1,
  224. 'locked' => FALSE,
  225. 'storage' => array(
  226. 'type' => 'field_chado_storage',
  227. ),
  228. );
  229. }
  230. // BASE ORGANISM_ID
  231. if ($table_name == 'cvterm') {
  232. $field_name = 'sio__vocabulary';
  233. $field_type = 'sio__vocabulary';
  234. $info[$field_name] = array(
  235. 'field_name' => $field_name,
  236. 'type' => $field_type,
  237. 'cardinality' => 1,
  238. 'locked' => FALSE,
  239. 'storage' => array(
  240. 'type' => 'field_chado_storage',
  241. ),
  242. );
  243. }
  244. // BASE DBXREF
  245. if (array_key_exists('dbxref_id', $schema['fields'])) {
  246. $field_name = 'data__accession';
  247. $field_type = 'data__accession';
  248. $info[$field_name] = array(
  249. 'field_name' => $field_name,
  250. 'type' => $field_type,
  251. 'cardinality' => 1,
  252. 'locked' => FALSE,
  253. 'storage' => array(
  254. 'type' => 'field_chado_storage',
  255. ),
  256. );
  257. }
  258. // FEATURE MD5CHECKSUM
  259. if ($table_name == 'feature') {
  260. $field_name = 'data__sequence_checksum';
  261. $field_type = 'data__sequence_checksum';
  262. $info[$field_name] = array(
  263. 'field_name' => $field_name,
  264. 'type' => $field_type,
  265. 'cardinality' => 1,
  266. 'locked' => FALSE,
  267. 'storage' => array(
  268. 'type' => 'field_chado_storage',
  269. ),
  270. );
  271. }
  272. // FEATURE RESIDUES
  273. if ($table_name == 'feature') {
  274. $field_name = 'data__sequence';
  275. $field_type = 'data__sequence';
  276. $info[$field_name] = array(
  277. 'field_name' => $field_name,
  278. 'type' => $field_type,
  279. 'cardinality' => 1,
  280. 'locked' => FALSE,
  281. 'storage' => array(
  282. 'type' => 'field_chado_storage',
  283. ),
  284. );
  285. }
  286. // FEATURE SEQLEN
  287. if ($table_name == 'feature') {
  288. $field_name = 'data__sequence_length';
  289. $field_type = 'data__sequence_length';
  290. $info[$field_name] = array(
  291. 'field_name' => $field_name,
  292. 'type' => $field_type,
  293. 'cardinality' => 1,
  294. 'locked' => FALSE,
  295. 'storage' => array(
  296. 'type' => 'field_chado_storage',
  297. ),
  298. );
  299. }
  300. // PROTEIN & CDS
  301. if ($table_name == 'feature' and
  302. ($bundle->label == 'mRNA' or $bundle->label == 'transcript')) {
  303. $field_name = 'data__protein_sequence';
  304. $field_type = 'data__protein_sequence';
  305. $info[$field_name] = array(
  306. 'field_name' => $field_name,
  307. 'type' => $field_type,
  308. 'cardinality' => 1,
  309. 'locked' => FALSE,
  310. 'storage' => array(
  311. 'type' => 'field_chado_storage',
  312. ),
  313. );
  314. // $field_name = 'so__cds';
  315. // $field_type = 'so__cds';
  316. // $info[$field_name] = array(
  317. // 'field_name' => $field_name,
  318. // 'type' => $field_type,
  319. // 'cardinality' => 1,
  320. // 'locked' => FALSE,
  321. // 'storage' => array(
  322. // 'type' => 'field_chado_storage',
  323. // ),
  324. // );
  325. }
  326. // // GENE TRANSCRIPTS
  327. // $rel_table = $table_name . '_relationship';
  328. // if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
  329. // $field_name = 'so__transcript';
  330. // $field_type = 'so__transcript';
  331. // $info[$field_name] = array(
  332. // 'field_name' => $field_name,
  333. // 'type' => $field_type,
  334. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  335. // 'locked' => FALSE,
  336. // 'storage' => array(
  337. // 'type' => 'field_chado_storage',
  338. // ),
  339. // );
  340. // }
  341. // ORGANISM TYPE_ID
  342. if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
  343. $field_name = 'taxrank__infraspecific_taxon';
  344. $field_type = 'taxrank__infraspecific_taxon';
  345. $info[$field_name] = array(
  346. 'field_name' => $field_name,
  347. 'type' => $field_type,
  348. 'cardinality' => 1,
  349. 'locked' => FALSE,
  350. 'storage' => array(
  351. 'type' => 'field_chado_storage',
  352. ),
  353. );
  354. }
  355. // FEATUREMAP UNITTYPE_ID
  356. if ($table_name == 'featuremap') {
  357. $field_name = 'uo__unit';
  358. $field_type = 'uo__unit';
  359. $info[$field_name] = array(
  360. 'field_name' => $field_name,
  361. 'type' => $field_type,
  362. 'cardinality' => 1,
  363. 'locked' => FALSE,
  364. 'storage' => array(
  365. 'type' => 'field_chado_storage',
  366. ),
  367. );
  368. }
  369. // Analysis source
  370. if ($table_name == 'analysis') {
  371. $field_name = 'local__source_data';
  372. $field_type = 'local__source_data';
  373. $info[$field_name] = array(
  374. 'field_name' => $field_name,
  375. 'type' => $field_type,
  376. 'cardinality' => 1,
  377. 'locked' => FALSE,
  378. 'storage' => array(
  379. 'type' => 'field_chado_storage',
  380. ),
  381. );
  382. }
  383. // Add an image field to the Organism type. This is a Drupal field and
  384. // not stored in Chado, but is used for backwards compatibility.
  385. if ($table_name == 'organism') {
  386. $field_name = 'data__image';
  387. $info[$field_name] = array(
  388. 'field_name' => $field_name,
  389. 'type' => 'image',
  390. 'cardinality' => 1,
  391. 'locked' => FALSE,
  392. 'storage' => array(
  393. 'type' => 'field_sql_storage',
  394. ),
  395. );
  396. }
  397. // Add field for viewing the phylogenetic tree.
  398. if ($table_name == 'phylotree') {
  399. $field_name = 'operation__phylotree_vis';
  400. $field_type = 'operation__phylotree_vis';
  401. $info[$field_name] = array(
  402. 'field_name' => $field_name,
  403. 'type' => $field_type,
  404. 'cardinality' => 1,
  405. 'locked' => FALSE,
  406. 'storage' => array(
  407. 'type' => 'field_chado_storage',
  408. ),
  409. );
  410. }
  411. }
  412. /**
  413. *
  414. * @param $details
  415. */
  416. function tripal_chado_bundle_fields_info_linker(&$info, $details, $entity_type, $bundle) {
  417. $table_name = $details['chado_table'];
  418. $type_table = $details['chado_type_table'];
  419. $type_column = $details['chado_type_column'];
  420. $cvterm_id = $details['chado_cvterm_id'];
  421. $type_value = $details['chado_type_value'];
  422. // CONTACTS
  423. $contact_table = $table_name . '_contact';
  424. if (chado_table_exists($contact_table)) {
  425. $schema = chado_get_schema($contact_table);
  426. $pkey = $schema['primary key'][0];
  427. $field_name = $table_name . '_contact';
  428. $field_type = 'chado_linker__contact';
  429. $info[$field_name] = array(
  430. 'field_name' => $field_name,
  431. 'type' => $field_type,
  432. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  433. 'locked' => FALSE,
  434. 'storage' => array(
  435. 'type' => 'field_chado_storage',
  436. ),
  437. );
  438. }
  439. // DBXREF
  440. $dbxref_table = $table_name . '_dbxref';
  441. if (chado_table_exists($dbxref_table)) {
  442. $field_name = 'sbo__database_cross_reference';
  443. $field_type = 'sbo__database_cross_reference';
  444. $info[$field_name] = array(
  445. 'field_name' => $field_name,
  446. 'type' => $field_type,
  447. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  448. 'locked' => FALSE,
  449. 'storage' => array(
  450. 'type' => 'field_chado_storage',
  451. ),
  452. );
  453. }
  454. // EXPRESSION
  455. // TODO: this should only show up on gene or mRNA bunldes, not every feature.
  456. // $expression_table = $table_name . '_expression';
  457. // if (chado_table_exists($expression_table)) {
  458. // $field_name = 'go__gene_expression';
  459. // $field_type = 'go__gene_expression';
  460. // $info[$field_name] = array(
  461. // 'field_name' => $field_name,
  462. // 'type' => $field_type,
  463. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  464. // 'locked' => FALSE,
  465. // 'storage' => array(
  466. // 'type' => 'field_chado_storage',
  467. // ),
  468. // );
  469. // }
  470. // FEATURELOC
  471. if ($table_name == 'feature') {
  472. $field_name = 'data__sequence_coordinates';
  473. $field_type = 'data__sequence_coordinates';
  474. $info[$field_name] = array(
  475. 'field_name' => $field_name,
  476. 'type' => $field_type,
  477. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  478. 'locked' => FALSE,
  479. 'storage' => array(
  480. 'type' => 'field_chado_storage',
  481. ),
  482. );
  483. }
  484. // FEATUREPOS
  485. if ($table_name == 'feature') {
  486. $field_name = 'ogi__location_on_map';
  487. $field_type = 'ogi__location_on_map';
  488. $info[$field_name] = array(
  489. 'field_name' => $field_name,
  490. 'type' => $field_type,
  491. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  492. 'locked' => FALSE,
  493. 'storage' => array(
  494. 'type' => 'field_chado_storage',
  495. ),
  496. );
  497. }
  498. // // GENOTYPE
  499. // $genotype_table = $table_name . '_genotype';
  500. // if (chado_table_exists($genotype_table)) {
  501. // $field_name = 'so__genotype';
  502. // $field_type = 'so__genotype';
  503. // $info[$field_name] = array(
  504. // 'field_name' => $field_name,
  505. // 'type' => $field_type,
  506. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  507. // 'locked' => FALSE,
  508. // 'storage' => array(
  509. // 'type' => 'field_chado_storage',
  510. // ),
  511. // );
  512. // }
  513. // // PHENOTYPE
  514. // $phenotype_table = $table_name . '_phenotype';
  515. // if (chado_table_exists($phenotype_table)) {
  516. // $field_name = 'sbo__phenotype';
  517. // $field_type = 'sbo__phenotype';
  518. // $info[$field_name] = array(
  519. // 'field_name' => $field_name,
  520. // 'type' => $field_type,
  521. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  522. // 'locked' => FALSE,
  523. // 'storage' => array(
  524. // 'type' => 'field_chado_storage',
  525. // ),
  526. // );
  527. // }
  528. // PROPERTIES
  529. $prop_table = $table_name . 'prop';
  530. if (chado_table_exists($prop_table)) {
  531. // Get the list of existing property types for this table.
  532. $sql = 'SELECT DISTINCT type_id FROM {' . $prop_table . '}';
  533. $props = chado_query($sql);
  534. while ($prop = $props->fetchObject()) {
  535. $term = chado_generate_var('cvterm', array('cvterm_id' => $prop->type_id));
  536. // The tripal_analysis_KEGG, tripal_analysis_blast, and
  537. // tripal_analysis_interpro modules store results in the analysisprop
  538. // table which is probably not the best place, but we don't want to
  539. // create a ton of fields for this, so skip them.
  540. if ($prop_table == 'analysisprop' and
  541. ($term->dbxref_id->db_id->name == 'KEGG_BRITE' or
  542. $term->dbxref_id->db_id->name == 'tripal')) {
  543. continue;
  544. }
  545. $field_name = strtolower(preg_replace('/[^\w]/','_', $term->dbxref_id->db_id->name . '__' . $term->name));
  546. $field_name = substr($field_name, 0, 32);
  547. $field_type = 'chado_linker__prop';
  548. $info[$field_name] = array(
  549. 'field_name' => $field_name,
  550. 'type' => $field_type,
  551. 'cardinality' => 1,
  552. 'locked' => FALSE,
  553. 'storage' => array(
  554. 'type' => 'field_chado_storage',
  555. ),
  556. );
  557. }
  558. }
  559. // CVTERMS
  560. $term_table = $table_name . '_cvterm';
  561. if (chado_table_exists($term_table)) {
  562. $schema = chado_get_schema($term_table);
  563. $pkey = $schema['primary key'][0];
  564. $lkey = key($schema['foreign keys'][$table_name]['columns']);
  565. $rkey = $schema['foreign keys'][$table_name]['columns'][$lkey];
  566. $field_name = 'sio__annotation';
  567. $field_type = 'sio__annotation';
  568. $info[$field_name] = array(
  569. 'field_name' => $field_name,
  570. 'type' => $field_type,
  571. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  572. 'locked' => FALSE,
  573. 'storage' => array(
  574. 'type' => 'field_chado_storage',
  575. ),
  576. );
  577. }
  578. // PUBLICATIONS
  579. $pub_table = $table_name . '_pub';
  580. if (chado_table_exists($pub_table)) {
  581. $field_name = 'schema__publication';
  582. $field_type = 'schema__publication';
  583. $info[$field_name] = array(
  584. 'field_name' => $field_name,
  585. 'type' => $field_type,
  586. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  587. 'locked' => FALSE,
  588. 'storage' => array(
  589. 'type' => 'field_chado_storage',
  590. ),
  591. );
  592. }
  593. // PUBLICATIONS (in reverse)
  594. // We want to be able to show all of the content that a publication links
  595. // to. The sio__references field does that.
  596. if ($table_name == 'pub') {
  597. $field_name = 'sio__references';
  598. $field_type = 'sio__references';
  599. $info[$field_name] = array(
  600. 'field_name' => $field_name,
  601. 'type' => $field_type,
  602. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  603. 'locked' => FALSE,
  604. 'storage' => array(
  605. 'type' => 'field_chado_storage',
  606. ),
  607. );
  608. }
  609. // RELATIONSHIPS
  610. // If the linker table does not exists then we don't want to add attach.
  611. $rel_table = $table_name . '_relationship';
  612. if (chado_table_exists($rel_table)) {
  613. $field_name = 'sbo__relationship';
  614. $field_type = 'sbo__relationship';
  615. $info[$field_name] = array(
  616. 'field_name' => $field_name,
  617. 'type' => $field_type,
  618. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  619. 'locked' => FALSE,
  620. 'storage' => array(
  621. 'type' => 'field_chado_storage',
  622. ),
  623. );
  624. }
  625. // SYNONYMS
  626. $syn_table = $table_name . '_synonym';
  627. if (chado_table_exists($syn_table)) {
  628. $field_name = 'schema__alternate_name';
  629. $field_type = 'schema__alternate_name';
  630. $info[$field_name] = array(
  631. 'field_name' => $field_name,
  632. 'type' => $field_type,
  633. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  634. 'locked' => FALSE,
  635. 'storage' => array(
  636. 'type' => 'field_chado_storage',
  637. ),
  638. 'settings' => array(
  639. ),
  640. );
  641. }
  642. }
  643. /**
  644. * Impelments hook_create_tripalfield_instance().
  645. *
  646. * This is a Tripal defined hook that supports integration with the
  647. * TripalEntity field.
  648. */
  649. function tripal_chado_bundle_instances_info($entity_type, $bundle) {
  650. $chado_bundle = db_select('chado_bundle', 'cb')
  651. ->fields('cb')
  652. ->condition('bundle_id', $bundle->id)
  653. ->execute()
  654. ->fetchObject();
  655. $details = array(
  656. 'chado_cvterm_id' => $chado_bundle->type_id,
  657. 'chado_table' => $chado_bundle->data_table,
  658. 'chado_type_table' => $chado_bundle->type_linker_table,
  659. 'chado_type_column' => $chado_bundle->type_column,
  660. 'chado_type_value' => $chado_bundle->type_value,
  661. );
  662. $info = array();
  663. tripal_chado_bundle_instances_info_base($info, $entity_type, $bundle, $details);
  664. tripal_chado_bundle_instances_info_custom($info, $entity_type, $bundle, $details);
  665. tripal_chado_bundle_instances_info_linker($info, $entity_type, $bundle, $details);
  666. return $info;
  667. }
  668. /**
  669. * Helper function for the hook_create_tripalfield_instance().
  670. *
  671. * Add the field instances that corresond to the columns of the base table.
  672. *
  673. * @param $entity_type
  674. * @param $bundle
  675. * @param $details
  676. */
  677. function tripal_chado_bundle_instances_info_base(&$info, $entity_type, $bundle, $details) {
  678. $fields = array();
  679. // Get Chado information
  680. $table_name = $details['chado_table'];
  681. $type_table = $details['chado_type_table'];
  682. $type_column = $details['chado_type_column'];
  683. $cvterm_id = $details['chado_cvterm_id'];
  684. $type_value = $details['chado_type_value'];
  685. // Iterate through the columns of the table and see if fields have been
  686. // created for each one. If not, then create them.
  687. $schema = chado_get_schema($table_name);
  688. if (!$schema) {
  689. return;
  690. }
  691. $pkey = $schema['primary key'][0];
  692. $columns = $schema['fields'];
  693. foreach ($columns as $column_name => $details) {
  694. // Skip the source columns in the analysis table. We have a custom
  695. // field for those columns
  696. if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
  697. $column_name == 'sourceversion' or $column_name == 'sourcename')) {
  698. continue;
  699. }
  700. // Skip the infraspecific type_id and name from the organism table as we
  701. // have a special field for those.
  702. if ($table_name == 'organism' and ($column_name == 'type_id' or
  703. $column_name == 'infraspecific_name')) {
  704. continue;
  705. }
  706. // Skip the cvterm.is_relationshptype.
  707. if ($table_name == 'cvterm' and $column_name == 'is_relationshiptype') {
  708. continue;
  709. }
  710. // The biosourceprovider_id and taxon_id are handled by custom fields.
  711. if ($table_name == 'biomaterial' and (
  712. $column_name == 'biosourceprovider_id' or $column_name == 'taxon_id')) {
  713. continue;
  714. }
  715. // Don't create base fields for the primary key and the type_id field.
  716. if ($column_name == $pkey or $column_name == $type_column) {
  717. continue;
  718. }
  719. $cvterm = tripal_get_chado_semweb_term($table_name, $column_name, array('return_object' => TRUE));
  720. if (!$cvterm) {
  721. // We already provided an error when creating the base field. So
  722. // don't create another one here.
  723. continue;
  724. }
  725. $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/[^\w]/', '_', $cvterm->name));
  726. $field_name = substr($field_name, 0, 32);
  727. // Skip the primary key field.
  728. if ($column_name == $schema['primary key'][0]) {
  729. continue;
  730. }
  731. // If the type_id defines the content type and it's part of the
  732. // base table and this column is the type_id then skip it.
  733. if (!$type_table and $type_column and $column_name == $type_column) {
  734. continue;
  735. }
  736. // Skip the type ID as it will be handled by a custom field.
  737. if ($column_name == 'type_id') {
  738. continue;
  739. }
  740. $base_info = array(
  741. 'field_name' => $field_name,
  742. 'entity_type' => 'TripalEntity',
  743. 'bundle' => $bundle->name,
  744. 'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
  745. 'description' => '',
  746. 'required' => FALSE,
  747. 'settings' => array(
  748. 'auto_attach' => TRUE,
  749. 'term_vocabulary' => $cvterm->dbxref_id->db_id->name,
  750. 'term_name' => $cvterm->name,
  751. 'term_accession' => $cvterm->dbxref_id->accession,
  752. 'chado_table' => $table_name,
  753. 'chado_column' => $column_name,
  754. 'base_table' => $table_name,
  755. ),
  756. 'widget' => array(
  757. 'settings' => array(
  758. 'display_label' => 1,
  759. ),
  760. ),
  761. 'display' => array(
  762. 'default' => array(
  763. 'label' => 'inline',
  764. 'region' =>'Left',
  765. 'settings' => array(),
  766. ),
  767. ),
  768. );
  769. // Determine if the field is required.
  770. if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
  771. $base_info['required'] = TRUE;
  772. }
  773. // Alter the field info array depending on the column details.
  774. switch($details['type']) {
  775. case 'char':
  776. $base_info['widget']['type'] = 'text_textfield';
  777. break;
  778. case 'varchar':
  779. $base_info['widget']['type'] = 'text_textfield';
  780. break;
  781. case 'text':
  782. $base_info['display']['default']['label'] = 'above';
  783. $base_info['widget']['type'] = 'text_textarea';
  784. $base_info['settings']['text_processing'] = '1';
  785. $base_info['settings']['format'] = 'full_html';
  786. break;
  787. case 'blob':
  788. // not sure how to support a blob field.
  789. continue;
  790. break;
  791. case 'int':
  792. $base_info['widget']['type'] = 'number';
  793. break;
  794. case 'float':
  795. $base_info['widget']['type'] = 'number';
  796. break;
  797. case 'numeric':
  798. $base_info['widget']['type'] = 'number';
  799. break;
  800. case 'serial':
  801. // Serial fields are most likely not needed as a field.
  802. break;
  803. case 'boolean':
  804. $base_info['widget']['type'] = 'options_onoff';
  805. $base_info['required'] = FALSE;
  806. break;
  807. case 'datetime':
  808. $base_info['widget']['type'] = 'date_select';
  809. $base_info['widget']['settings']['increment'] = 1;
  810. $base_info['widget']['settings']['tz_handling'] = 'none';
  811. $base_info['widget']['settings']['collapsible'] = TRUE;
  812. // TODO: Add settings so that the minutes increment by 1.
  813. // And turn off the timezone, as the Chado field doesn't support it.
  814. break;
  815. }
  816. // Set some default semantic web information
  817. if ($column_name == 'uniquename') {
  818. $base_info['label'] = 'Identifier';
  819. $base_info['widget']['type'] = 'text_textfield';
  820. if ($details['type'] == 'text') {
  821. unset($base_info['display']['default']['label']);
  822. unset($base_info['settings']['text_processing']);
  823. unset($base_info['settings']['format']);
  824. }
  825. }
  826. if ($base_info['label'] == 'Timeaccessioned') {
  827. $base_info['label'] = 'Time Accessioned';
  828. $base_info['description'] = 'Please enter the time that this record was first added to the database.';
  829. }
  830. if ($base_info['label'] == 'Timelastmodified') {
  831. $base_info['label'] = 'Time Last Modified';
  832. $base_info['description'] = 'Please enter the time that this record was last modified. The default is the current time.';
  833. }
  834. //
  835. // ORGANISM TABLE
  836. //
  837. if ($table_name == 'organism' and $column_name == 'comment') {
  838. $base_info['label'] = 'Description';
  839. }
  840. //
  841. // BIOMATERIAL TABLE
  842. //
  843. if ($table_name == 'biomaterial' and $column_name == 'name') {
  844. $base_info['widget'] = array();
  845. $base_info['widget']['type'] = 'text_textfield';
  846. unset($base_info['display']['default']['label']);
  847. unset($base_info['settings']['text_processing']);
  848. unset($base_info['settings']['format']);
  849. }
  850. //
  851. // FEATUREMAP TABLE
  852. //
  853. if ($table_name == 'featuremap' and $column_name == 'name') {
  854. $base_info['required'] = TRUE;
  855. }
  856. //
  857. // PUB TABLE
  858. //
  859. if ($table_name == 'pub') {
  860. if ($column_name == 'title' or $column_name == 'type_id') {
  861. $base_info['required'] = TRUE;
  862. }
  863. if($column_name == 'uniquename' or $column_name == 'title' or $column_name == 'volumetitle') {
  864. $base_info['widget']['type'] = 'text_textfield';
  865. $base_info['settings']['text_processing'] = '0';
  866. }
  867. if($column_name == 'uniquename') {
  868. $base_info['label'] = 'Unique Local Identifier';
  869. $base_info['required'] = TRUE;
  870. $base_info['description'] = 'This publication is housed in Chado whic requires a unique identifer (or name) be provided for every publication. This identifier need not be shown to end-users but it is required. Each site must decide on a format for this unique name.';
  871. }
  872. if($column_name == 'title') {
  873. $base_info['description'] = 'The title of the published work.';
  874. }
  875. if($column_name == 'series_name') {
  876. $base_info['description'] = 'The name media that produces a series of publications (e.g. journal, conference proceedings, etc.).';
  877. }
  878. if($column_name == 'issue') {
  879. $base_info['description'] = 'The issue of the series (e.g. journal) where the publication was printed.';
  880. }
  881. if($column_name == 'volume') {
  882. $base_info['description'] = 'The volume of the series (e.g. journal) where the publication was printed.';
  883. }
  884. if($column_name == 'pyear') {
  885. $base_info['label'] = 'Publication Year';
  886. $base_info['required'] = TRUE;
  887. }
  888. if($column_name == 'pages') {
  889. $base_info['label'] = 'Page Numbers';
  890. }
  891. if($column_name == 'pubplace') {
  892. $base_info['label'] = 'Publication Location';
  893. }
  894. if($column_name == 'volumetitle') {
  895. $base_info['label'] = 'Volumn Title';
  896. $base_info['label'] = 'The title of the volume (if applicable).';
  897. }
  898. if($column_name == 'miniref') {
  899. $base_info['label'] = 'Mini Local identifier';
  900. $base_info['description'] = 'Some sites use small identifiers for each publication. if your site uses this please provide the proper miniref for this publication.';
  901. }
  902. }
  903. //
  904. // ANALYSIS TABLE
  905. //
  906. if ($table_name == 'analysis' and $column_name == 'name') {
  907. $base_info['required'] = TRUE;
  908. }
  909. if ($table_name == 'analysis' and $column_name == 'program') {
  910. $base_info['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.';
  911. $base_info['label'] = 'Program, Pipeline, Workflow or Method Name';
  912. }
  913. if ($table_name == 'analysis' and $column_name == 'algorithm') {
  914. $base_info['label'] = 'Algorithm';
  915. $base_info['description'] = 'The name of the algorithm used to produce the dataset if different from the program.';
  916. }
  917. if ($table_name == 'analysis' and $column_name == 'programversion') {
  918. $base_info['label'] = 'Program Version';
  919. $base_info['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.';
  920. }
  921. if ($table_name == 'analysis' and $column_name == 'timeexecuted') {
  922. $base_info['label'] = 'Date Performed';
  923. $base_info['description'] = 'The date and time when the analysis was performed.';
  924. }
  925. if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
  926. $column_name == 'sourceversion' or $column_name == 'sourcename')) {
  927. // Skip the source columns in the analysis table. We have a custom
  928. // field for those columns
  929. continue;
  930. }
  931. //
  932. // PROJECT TABLE
  933. //
  934. if ($table_name == 'project' and $column_name == 'description') {
  935. $base_info['label'] = 'Short Description';
  936. }
  937. //
  938. // CONTACT TABLE
  939. //
  940. if ($table_name == 'contact' and $column_name == 'description') {
  941. $base_info['label'] = 'Short Description';
  942. }
  943. $info[$field_name] = $base_info;
  944. }
  945. }
  946. /**
  947. * Helper function for the hook_create_tripalfield_instance().
  948. *
  949. * Adds custom fields for base fields. These override the settings provided
  950. * in the tripal_chado_create_tripalfield_instance_base() function.
  951. *
  952. * @param $entity_type
  953. * @param $bundle
  954. * @param $details
  955. */
  956. function tripal_chado_bundle_instances_info_custom(&$info, $entity_type, $bundle, $details) {
  957. $table_name = $details['chado_table'];
  958. $type_table = $details['chado_type_table'];
  959. $type_column = $details['chado_type_column'];
  960. $cvterm_id = $details['chado_cvterm_id'];
  961. $type_value = $details['chado_type_value'];
  962. $schema = chado_get_schema($table_name);
  963. // An additional type for publications
  964. if (array_key_exists('type_id', $schema['fields']) and 'type_id' != $type_column) {
  965. $field_name = 'schema__additional_type';
  966. $is_required = FALSE;
  967. if (array_key_exists('not null', $schema['fields']['type_id']) and
  968. $schema['fields']['type_id']['not null']) {
  969. $is_required = TRUE;
  970. }
  971. $label = ucwords(preg_replace('/_/', ' ', $table_name)) . ' Type';
  972. $default_vocab = '';
  973. $parent_term = '';
  974. switch($table_name) {
  975. case 'pub':
  976. $default_vocab = 'tripal_pub';
  977. $label = 'Publication Type';
  978. $parent_term = 'TPUB:0000015';
  979. $description = 'Select the type.';
  980. break;
  981. case 'contact':
  982. $default_vocab = 'tripal_contact';
  983. $parent_term = 'TContact:0000001';
  984. $description = 'Select the type.';
  985. break;
  986. default:
  987. $description = t('Enter the name of the term that specifies the type. ' .
  988. 'The type must be the name of a term in a controlled vocabulary and ' .
  989. 'the controlled vocabulary should already be loaded into this site.');
  990. }
  991. $info[$field_name] = array(
  992. 'field_name' => $field_name,
  993. 'entity_type' => $entity_type,
  994. 'bundle' => $bundle->name,
  995. 'label' => $label,
  996. 'description' => $description,
  997. 'required' => $is_required,
  998. 'settings' => array(
  999. 'auto_attach' => TRUE,
  1000. 'chado_table' => $table_name,
  1001. 'chado_column' => 'type_id',
  1002. 'base_table' => $table_name,
  1003. 'vocabulary' => $default_vocab,
  1004. 'parent_term' => $parent_term,
  1005. ),
  1006. 'widget' => array(
  1007. 'type' => 'schema__additional_type_widget',
  1008. 'settings' => array(
  1009. 'display_label' => 1,
  1010. ),
  1011. ),
  1012. 'display' => array(
  1013. 'default' => array(
  1014. 'label' => 'inline',
  1015. 'type' => 'schema__additional_type_formatter',
  1016. 'settings' => array(),
  1017. ),
  1018. ),
  1019. );
  1020. }
  1021. // BASE ORGANISM_ID
  1022. if ($table_name != 'organism' and
  1023. (array_key_exists('organism_id', $schema['fields']) or
  1024. array_key_exists('taxon_id', $schema['fields']))) {
  1025. $field_name = 'obi__organism';
  1026. $is_required = FALSE;
  1027. $table_column = 'organism_id';
  1028. if ($table_name == 'biomaterial') {
  1029. $is_required = FALSE;
  1030. $table_column = 'taxon_id';
  1031. }
  1032. elseif (array_key_exists('not null', $schema['fields']['organism_id']) and
  1033. $schema['fields']['organism_id']['not null']) {
  1034. $is_required = TRUE;
  1035. }
  1036. $info[$field_name] = array(
  1037. 'field_name' => $field_name,
  1038. 'entity_type' => $entity_type,
  1039. 'bundle' => $bundle->name,
  1040. 'label' => 'Organism',
  1041. 'description' => 'The full scientific name for a species..',
  1042. 'required' => $is_required,
  1043. 'settings' => array(
  1044. 'auto_attach' => TRUE,
  1045. 'chado_table' => $table_name,
  1046. 'chado_column' => $table_column,
  1047. 'base_table' => $table_name,
  1048. ),
  1049. 'widget' => array(
  1050. 'type' => 'obi__organism_widget',
  1051. 'settings' => array(
  1052. 'display_label' => 1,
  1053. ),
  1054. ),
  1055. 'display' => array(
  1056. 'default' => array(
  1057. 'label' => 'inline',
  1058. 'type' => 'obi__organism_formatter',
  1059. 'settings' => array(),
  1060. ),
  1061. ),
  1062. );
  1063. }
  1064. if ($table_name == 'biomaterial') {
  1065. $field_name = 'biomaterial__provider_id';
  1066. $field_type = 'local__contact';
  1067. $info[$field_name] = array(
  1068. 'field_name' => $field_name,
  1069. 'entity_type' => $entity_type,
  1070. 'bundle' => $bundle->name,
  1071. 'label' => 'Contact',
  1072. 'description' => 'An indviddual or organization that serves as a contact for this record.',
  1073. 'required' => FALSE,
  1074. 'settings' => array(
  1075. 'auto_attach' => FALSE,
  1076. 'chado_table' => 'biomaterial',
  1077. 'chado_column' => 'biosourceprovider_id',
  1078. 'base_table' => 'biomaterial',
  1079. ),
  1080. 'widget' => array(
  1081. 'type' => 'local__contact_widget',
  1082. 'settings' => array(
  1083. 'display_label' => 1,
  1084. ),
  1085. ),
  1086. 'display' => array(
  1087. 'default' => array(
  1088. 'label' => 'inline',
  1089. 'type' => 'local__contact_formatter',
  1090. 'settings' => array(),
  1091. ),
  1092. ),
  1093. );
  1094. }
  1095. // BASE CVTERM
  1096. if ($table_name == 'cvterm') {
  1097. $field_name = 'sio__vocabulary';
  1098. $is_required = TRUE;
  1099. $info[$field_name] = array(
  1100. 'field_name' => $field_name,
  1101. 'entity_type' => $entity_type,
  1102. 'bundle' => $bundle->name,
  1103. 'label' => 'Vocabulary',
  1104. 'description' => 'A controlled vocabulary.',
  1105. 'required' => $is_required,
  1106. 'settings' => array(
  1107. 'auto_attach' => TRUE,
  1108. 'chado_table' => $table_name,
  1109. 'chado_column' => 'cv_id',
  1110. 'base_table' => $table_name,
  1111. ),
  1112. 'widget' => array(
  1113. 'type' => 'sio__vocabulary_widget',
  1114. 'settings' => array(
  1115. 'display_label' => 1,
  1116. ),
  1117. ),
  1118. 'display' => array(
  1119. 'default' => array(
  1120. 'label' => 'inline',
  1121. 'type' => 'sio__vocabulary_formatter',
  1122. 'settings' => array(),
  1123. ),
  1124. ),
  1125. );
  1126. }
  1127. // BASE DBXREF
  1128. if (array_key_exists('dbxref_id', $schema['fields'])) {
  1129. $field_name = 'data__accession';
  1130. $info[$field_name] = array(
  1131. 'field_name' => $field_name,
  1132. 'entity_type' => $entity_type,
  1133. 'bundle' => $bundle->name,
  1134. 'label' => 'Accession',
  1135. 'description' => 'This field specifies the unique stable accession (ID) for
  1136. this record. It requires that this site have a database entry.',
  1137. 'required' => FALSE,
  1138. 'settings' => array(
  1139. 'auto_attach' => TRUE,
  1140. 'chado_table' => $table_name,
  1141. 'chado_column' => 'dbxref_id',
  1142. 'base_table' => $table_name,
  1143. ),
  1144. 'widget' => array(
  1145. 'type' => 'data__accession_widget',
  1146. 'settings' => array(
  1147. 'display_label' => 1,
  1148. ),
  1149. ),
  1150. 'display' => array(
  1151. 'default' => array(
  1152. 'label' => 'inline',
  1153. 'type' => 'data__accession_formatter',
  1154. 'settings' => array(),
  1155. ),
  1156. ),
  1157. );
  1158. }
  1159. // FEATURE MD5CHECKSUM
  1160. if ($table_name == 'feature') {
  1161. $field_name = 'data__sequence_checksum';
  1162. $info[$field_name] = array(
  1163. 'field_name' => $field_name,
  1164. 'entity_type' => $entity_type,
  1165. 'bundle' => $bundle->name,
  1166. 'label' => 'Sequence Checksum',
  1167. 'description' => 'The MD5 checksum for the sequence. The checksum here
  1168. will always be unique for the raw unformatted sequence. To verify that the
  1169. sequence has not been corrupted, download the raw sequence and use an MD5 tool
  1170. to calculate the value. If the value calculated is identical the one shown
  1171. here, then the downloaded sequence is uncorrupted.',
  1172. 'required' => FALSE,
  1173. 'settings' => array(
  1174. 'auto_attach' => TRUE,
  1175. 'chado_table' => $table_name,
  1176. 'chado_column' => 'md5checksum',
  1177. 'base_table' => $table_name,
  1178. ),
  1179. 'widget' => array(
  1180. 'type' => 'data__sequence_checksum_widget',
  1181. 'settings' => array(
  1182. 'display_label' => 1,
  1183. 'md5_fieldname' => 'feature__md5checksum',
  1184. ),
  1185. ),
  1186. 'display' => array(
  1187. 'default' => array(
  1188. 'label' => 'inline',
  1189. 'type' => 'data__sequence_checksum_formatter',
  1190. 'settings' => array(),
  1191. ),
  1192. ),
  1193. );
  1194. }
  1195. // FEATURE RESIDUES
  1196. if ($table_name == 'feature') {
  1197. $field_name = 'data__sequence';
  1198. $info[$field_name] = array(
  1199. 'field_name' => $field_name,
  1200. 'entity_type' => $entity_type,
  1201. 'bundle' => $bundle->name,
  1202. 'label' => 'Sequence',
  1203. 'description' => 'All available sequences for this record.',
  1204. 'required' => FALSE,
  1205. 'settings' => array(
  1206. 'auto_attach' => FALSE,
  1207. 'chado_table' => $table_name,
  1208. 'chado_column' => 'residues',
  1209. 'base_table' => $table_name,
  1210. ),
  1211. 'widget' => array(
  1212. 'type' => 'data__sequence_widget',
  1213. 'settings' => array(
  1214. 'display_label' => 1,
  1215. ),
  1216. ),
  1217. 'display' => array(
  1218. 'default' => array(
  1219. 'label' => 'above',
  1220. 'type' => 'data__sequence_formatter',
  1221. 'settings' => array(),
  1222. ),
  1223. ),
  1224. );
  1225. }
  1226. // FEATURE SEQLEN
  1227. if ($table_name == 'feature') {
  1228. $field_name = 'data__sequence_length';
  1229. $info[$field_name] = array(
  1230. 'field_name' => $field_name,
  1231. 'entity_type' => $entity_type,
  1232. 'bundle' => $bundle->name,
  1233. 'label' => 'Sequence Length',
  1234. 'description' => 'The number of residues in the raw sequence. This length
  1235. is only for the assigned raw sequence and does not represent the length of any
  1236. sequences derived from alignments. If this value is zero but aligned sequences
  1237. are present then this record has no official assigned sequence.',
  1238. 'required' => FALSE,
  1239. 'settings' => array(
  1240. 'auto_attach' => TRUE,
  1241. 'chado_table' => $table_name,
  1242. 'chado_column' => 'seqlen',
  1243. 'base_table' => $table_name,
  1244. ),
  1245. 'widget' => array(
  1246. 'type' => 'data__sequence_length_widget',
  1247. 'settings' => array(
  1248. 'display_label' => 1,
  1249. ),
  1250. ),
  1251. 'display' => array(
  1252. 'default' => array(
  1253. 'label' => 'inline',
  1254. 'type' => 'data__sequence_length_formatter',
  1255. 'settings' => array(),
  1256. ),
  1257. ),
  1258. );
  1259. }
  1260. // PROTEIN & CDS SEQUENCES.
  1261. if ($table_name == 'feature' and
  1262. ($bundle->label == 'mRNA' or $bundle->label == 'transcript')) {
  1263. $field_name = 'data__protein_sequence';
  1264. $info[$field_name] = array(
  1265. 'field_name' => $field_name,
  1266. 'entity_type' => $entity_type,
  1267. 'bundle' => $bundle->name,
  1268. 'label' => 'Protein Sequence',
  1269. 'description' => 'Protein sequences.',
  1270. 'required' => FALSE,
  1271. 'settings' => array(
  1272. 'auto_attach' => FALSE,
  1273. 'chado_table' => 'feature',
  1274. 'chado_column' => 'residues',
  1275. 'base_table' => 'feature',
  1276. ),
  1277. 'widget' => array(
  1278. 'type' => 'data__protein_sequence_widget',
  1279. 'settings' => array(
  1280. 'display_label' => 1,
  1281. ),
  1282. ),
  1283. 'display' => array(
  1284. 'default' => array(
  1285. 'label' => 'above',
  1286. 'type' => 'data__protein_sequence_formatter',
  1287. 'settings' => array(),
  1288. ),
  1289. ),
  1290. );
  1291. // $field_name = 'so__cds';
  1292. // $info[$field_name] = array(
  1293. // 'field_name' => $field_name,
  1294. // 'entity_type' => $entity_type,
  1295. // 'bundle' => $bundle->name,
  1296. // 'label' => 'Coding Sequence',
  1297. // 'description' => 'Coding sequences.',
  1298. // 'required' => FALSE,
  1299. // 'settings' => array(
  1300. // 'auto_attach' => FALSE,
  1301. // 'chado_table' => 'featureloc',
  1302. // 'chado_column' => '',
  1303. // 'base_table' => 'featureloc',
  1304. // ),
  1305. // 'widget' => array(
  1306. // 'type' => 'so__cds_widget',
  1307. // 'settings' => array(
  1308. // 'display_label' => 1,
  1309. // ),
  1310. // ),
  1311. // 'display' => array(
  1312. // 'default' => array(
  1313. // 'label' => 'above',
  1314. // 'type' => 'so__cds_formatter',
  1315. // 'settings' => array(),
  1316. // ),
  1317. // ),
  1318. // );
  1319. }
  1320. // // GENE TRANSCRIPTS
  1321. // $rel_table = $table_name . '_relationship';
  1322. // if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
  1323. // $field_name = 'so__transcript';
  1324. // $info[$field_name] = array(
  1325. // 'field_name' => $field_name,
  1326. // 'entity_type' => $entity_type,
  1327. // 'bundle' => $bundle->name,
  1328. // 'label' => 'Transcripts',
  1329. // 'description' => 'Transcripts that are part of this gene.',
  1330. // 'required' => FALSE,
  1331. // 'settings' => array(
  1332. // 'auto_attach' => FALSE,
  1333. // 'chado_table' => $rel_table,
  1334. // 'chado_column' => '',
  1335. // 'base_table' => $table_name,
  1336. // ),
  1337. // 'widget' => array(
  1338. // 'type' => 'so__transcript_widget',
  1339. // 'settings' => array(
  1340. // 'display_label' => 1,
  1341. // ),
  1342. // ),
  1343. // 'display' => array(
  1344. // 'default' => array(
  1345. // 'label' => 'above',
  1346. // 'type' => 'so__transcript_formatter',
  1347. // 'settings' => array(),
  1348. // ),
  1349. // ),
  1350. // );
  1351. // }
  1352. // ORGANISM TYPE_ID
  1353. if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
  1354. $field_name = 'taxrank__infraspecific_taxon';
  1355. $info[$field_name] = array(
  1356. 'field_name' => $field_name,
  1357. 'entity_type' => $entity_type,
  1358. 'bundle' => $bundle->name,
  1359. 'label' => 'Infraspecific Taxon',
  1360. 'description' => 'The Infraspecific Taxon.',
  1361. 'required' => FALSE,
  1362. 'settings' => array(
  1363. 'auto_attach' => TRUE,
  1364. 'chado_table' => 'organism',
  1365. 'chado_column' => 'type_id',
  1366. 'base_table' => 'organism',
  1367. ),
  1368. 'widget' => array(
  1369. 'type' => 'taxrank__infraspecific_taxon_widget',
  1370. 'settings' => array(
  1371. 'display_label' => 1,
  1372. ),
  1373. ),
  1374. 'display' => array(
  1375. 'default' => array(
  1376. 'label' => 'inline',
  1377. 'type' => 'taxrank__infraspecific_taxon_formatter',
  1378. 'settings' => array(),
  1379. ),
  1380. ),
  1381. );
  1382. }
  1383. // FEATURE MAP UNITS
  1384. if ($table_name == 'featuremap') {
  1385. $field_name = 'uo__unit';
  1386. $info[$field_name] = array(
  1387. 'field_name' => $field_name,
  1388. 'entity_type' => $entity_type,
  1389. 'bundle' => $bundle->name,
  1390. 'label' => 'Units',
  1391. 'description' => 'The map\'s unit type.',
  1392. 'required' => TRUE,
  1393. 'settings' => array(
  1394. 'auto_attach' => TRUE,
  1395. 'chado_table' => $table_name,
  1396. 'chado_column' => 'unittype_id',
  1397. 'base_table' => $table_name,
  1398. ),
  1399. 'widget' => array(
  1400. 'type' => 'uo__unit_widget',
  1401. 'settings' => array(
  1402. 'display_label' => 1,
  1403. ),
  1404. ),
  1405. 'display' => array(
  1406. 'default' => array(
  1407. 'label' => 'inline',
  1408. 'type' => 'uo__unit_formatter',
  1409. 'settings' => array(),
  1410. ),
  1411. ),
  1412. );
  1413. }
  1414. // the analysis source.
  1415. if ($table_name == 'analysis') {
  1416. $field_name = 'local__source_data';
  1417. $info[$field_name] = array(
  1418. 'field_name' => $field_name,
  1419. 'entity_type' => $entity_type,
  1420. 'bundle' => $bundle->name,
  1421. 'label' => 'Data Source',
  1422. 'description' => 'The source where data was obtained for this analysis.',
  1423. 'required' => FALSE,
  1424. 'settings' => array(
  1425. 'auto_attach' => TRUE,
  1426. 'chado_table' => $table_name,
  1427. 'chado_column' => 'analysis_id',
  1428. 'base_table' => $table_name,
  1429. ),
  1430. 'widget' => array(
  1431. 'type' => 'local__source_data_widget',
  1432. 'settings' => array(
  1433. 'display_label' => 1,
  1434. ),
  1435. ),
  1436. 'display' => array(
  1437. 'default' => array(
  1438. 'label' => 'inline',
  1439. 'type' => 'local__source_data_formatter',
  1440. 'settings' => array(),
  1441. ),
  1442. ),
  1443. );
  1444. }
  1445. // Add an image field to the Organism type. This is a Drupal field and
  1446. // not stored in Chado, but is used for backwards compatibility.
  1447. if ($table_name == 'organism') {
  1448. $field_name = 'data__image';
  1449. $info[$field_name] = array(
  1450. 'field_name' => $field_name,
  1451. 'entity_type' => $entity_type,
  1452. 'bundle' => $bundle->name,
  1453. 'label' => 'Organism Image',
  1454. 'description' => 'An image for the organism',
  1455. 'required' => FALSE,
  1456. 'settings' => array(
  1457. 'term_vocabulary' => 'data',
  1458. 'term_name' => 'Image',
  1459. 'term_accession' => '2968',
  1460. ),
  1461. 'display' => array(
  1462. 'default' => array(
  1463. 'label' => 'hidden',
  1464. ),
  1465. ),
  1466. );
  1467. }
  1468. // Phylotree Viewer
  1469. if ($table_name == 'phylotree') {
  1470. $field_name = 'operation__phylotree_vis';
  1471. $schema = chado_get_schema('phylotree');
  1472. $pkey = $schema['primary key'][0];
  1473. $info[$field_name] = array(
  1474. 'field_name' => $field_name,
  1475. 'entity_type' => $entity_type,
  1476. 'bundle' => $bundle->name,
  1477. 'label' => 'Tree View',
  1478. 'description' => 'Rendering of a phylogenetic tree.',
  1479. 'required' => FALSE,
  1480. 'settings' => array(
  1481. 'auto_attach' => FALSE,
  1482. 'chado_table' => 'phylotree',
  1483. 'chado_column' => 'type_id',
  1484. 'base_table' => 'phylotree',
  1485. ),
  1486. 'widget' => array(
  1487. 'type' => 'operation__phylotree_vis_widget',
  1488. 'settings' => array(
  1489. 'display_label' => 0,
  1490. ),
  1491. ),
  1492. 'display' => array(
  1493. 'default' => array(
  1494. 'label' => 'hidden',
  1495. 'type' => 'operation__phylotree_vis_formatter',
  1496. 'settings' => array(),
  1497. ),
  1498. ),
  1499. );
  1500. }
  1501. }
  1502. /**
  1503. *
  1504. * @param unknown $entity_type
  1505. * @param unknown $bundle
  1506. * @param unknown $details
  1507. */
  1508. function tripal_chado_bundle_instances_info_linker(&$info, $entity_type, $bundle, $details) {
  1509. $table_name = $details['chado_table'];
  1510. $type_table = $details['chado_type_table'];
  1511. $type_column = $details['chado_type_column'];
  1512. $cvterm_id = $details['chado_cvterm_id'];
  1513. $type_value = $details['chado_type_value'];
  1514. // CONTACTS
  1515. $contact_table = $table_name . '_contact';
  1516. if (chado_table_exists($contact_table)) {
  1517. $field_name = $table_name . '_contact';
  1518. $info[$field_name] = $info[$field_name] = array(
  1519. 'field_name' => $field_name,
  1520. 'entity_type' => $entity_type,
  1521. 'bundle' => $bundle->name,
  1522. 'label' => 'Contact',
  1523. 'description' => 'Associates an indviddual or organization with this record',
  1524. 'required' => FALSE,
  1525. 'settings' => array(
  1526. 'auto_attach' => FALSE,
  1527. 'chado_table' => $contact_table,
  1528. 'base_table' => $table_name,
  1529. 'chado_column' => 'contact_id',
  1530. ),
  1531. 'widget' => array(
  1532. 'type' => 'local__contact_widget',
  1533. 'settings' => array(
  1534. 'display_label' => 1,
  1535. ),
  1536. ),
  1537. 'display' => array(
  1538. 'default' => array(
  1539. 'label' => 'hidden',
  1540. 'type' => 'local__contact_formatter',
  1541. 'settings' => array(),
  1542. ),
  1543. ),
  1544. );
  1545. }
  1546. // DBXREF
  1547. $dbxref_table = $table_name . '_dbxref';
  1548. if (chado_table_exists($dbxref_table)) {
  1549. $field_name = 'sbo__database_cross_reference';
  1550. $schema = chado_get_schema($dbxref_table);
  1551. $pkey = $schema['primary key'][0];
  1552. $info[$field_name] = array(
  1553. 'field_name' => $field_name,
  1554. 'entity_type' => $entity_type,
  1555. 'bundle' => $bundle->name,
  1556. 'label' => 'Cross Reference',
  1557. 'description' => 'The IDs where this record may be available in other external online databases.',
  1558. 'required' => FALSE,
  1559. 'settings' => array(
  1560. 'auto_attach' => FALSE,
  1561. 'chado_table' => $dbxref_table,
  1562. 'chado_column' => $pkey,
  1563. 'base_table' => $table_name,
  1564. ),
  1565. 'widget' => array(
  1566. 'type' => 'sbo__database_cross_reference_widget',
  1567. 'settings' => array(
  1568. 'display_label' => 1,
  1569. ),
  1570. ),
  1571. 'display' => array(
  1572. 'default' => array(
  1573. 'label' => 'hidden',
  1574. 'type' => 'sbo__database_cross_reference_formatter',
  1575. 'settings' => array(),
  1576. ),
  1577. ),
  1578. );
  1579. }
  1580. // EXPRESSION
  1581. // TODO: this should only show up on gene or mRNA and the GO must be
  1582. // laoded or this field will crash things.
  1583. // $expression_table = $table_name . '_expression';
  1584. // if (chado_table_exists($expression_table)) {
  1585. // $field_name = 'go__gene_expression';
  1586. // $schema = chado_get_schema($expression_table);
  1587. // $pkey = $schema['primary key'][0];
  1588. // $info[$field_name] = array(
  1589. // 'field_name' => $field_name,
  1590. // 'entity_type' => $entity_type,
  1591. // 'bundle' => $bundle->name,
  1592. // 'label' => 'Gene expression',
  1593. // 'description' => 'Information about the expression of this record.',
  1594. // 'required' => FALSE,
  1595. // 'settings' => array(
  1596. // 'auto_attach' => FALSE,
  1597. // 'chado_table' => $expression_table,
  1598. // 'chado_column' => $pkey,
  1599. // 'base_table' => $table_name,
  1600. // ),
  1601. // 'widget' => array(
  1602. // 'type' => 'go__gene_expression_widget',
  1603. // 'settings' => array(
  1604. // 'display_label' => 1,
  1605. // ),
  1606. // ),
  1607. // 'display' => array(
  1608. // 'default' => array(
  1609. // 'label' => 'above',
  1610. // 'type' => 'go__gene_expression_formatter',
  1611. // 'settings' => array(),
  1612. // ),
  1613. // ),
  1614. // );
  1615. // }
  1616. // FEATURELOC
  1617. if ($table_name == 'feature') {
  1618. $field_name = 'data__sequence_coordinates';
  1619. $schema = chado_get_schema('featureloc');
  1620. $pkey = $schema['primary key'][0];
  1621. $info[$field_name] = array(
  1622. 'field_name' => $field_name,
  1623. 'entity_type' => $entity_type,
  1624. 'bundle' => $bundle->name,
  1625. 'label' => 'Sequence Coordinates',
  1626. 'description' => 'The locations on other genomic sequences where this
  1627. record has been aligned.',
  1628. 'required' => FALSE,
  1629. 'settings' => array(
  1630. 'auto_attach' => FALSE,
  1631. 'chado_table' => 'featureloc',
  1632. 'chado_column' => $pkey,
  1633. 'base_table' => 'feature',
  1634. ),
  1635. 'widget' => array(
  1636. 'type' => 'data__sequence_coordinates_widget',
  1637. 'settings' => array(
  1638. 'display_label' => 1,
  1639. ),
  1640. ),
  1641. 'display' => array(
  1642. 'default' => array(
  1643. 'label' => 'hidden',
  1644. 'type' => 'data__sequence_coordinates_formatter',
  1645. 'settings' => array(),
  1646. ),
  1647. ),
  1648. );
  1649. }
  1650. // FEATUREPOS
  1651. if ($table_name == 'feature') {
  1652. $field_name = 'ogi__location_on_map';
  1653. $schema = chado_get_schema('featurepos');
  1654. $pkey = $schema['primary key'][0];
  1655. $info[$field_name] = array(
  1656. 'field_name' => $field_name,
  1657. 'entity_type' => $entity_type,
  1658. 'bundle' => $bundle->name,
  1659. 'label' => 'Location on Map',
  1660. 'description' => 'The positions on a genetic map.',
  1661. 'required' => FALSE,
  1662. 'settings' => array(
  1663. 'auto_attach' => FALSE,
  1664. 'chado_table' => 'featurepos',
  1665. 'chado_column' => $pkey,
  1666. 'base_table' => 'feature',
  1667. ),
  1668. 'widget' => array(
  1669. 'type' => 'ogi__location_on_map_widget',
  1670. 'settings' => array(
  1671. 'display_label' => 1,
  1672. ),
  1673. ),
  1674. 'display' => array(
  1675. 'default' => array(
  1676. 'label' => 'hidden',
  1677. 'type' => 'ogi__location_on_map_formatter',
  1678. 'settings' => array(),
  1679. ),
  1680. ),
  1681. );
  1682. }
  1683. // // GENOTYPE
  1684. // $genotype_table = $table_name . '_genotype';
  1685. // if (chado_table_exists($genotype_table)) {
  1686. // $field_name = 'so__genotype';
  1687. // $schema = chado_get_schema($genotype_table);
  1688. // $pkey = $schema['primary key'][0];
  1689. // $info[$field_name] = array(
  1690. // 'field_name' => $field_name,
  1691. // 'entity_type' => $entity_type,
  1692. // 'bundle' => $bundle->name,
  1693. // 'label' => 'Genotype',
  1694. // 'description' => 'The genotypes associated with this record.',
  1695. // 'required' => FALSE,
  1696. // 'settings' => array(
  1697. // 'auto_attach' => FALSE,
  1698. // 'chado_table' => $genotype_table,
  1699. // 'chado_column' => $pkey,
  1700. // 'base_table' => $table_name,
  1701. // ),
  1702. // 'widget' => array(
  1703. // 'type' => 'so__genotype_widget',
  1704. // 'settings' => array(
  1705. // 'display_label' => 1,
  1706. // ),
  1707. // ),
  1708. // 'display' => array(
  1709. // 'default' => array(
  1710. // 'label' => 'hidden',
  1711. // 'type' => 'so__genotype_formatter',
  1712. // 'settings' => array(),
  1713. // ),
  1714. // ),
  1715. // );
  1716. // }
  1717. // // PHENOTYPE
  1718. // $phenotype_table = $table_name . '_phenotype';
  1719. // if (chado_table_exists($phenotype_table)) {
  1720. // $field_name = 'sbo__phenotype';
  1721. // $schema = chado_get_schema($phenotype_table);
  1722. // $pkey = $schema['primary key'][0];
  1723. // $info[$field_name] = array(
  1724. // 'field_name' => $field_name,
  1725. // 'entity_type' => $entity_type,
  1726. // 'bundle' => $bundle->name,
  1727. // 'label' => 'Phenotype',
  1728. // 'description' => 'The phenotypes associated with this record.',
  1729. // 'required' => FALSE,
  1730. // 'settings' => array(
  1731. // 'auto_attach' => FALSE,
  1732. // 'chado_table' => $phenotype_table,
  1733. // 'chado_column' => $pkey,
  1734. // 'base_table' => $table_name,
  1735. // ),
  1736. // 'widget' => array(
  1737. // 'type' => 'sbo__phenotype_widget',
  1738. // 'settings' => array(
  1739. // 'display_label' => 1,
  1740. // ),
  1741. // ),
  1742. // 'display' => array(
  1743. // 'default' => array(
  1744. // 'label' => 'hidden',
  1745. // 'type' => 'sbo__phenotype_formatter',
  1746. // 'settings' => array(),
  1747. // ),
  1748. // ),
  1749. // );
  1750. // }
  1751. // PROPERTIES
  1752. $prop_table = $table_name . 'prop';
  1753. if (chado_table_exists($prop_table)) {
  1754. $tschema = chado_get_schema($table_name);
  1755. $schema = chado_get_schema($prop_table);
  1756. $tpkey = $tschema['primary key'][0];
  1757. $pkey = $schema['primary key'][0];
  1758. // Property tables can be a bit tricky because not all property types
  1759. // in the prop table are appropriate for each type of data. Also som
  1760. // bundle types are resolved via a property. So, we have to distinguish
  1761. // between these two cases.
  1762. $sql = '';
  1763. $args = array();
  1764. // First, is this the case where all of the records in the table are
  1765. // of this type? If so, then all properties apply
  1766. if (!$type_column) {
  1767. $sql = 'SELECT DISTINCT type_id FROM {' . $prop_table . '}';
  1768. $props = chado_query($sql, $args);
  1769. }
  1770. // Second, if this is the case where a content type is uniquely identified
  1771. // by a type_id value in the base table, then only properties associated
  1772. // with that type ID should be used.
  1773. else if ($type_column and !$type_table) {
  1774. $sql = "
  1775. SELECT DISTINCT P.type_id
  1776. FROM {" . $prop_table . "} P
  1777. INNER JOIN {" . $table_name . "} T on T.$tpkey = P.$tpkey
  1778. WHERE T.$type_column = :cvterm_id
  1779. ";
  1780. $args[':cvterm_id'] = $cvterm_id;
  1781. $props = chado_query($sql, $args);
  1782. }
  1783. // Third, if this is the case where a content type is uniquely identified
  1784. // via a term/value pair in the prop table.
  1785. else if ($type_column and $type_table == $prop_table and !empty($type_value)) {
  1786. $sql = "
  1787. SELECT DISTINCT P2.type_id
  1788. FROM {" . $prop_table . "} P1
  1789. INNER JOIN {" . $table_name . "} T on T.$tpkey = P1.$tpkey
  1790. INNER JOIN {" . $prop_table . "} P2 on T.$tpkey = P2.$tpkey
  1791. WHERE P1.$type_column = :cvterm_id AND P1.value = :prop_value AND
  1792. P2.type_id != P1.type_id
  1793. ";
  1794. $args[':cvterm_id'] = $cvterm_id;
  1795. $args[':prop_value'] = $type_value;
  1796. $props = chado_query($sql, $args);
  1797. }
  1798. // Fourth, if this is the case where the content type is uinquely identifed
  1799. // via another table (e.g. cvterm linking table) and not this prop table.
  1800. else if ($type_column and $type_table != $prop_table and empty($type_value)) {
  1801. $sql = "
  1802. SELECT DISTINCT P.type_id
  1803. FROM {" . $prop_table . "} P
  1804. INNER JOIN {" . $table_name . "} T on T.$tpkey = P.$tpkey
  1805. INNER JOIN {" . $type_table . "} TT on TT.$tpkey = T.$tpkey
  1806. WHERE TT.$type_column = :cvterm_id
  1807. ";
  1808. $args[':cvterm_id'] = $cvterm_id;
  1809. $props = chado_query($sql, $args);
  1810. }
  1811. else {
  1812. // Do nothing;
  1813. }
  1814. if ($props) {
  1815. while ($prop = $props->fetchObject()) {
  1816. $term = chado_generate_var('cvterm', array('cvterm_id' => $prop->type_id));
  1817. $term = chado_expand_var($term, 'field', 'cvterm.definition');
  1818. // Skip the Publiation Type property for pubs as this is
  1819. // already handled by the pub.type_id field.
  1820. if ($term->name == 'Publication Type' and $term->cv_id->name == 'tripal_pub') {
  1821. continue;
  1822. }
  1823. // The tripal_analysis_KEGG, tripal_analysis_blast, and
  1824. // tripal_analysis_interpro modules store results in the analysisprop
  1825. // table which is probably not the best place, but we don't want to
  1826. // create a ton of fields for this.
  1827. if ($prop_table == 'analysisprop' and
  1828. ($term->dbxref_id->db_id->name == 'KEGG_BRITE' or
  1829. $term->dbxref_id->db_id->name == 'tripal')) {
  1830. continue;
  1831. }
  1832. $field_name = strtolower(preg_replace('/[^\w]/','_', $term->dbxref_id->db_id->name . '__' . $term->name));
  1833. $field_name = substr($field_name, 0, 32);
  1834. $info[$field_name] = array(
  1835. 'field_name' => $field_name,
  1836. 'entity_type' => $entity_type,
  1837. 'bundle' => $bundle->name,
  1838. 'label' => ucwords(preg_replace('/_/', ' ', $term->name)),
  1839. 'description' => $term->definition,
  1840. 'required' => FALSE,
  1841. 'settings' => array(
  1842. 'auto_attach' => TRUE,
  1843. 'term_vocabulary' => $term->dbxref_id->db_id->name,
  1844. 'term_accession' => $term->dbxref_id->accession,
  1845. 'term_name' => $term->name,
  1846. 'base_table' => $table_name,
  1847. 'chado_table' => $prop_table,
  1848. 'chado_column' => $pkey,
  1849. ),
  1850. 'widget' => array(
  1851. 'type' => 'chado_linker__prop_widget',
  1852. 'settings' => array(
  1853. 'display_label' => 1,
  1854. ),
  1855. ),
  1856. 'display' => array(
  1857. 'default' => array(
  1858. 'label' => 'hidden',
  1859. 'type' => 'chado_linker__prop_formatter',
  1860. 'settings' => array(),
  1861. ),
  1862. ),
  1863. );
  1864. // Make some customizations to some fields
  1865. if ($term->name == 'Citation' and $term->cv_id->name == 'tripal_pub') {
  1866. $info[$field_name]['required'] = TRUE;
  1867. $info[$field_name]['description'] = t('All publications must have a unique citation.
  1868. Please enter the full citation for this publication. For PubMed style citations list
  1869. the last name of the author followed by initials. Each author should be separated by a comma. Next comes
  1870. the title, followed by the series title (e.g. journal name), publication date (4 digit year, 3 character Month, day), volume, issue and page numbers. You may also use HTML to provide a link in the citation.
  1871. Below is an example: <pre>Medeiros PM, Ladio AH, Santos AM, Albuquerque UP. <a href="http://www.ncbi.nlm.nih.gov/pubmed/23462414" target="_blank">Does the selection of medicinal plants by Brazilian local populations
  1872. suffer taxonomic influence?</a> J Ethnopharmacol. 2013 Apr 19; 146(3):842-52.</pre>');
  1873. $info[$field_name]['settings']['rows'] = 3;
  1874. }
  1875. if ($term->name == 'Abstract' and $term->cv_id->name == 'tripal_pub') {
  1876. $info[$field_name]['settings']['rows'] = 5;
  1877. }
  1878. }
  1879. }
  1880. }
  1881. // CVTERMS
  1882. $term_table = $table_name . '_cvterm';
  1883. if (chado_table_exists($term_table)) {
  1884. $schema = chado_get_schema($term_table);
  1885. $pkey = $schema['primary key'][0];
  1886. $lkey = key($schema['foreign keys'][$table_name]['columns']);
  1887. $rkey = $schema['foreign keys'][$table_name]['columns'][$lkey];
  1888. $field_name = 'sio__annotation';
  1889. $info[$field_name] = array(
  1890. 'field_name' => $field_name,
  1891. 'entity_type' => $entity_type,
  1892. 'bundle' => $bundle->name,
  1893. 'label' => 'Annotations',
  1894. 'description' => 'Annotations that are associated with this record.',
  1895. 'required' => FALSE,
  1896. 'settings' => array(
  1897. 'auto_attach' => FALSE,
  1898. 'chado_table' => $term_table,
  1899. 'chado_column' => $pkey,
  1900. 'base_table' => $table_name,
  1901. ),
  1902. 'widget' => array(
  1903. 'type' => 'sio__annotation_widget',
  1904. 'settings' => array(
  1905. 'display_label' => 1,
  1906. ),
  1907. ),
  1908. 'display' => array(
  1909. 'default' => array(
  1910. 'label' => 'hidden',
  1911. 'type' => 'sio__annotation_formatter',
  1912. 'settings' => array(),
  1913. ),
  1914. ),
  1915. );
  1916. }
  1917. // PUBLICATIONS
  1918. $pub_table = $table_name . '_pub';
  1919. if (chado_table_exists($pub_table)) {
  1920. $field_name = 'schema__publication';
  1921. $schema = chado_get_schema($pub_table);
  1922. $pkey = $schema['primary key'][0];
  1923. $info[$field_name] = array(
  1924. 'field_name' => $field_name,
  1925. 'entity_type' => $entity_type,
  1926. 'bundle' => $bundle->name,
  1927. 'label' => 'Publication',
  1928. 'description' => 'This record has been referenced or is sourced from these publications.',
  1929. 'required' => FALSE,
  1930. 'settings' => array(
  1931. 'auto_attach' => FALSE,
  1932. 'chado_table' => $pub_table,
  1933. 'chado_column' => $pkey,
  1934. 'base_table' => $table_name,
  1935. ),
  1936. 'widget' => array(
  1937. 'type' => 'schema__publication_widget',
  1938. 'settings' => array(
  1939. 'display_label' => 1,
  1940. ),
  1941. ),
  1942. 'display' => array(
  1943. 'default' => array(
  1944. 'label' => 'hidden',
  1945. 'type' => 'schema__publication_formatter',
  1946. 'settings' => array(),
  1947. ),
  1948. ),
  1949. );
  1950. }
  1951. // PUBLICATIONS (in reverse)
  1952. // We want to be able to show all of the content that a publication links
  1953. // to. The sio__references field does that.
  1954. if ($table_name == 'pub') {
  1955. $field_name = 'sio__references';
  1956. $schema = chado_get_schema($table_name);
  1957. $pkey = $schema['primary key'][0];
  1958. $info[$field_name] = array(
  1959. 'field_name' => $field_name,
  1960. 'entity_type' => $entity_type,
  1961. 'bundle' => $bundle->name,
  1962. 'label' => 'References',
  1963. 'description' => 'Records that are referred to by the publication.',
  1964. 'required' => FALSE,
  1965. 'settings' => array(
  1966. 'auto_attach' => FALSE,
  1967. 'chado_table' => $table_name,
  1968. 'chado_column' => $pkey,
  1969. 'base_table' => $table_name,
  1970. ),
  1971. 'widget' => array(
  1972. 'type' => 'sio__references_widget',
  1973. 'settings' => array(
  1974. 'display_label' => 1,
  1975. ),
  1976. ),
  1977. 'display' => array(
  1978. 'default' => array(
  1979. 'label' => 'hidden',
  1980. 'type' => 'sio__references_formatter',
  1981. 'settings' => array(),
  1982. ),
  1983. ),
  1984. );
  1985. }
  1986. // RELATIONSHIPS
  1987. // If the linker table does not exists then we don't want to add attach.
  1988. $rel_table = $table_name . '_relationship';
  1989. if (chado_table_exists($rel_table)) {
  1990. $field_name = 'sbo__relationship';
  1991. $schema = chado_get_schema($rel_table);
  1992. $pkey = $schema['primary key'][0];
  1993. $info[$field_name] = array(
  1994. 'field_name' => $field_name,
  1995. 'entity_type' => $entity_type,
  1996. 'bundle' => $bundle->name,
  1997. 'label' => 'Relationship',
  1998. 'description' => 'Other records with relationships to this record.',
  1999. 'required' => FALSE,
  2000. 'settings' => array(
  2001. 'auto_attach' => FALSE,
  2002. 'chado_table' => $rel_table,
  2003. 'chado_column' => $pkey,
  2004. 'base_table' => $table_name,
  2005. ),
  2006. 'widget' => array(
  2007. 'type' => 'sbo__relationship_widget',
  2008. 'settings' => array(
  2009. 'display_label' => 1,
  2010. ),
  2011. ),
  2012. 'display' => array(
  2013. 'default' => array(
  2014. 'label' => 'hidden',
  2015. 'type' => 'sbo__relationship_formatter',
  2016. 'settings' => array(),
  2017. ),
  2018. ),
  2019. );
  2020. }
  2021. // SYNONYMS
  2022. $syn_table = $table_name . '_synonym';
  2023. if (chado_table_exists($syn_table)) {
  2024. $field_name = 'schema__alternate_name';
  2025. $schema = chado_get_schema($syn_table);
  2026. $pkey = $schema['primary key'][0];
  2027. $info[$field_name] = array(
  2028. 'field_name' => $field_name,
  2029. 'entity_type' => $entity_type,
  2030. 'bundle' => $bundle->name,
  2031. 'label' => 'Synonyms',
  2032. 'description' => 'Alternate names, aliases or synonyms for this record.',
  2033. 'required' => FALSE,
  2034. 'settings' => array(
  2035. 'auto_attach' => FALSE,
  2036. 'chado_table' => $syn_table,
  2037. 'chado_column' => $pkey,
  2038. 'base_table' => $table_name,
  2039. ),
  2040. 'widget' => array(
  2041. 'type' => 'schema__alternate_name_widget',
  2042. 'settings' => array(
  2043. 'display_label' => 1,
  2044. ),
  2045. ),
  2046. 'display' => array(
  2047. 'default' => array(
  2048. 'label' => 'hidden',
  2049. 'type' => 'schema__alternate_name_formatter',
  2050. 'settings' => array(),
  2051. ),
  2052. ),
  2053. );
  2054. }
  2055. }
  2056. /**
  2057. * Implements hook_bundle_create_user_field().
  2058. *
  2059. * A priviledged user has the ability to add new fields to the bundle. The
  2060. * chado_linker__prop and chado_linker__cvterm fields are allowed to be
  2061. * added dynamically by the user. But, Drupal doesn't know how to deal with
  2062. * it, so this function is called for any field attached to a TripalEntity
  2063. * bundle type. Any fields whose TripalField::$module argument is set to
  2064. * 'tripal_chado' and that can be added dynamically will result in a call
  2065. * to this function.
  2066. */
  2067. function tripal_chado_bundle_create_user_field($new_field, $bundle) {
  2068. // Get the table this bundle is mapped to.
  2069. $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
  2070. $vocab = $term->vocab;
  2071. $params = array(
  2072. 'vocabulary' => $vocab->vocabulary,
  2073. 'accession' => $term->accession,
  2074. );
  2075. $chado_table = $bundle->data_table;
  2076. $chado_type_table = $bundle->type_linker_table;
  2077. $chado_type_column = $bundle->type_column;
  2078. $chado_type_id = $bundle->type_id;
  2079. $chado_type_value = $bundle->type_value;
  2080. // We allow site admins to add new chado_linker__prop fields to an entity.
  2081. // This function will allow us to properly add them. But at this point we
  2082. // don't know the controlled vocabulary term. We'll have to use the
  2083. // defaults and let the user set it using the interface.
  2084. if ($new_field['type'] == 'chado_linker__prop') {
  2085. $table_name = $chado_table . 'prop';
  2086. if (chado_table_exists($table_name)) {
  2087. $schema = chado_get_schema($table_name);
  2088. $pkey = $schema['primary key'][0];
  2089. $field_name = $new_field['field_name'];
  2090. $field_type = 'chado_linker__prop';
  2091. // First add the field.
  2092. field_create_field(array(
  2093. 'field_name' => $field_name,
  2094. 'type' => $field_type,
  2095. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  2096. 'locked' => FALSE,
  2097. 'storage' => array(
  2098. 'type' => 'field_chado_storage',
  2099. ),
  2100. ));
  2101. // Now add the instance
  2102. field_create_instance(array(
  2103. 'field_name' => $field_name,
  2104. 'entity_type' => 'TripalEntity',
  2105. 'bundle' => $bundle->name,
  2106. 'label' => $new_field['label'],
  2107. 'description' => '',
  2108. 'required' => FALSE,
  2109. 'settings' => array(
  2110. 'auto_attach' => TRUE,
  2111. 'base_table' => $chado_table,
  2112. 'chado_table' => $table_name,
  2113. 'chado_column' => $pkey,
  2114. 'term_vocabulary' => '',
  2115. 'term_accession' => '',
  2116. 'term_name' => ''
  2117. ),
  2118. 'widget' => array(
  2119. 'type' => 'chado_linker__prop_widget',
  2120. 'settings' => array(
  2121. 'display_label' => 1,
  2122. ),
  2123. ),
  2124. 'display' => array(
  2125. 'default' => array(
  2126. 'label' => 'inline',
  2127. 'type' => 'chado_linker__prop_formatter',
  2128. 'settings' => array(),
  2129. ),
  2130. ),
  2131. ));
  2132. }
  2133. else {
  2134. drupal_set_message('Cannot add a property field to this entity. Chado does not support properties for this data type.', 'error');
  2135. }
  2136. }
  2137. // We allow site admins to add new chado_linker__cvterm fields to an entity.
  2138. // This function will allow us to properly add them. But at this point we
  2139. // don't know the controlled vocabulary term. We'll have to use the
  2140. // defaults and let the user set it using the interface.
  2141. if ($new_field['type'] == 'chado_linker__cvterm') {
  2142. $table_name = $chado_table . '_cvterm';
  2143. if (chado_table_exists($table_name)) {
  2144. $schema = chado_get_schema($table_name);
  2145. $pkey = $schema['primary key'][0];
  2146. $field_name = $new_field['field_name'];
  2147. $field_type = 'chado_linker__cvterm';
  2148. // First add the field.
  2149. field_create_field(array(
  2150. 'field_name' => $field_name,
  2151. 'type' => $field_type,
  2152. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  2153. 'locked' => FALSE,
  2154. 'storage' => array(
  2155. 'type' => 'field_chado_storage',
  2156. ),
  2157. 'settings' => array(
  2158. 'base_table' => $chado_table,
  2159. 'chado_table' => $table_name,
  2160. 'chado_column' => $pkey,
  2161. ),
  2162. ));
  2163. // Now add the instance
  2164. field_create_instance(array(
  2165. 'field_name' => $field_name,
  2166. 'entity_type' => 'TripalEntity',
  2167. 'bundle' => $bundle->name,
  2168. 'label' => $new_field['label'],
  2169. 'description' => '',
  2170. 'required' => FALSE,
  2171. 'settings' => array(
  2172. 'auto_attach' => TRUE,
  2173. ),
  2174. 'widget' => array(
  2175. 'type' => 'chado_linker__cvterm_widget',
  2176. 'settings' => array(
  2177. 'display_label' => 1,
  2178. ),
  2179. ),
  2180. 'display' => array(
  2181. 'default' => array(
  2182. 'label' => 'above',
  2183. 'type' => 'chado_linker__cvterm_formatter',
  2184. 'settings' => array(),
  2185. ),
  2186. ),
  2187. ));
  2188. }
  2189. else {
  2190. drupal_set_message('Cannot add a property field to this entity. Chado does not support annotations for this data type.', 'error');
  2191. }
  2192. }
  2193. }
  2194. /**
  2195. * Allows for altering of a field's instance setting form.
  2196. *
  2197. * This appears to be a Drupal hook but is actually a custom function created
  2198. * by this module. It is called by the tripal_form_alter() function of this
  2199. * module.
  2200. *
  2201. * Here we put additional form elements for any field, regardless if it is
  2202. * a tripalField or not.
  2203. *
  2204. * @param $form
  2205. * The form array. Alterations to the form can be made within this array.
  2206. * @param $form_state
  2207. * The form state array.
  2208. */
  2209. function tripal_chado_field_instance_settings_form_alter(&$form, $form_state) {
  2210. global $language;
  2211. $field = $form['#field'];
  2212. $instance = $form['#instance'];
  2213. $base_table = array_key_exists('base_table', $instance['settings']) ? $instance['settings']['base_table'] : '';
  2214. $chado_table = array_key_exists('chado_table', $instance['settings']) ? $instance['settings']['chado_table'] : '';
  2215. $chado_column = array_key_exists('chado_column', $instance['settings']) ? $instance['settings']['chado_column'] : '';
  2216. if ($chado_table) {
  2217. // Construct a table for the vocabulary information.
  2218. $headers = array();
  2219. $rows = array();
  2220. $rows[] = array(
  2221. array(
  2222. 'data' => 'Base Table',
  2223. 'header' => TRUE,
  2224. 'width' => '20%',
  2225. ),
  2226. $base_table
  2227. );
  2228. $rows[] = array(
  2229. array(
  2230. 'data' => 'Record Table',
  2231. 'header' => TRUE,
  2232. 'width' => '20%',
  2233. ),
  2234. $chado_table
  2235. );
  2236. $rows[] = array(
  2237. array(
  2238. 'data' => 'ID Column',
  2239. 'header' => TRUE,
  2240. 'width' => '20%',
  2241. ),
  2242. $chado_column
  2243. );
  2244. $table = array(
  2245. 'header' => $headers,
  2246. 'rows' => $rows,
  2247. 'attributes' => array(
  2248. ),
  2249. 'sticky' => FALSE,
  2250. 'caption' => '',
  2251. 'colgroups' => array(),
  2252. 'empty' => '',
  2253. );
  2254. $form['chado_mapping'] = array(
  2255. '#type' => 'fieldset',
  2256. '#title' => 'Chado Mapping',
  2257. '#description' => t('This field maps to data in Chado to the following table:'),
  2258. );
  2259. $form['chado_mapping']['details'] = array(
  2260. '#type' => 'item',
  2261. '#markup' => theme_table($table),
  2262. );
  2263. }
  2264. }
  2265. /**
  2266. * Implements hook_form_FROM_ID_alter()
  2267. */
  2268. function tripal_chado_form_tripalbundle_form_alter(&$form, $form_state) {
  2269. global $language;
  2270. $bundle = $form['#bundle'];
  2271. $term = entity_load('TripalTerm', array('id' => $bundle->term_id));
  2272. $term = reset($term);
  2273. $vocab = $term->vocab;
  2274. $params = array(
  2275. 'vocabulary' => $vocab->vocabulary,
  2276. 'accession' => $term->accession,
  2277. );
  2278. $chado_table = $bundle->data_table;
  2279. $chado_column = $bundle->type_column;
  2280. $chado_type_table = $bundle->type_linker_table;
  2281. $chado_type_id = $bundle->type_id;
  2282. $chado_type_value = $bundle->type_value;
  2283. // Construct a table for the vocabulary information.
  2284. $headers = array();
  2285. $rows = array();
  2286. $rows[] = array(
  2287. array(
  2288. 'data' => 'Chado Table',
  2289. 'header' => TRUE,
  2290. 'width' => '20%',
  2291. ),
  2292. $chado_table
  2293. );
  2294. if ($chado_column) {
  2295. $rows[] = array(
  2296. array(
  2297. 'data' => 'Type Column',
  2298. 'header' => TRUE,
  2299. 'width' => '20%',
  2300. ),
  2301. $chado_column
  2302. );
  2303. }
  2304. if ($chado_type_table) {
  2305. $rows[] = array(
  2306. array(
  2307. 'data' => 'Association Table',
  2308. 'header' => TRUE,
  2309. 'width' => '20%',
  2310. ),
  2311. $chado_type_table
  2312. );
  2313. }
  2314. if ($chado_type_table and $chado_type_id) {
  2315. $rows[] = array(
  2316. array(
  2317. 'data' => 'CVTerm Table ID',
  2318. 'header' => TRUE,
  2319. 'width' => '20%',
  2320. ),
  2321. $chado_type_id
  2322. );
  2323. }
  2324. if ($chado_type_value) {
  2325. $rows[] = array(
  2326. array(
  2327. 'data' => 'Property Value',
  2328. 'header' => TRUE,
  2329. 'width' => '20%',
  2330. ),
  2331. $chado_type_value
  2332. );
  2333. }
  2334. $table = array(
  2335. 'header' => $headers,
  2336. 'rows' => $rows,
  2337. 'attributes' => array(
  2338. ),
  2339. 'sticky' => FALSE,
  2340. 'caption' => '',
  2341. 'colgroups' => array(),
  2342. 'empty' => '',
  2343. );
  2344. $form['chado_mapping'] = array(
  2345. '#type' => 'item',
  2346. '#title' => 'Chado Mapping',
  2347. '#markup' => theme_table($table),
  2348. '#description' => t('This content type maps to the table in Chado
  2349. listed above. Chado allows multiple data types to be housed
  2350. in a single table. Therefore, the column that is used to
  2351. differentiate between data types is also listed above.'),
  2352. '#weight' => 0,
  2353. );
  2354. }
  2355. /**
  2356. * Implements hook_field_views_data_alter();
  2357. */
  2358. function tripal_chado_field_views_data_alter(&$result, $field, $module) {
  2359. // This module creates the data__image field for managing images on
  2360. // bio_data content types. But we want it to render correctly
  2361. // so we need to set some handlers.
  2362. if ($field['field_name'] == 'data__image') {
  2363. foreach ($result as $key => $fields) {
  2364. // It's not clear how to identify our bundle types, but they do have
  2365. // a double underscore in their name to separate the vocabulary from
  2366. // the accession, so we'll use that to find them.
  2367. if (preg_match('/__/', $key)) {
  2368. $result[$key]['data__image']['field']['handler'] = 'tripal_views_handler_field_image';
  2369. }
  2370. }
  2371. }
  2372. }