tripal_chado.fields.inc 79 KB

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