tripal_chado.fields.inc 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248
  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 = [
  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_id' => $chado_bundle->type_id,
  20. 'chado_type_column' => $chado_bundle->type_column,
  21. 'chado_type_value' => $chado_bundle->type_value,
  22. 'chado_base_type_id' => $chado_bundle->base_type_id,
  23. ];
  24. $info = [];
  25. // Create the fields for each column in the table.
  26. tripal_chado_bundle_fields_info_base($info, $details, $entity_type, $bundle);
  27. // Create custom fields.
  28. tripal_chado_bundle_fields_info_custom($info, $details, $entity_type, $bundle);
  29. // Create fields for linking tables.
  30. tripal_chado_bundle_fields_info_linker($info, $details, $entity_type, $bundle);
  31. return $info;
  32. }
  33. /**
  34. *
  35. * @param unknown $details
  36. */
  37. function tripal_chado_bundle_fields_info_base(&$info, $details, $entity_type, $bundle) {
  38. $table_name = $details['chado_table'];
  39. $type_table = $details['chado_type_table'];
  40. $type_column = $details['chado_type_column'];
  41. $cvterm_id = $details['chado_cvterm_id'];
  42. $type_value = $details['chado_type_value'];
  43. // Iterate through the columns of the table and see if fields have been
  44. // created for each one. If not, then create them.
  45. $schema = chado_get_schema($table_name);
  46. if (!$schema) {
  47. return;
  48. }
  49. $pkey = $schema['primary key'][0];
  50. // Get the list of columns for this table and create a new field for each one.
  51. $columns = $schema['fields'];
  52. foreach ($columns as $column_name => $details) {
  53. // Skip the source columns in the analysis table. We have a custom
  54. // field for those columns
  55. if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
  56. $column_name == 'sourceversion' or $column_name == 'sourcename')) {
  57. continue;
  58. }
  59. // Skip the infraspecific type_id and name from the organism table as we
  60. // have a special field for those.
  61. if ($table_name == 'organism' and ($column_name == 'type_id' or
  62. $column_name == 'infraspecific_name')) {
  63. continue;
  64. }
  65. // Skip the cvterm.is_relationshptype.
  66. if ($table_name == 'cvterm' and $column_name == 'is_relationshiptype') {
  67. continue;
  68. }
  69. // The biosourceprovider_id and taxon_id are handled by custom fields.
  70. if ($table_name == 'biomaterial' and (
  71. $column_name == 'biosourceprovider_id' or $column_name == 'taxon_id')) {
  72. continue;
  73. }
  74. // Don't create base fields for the primary key and the type_id field.
  75. if ($column_name == $pkey or $column_name == $type_column) {
  76. continue;
  77. }
  78. $cvterm = chado_get_semweb_term($table_name, $column_name, ['return_object' => TRUE]);
  79. if (!$cvterm) {
  80. tripal_report_error('tripal', TRIPAL_ERROR,
  81. 'Cannot create field for "%table_name.%column_name". Missing an appropriate vocabulary term',
  82. ['%table_name' => $table_name, '%column_name' => $column_name]);
  83. drupal_set_message(t('Cannot create field for "%table_name.%column_name". Missing an appropriate vocabulary term',
  84. [
  85. '%table_name' => $table_name,
  86. '%column_name' => $column_name,
  87. ]), 'error');
  88. continue;
  89. }
  90. $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/[^\w]/', '_', $cvterm->name));
  91. $field_name = substr($field_name, 0, 32);
  92. // Skip the primary key field.
  93. if ($column_name == $schema['primary key'][0]) {
  94. continue;
  95. }
  96. // If the type_id defines the content type and it's part of the
  97. // base table and this column is the type_id then skip it.
  98. if (!$type_table and $type_column and $column_name == $type_column) {
  99. continue;
  100. }
  101. // Skip the type ID as it will be handled by a custom field.
  102. if ($column_name == 'type_id') {
  103. continue;
  104. }
  105. // Set some defaults for the field.
  106. $base_info = [
  107. 'field_name' => $field_name,
  108. 'type' => '',
  109. 'cardinality' => 1,
  110. 'locked' => FALSE,
  111. 'storage' => [
  112. 'type' => 'field_chado_storage',
  113. 'sql' => [],
  114. ],
  115. ];
  116. // Alter the field info array depending on the column details.
  117. switch ($details['type']) {
  118. case 'char':
  119. $base_info['type'] = 'text';
  120. $base_info['settings']['max_length'] = $details['length'];
  121. break;
  122. case 'varchar':
  123. $base_info['type'] = 'text';
  124. $base_info['settings']['max_length'] = $details['length'];
  125. break;
  126. case 'text':
  127. $base_info['type'] = 'text';
  128. $base_info['settings']['max_length'] = 17179869184;
  129. $base_info['settings']['text_processing'] = 1;
  130. break;
  131. case 'blob':
  132. // not sure how to support a blob field.
  133. continue 2;
  134. break;
  135. case 'int':
  136. $base_info['type'] = 'number_integer';
  137. break;
  138. case 'float':
  139. $base_info['type'] = 'number_float';
  140. $base_info['settings']['precision'] = 10;
  141. $base_info['settings']['scale'] = 2;
  142. $base_info['settings']['decimal_separator'] = '.';
  143. break;
  144. case 'numeric':
  145. $base_info['type'] = 'number_decimal';
  146. break;
  147. case 'serial':
  148. // Serial fields are most likely not needed as a field.
  149. break;
  150. case 'boolean':
  151. $base_info['type'] = 'list_boolean';
  152. $base_info['settings']['allowed_values'] = [0 => "No", 1 => "Yes"];
  153. break;
  154. case 'datetime':
  155. // Use the Drupal Date and Date API to create the field/widget
  156. $base_info['type'] = 'datetime';
  157. break;
  158. }
  159. // Set some defaults for biomaterial table
  160. if ($table_name == 'biomaterial' and $column_name == 'name') {
  161. $base_info['type'] = 'text';
  162. $base_info['settings']['max_length'] = '2048';
  163. $base_info['settings']['text_processing'] = 0;
  164. }
  165. // Set some default semantic web information
  166. if ($column_name == 'uniquename') {
  167. $base_info['settings']['text_processing'] = 0;
  168. }
  169. // Sometimes the boolean fields are listed as integer. We need to
  170. // correct for that.
  171. if ($column_name == 'is_obsolete' or $column_name == 'is_analysis' or
  172. $column_name == 'is_relationshiptype' or $column_name == 'is_for_definition' or
  173. $column_name == 'is_view' or $column_name == 'is_updateable') {
  174. $base_info['type'] = 'list_boolean';
  175. $base_info['settings']['allowed_values'] = [0 => "No", 1 => "Yes"];
  176. }
  177. //
  178. // PUB TABLE
  179. //
  180. if ($table_name == 'pub' and (
  181. $column_name == 'uniquename' or $column_name == 'title' or
  182. $column_name == 'volumetitle')) {
  183. $base_info['type'] = 'text';
  184. $base_info['settings']['text_processing'] = 0;
  185. }
  186. $info[$field_name] = $base_info;
  187. }
  188. }
  189. /**
  190. *
  191. * @param unknown $details
  192. */
  193. function tripal_chado_bundle_fields_info_custom(&$info, $details, $entity_type, $bundle) {
  194. $table_name = $details['chado_table'];
  195. $type_table = $details['chado_type_table'];
  196. $type_column = $details['chado_type_column'];
  197. $cvterm_id = $details['chado_cvterm_id'];
  198. $type_value = $details['chado_type_value'];
  199. $base_type_id = $details['chado_base_type_id'];
  200. $schema = chado_get_schema($table_name);
  201. // Add the additional_type field to all tables with a type_id that is not used
  202. // as the type column nor has a $base_type_id (i.e. the content type uses a
  203. // prop or linker table to resolve the type).
  204. if (array_key_exists('type_id', $schema['fields']) and 'type_id' != $type_column and
  205. !$base_type_id and $table_name != 'organism') {
  206. $field_name = 'schema__additional_type';
  207. $field_type = 'schema__additional_type';
  208. $info[$field_name] = [
  209. 'field_name' => $field_name,
  210. 'type' => $field_type,
  211. 'cardinality' => 1,
  212. 'locked' => FALSE,
  213. 'storage' => [
  214. 'type' => 'field_chado_storage',
  215. ],
  216. ];
  217. }
  218. // BASE ARRAYDESIGN TABLE
  219. if ($table_name == 'arraydesign') {
  220. $field_name = 'ncit__technology_platform';
  221. $field_type = 'schema__additional_type';
  222. $info[$field_name] = [
  223. 'field_name' => $field_name,
  224. 'type' => $field_type,
  225. 'cardinality' => 1,
  226. 'locked' => FALSE,
  227. 'storage' => [
  228. 'type' => 'field_chado_storage',
  229. ],
  230. ];
  231. $field_name = 'efo__substrate_type';
  232. $field_type = 'schema__additional_type';
  233. $info[$field_name] = [
  234. 'field_name' => $field_name,
  235. 'type' => $field_type,
  236. 'cardinality' => 1,
  237. 'locked' => FALSE,
  238. 'storage' => [
  239. 'type' => 'field_chado_storage',
  240. ],
  241. ];
  242. }
  243. // BASE ORGANISM_ID
  244. if ($table_name != 'organism' and
  245. (array_key_exists('organism_id', $schema['fields']) or
  246. array_key_exists('taxon_id', $schema['fields']))) {
  247. $field_name = 'obi__organism';
  248. $field_type = 'obi__organism';
  249. $info[$field_name] = [
  250. 'field_name' => $field_name,
  251. 'type' => $field_type,
  252. 'cardinality' => 1,
  253. 'locked' => FALSE,
  254. 'storage' => [
  255. 'type' => 'field_chado_storage',
  256. ],
  257. ];
  258. }
  259. if ($table_name == 'biomaterial') {
  260. $field_name = 'biomaterial__provider_id';
  261. $field_type = 'local__contact';
  262. $info[$field_name] = [
  263. 'field_name' => $field_name,
  264. 'type' => $field_type,
  265. 'cardinality' => 1,
  266. 'locked' => FALSE,
  267. 'storage' => [
  268. 'type' => 'field_chado_storage',
  269. ],
  270. ];
  271. }
  272. if ($table_name == 'arraydesign') {
  273. $field_name = 'efo__array_manufacturer';
  274. $field_type = 'local__contact';
  275. $info[$field_name] = [
  276. 'field_name' => $field_name,
  277. 'type' => $field_type,
  278. 'cardinality' => 1,
  279. 'locked' => FALSE,
  280. 'storage' => [
  281. 'type' => 'field_chado_storage',
  282. ],
  283. ];
  284. }
  285. // BASE ORGANISM_ID
  286. if ($table_name == 'cvterm') {
  287. $field_name = 'sio__vocabulary';
  288. $field_type = 'sio__vocabulary';
  289. $info[$field_name] = [
  290. 'field_name' => $field_name,
  291. 'type' => $field_type,
  292. 'cardinality' => 1,
  293. 'locked' => FALSE,
  294. 'storage' => [
  295. 'type' => 'field_chado_storage',
  296. ],
  297. ];
  298. }
  299. // BASE DBXREF
  300. if (array_key_exists('dbxref_id', $schema['fields'])) {
  301. $field_name = 'data__accession';
  302. $field_type = 'data__accession';
  303. $info[$field_name] = [
  304. 'field_name' => $field_name,
  305. 'type' => $field_type,
  306. 'cardinality' => 1,
  307. 'locked' => FALSE,
  308. 'storage' => [
  309. 'type' => 'field_chado_storage',
  310. ],
  311. ];
  312. }
  313. // FEATURE MD5CHECKSUM
  314. if ($table_name == 'feature') {
  315. $field_name = 'data__sequence_checksum';
  316. $field_type = 'data__sequence_checksum';
  317. $info[$field_name] = [
  318. 'field_name' => $field_name,
  319. 'type' => $field_type,
  320. 'cardinality' => 1,
  321. 'locked' => FALSE,
  322. 'storage' => [
  323. 'type' => 'field_chado_storage',
  324. ],
  325. ];
  326. }
  327. // FEATURE RESIDUES
  328. if ($table_name == 'feature') {
  329. $field_name = 'data__sequence';
  330. $field_type = 'data__sequence';
  331. $info[$field_name] = [
  332. 'field_name' => $field_name,
  333. 'type' => $field_type,
  334. 'cardinality' => 1,
  335. 'locked' => FALSE,
  336. 'storage' => [
  337. 'type' => 'field_chado_storage',
  338. ],
  339. ];
  340. }
  341. // FEATURE SEQLEN
  342. if ($table_name == 'feature') {
  343. $field_name = 'data__sequence_length';
  344. $field_type = 'data__sequence_length';
  345. $info[$field_name] = [
  346. 'field_name' => $field_name,
  347. 'type' => $field_type,
  348. 'cardinality' => 1,
  349. 'locked' => FALSE,
  350. 'storage' => [
  351. 'type' => 'field_chado_storage',
  352. ],
  353. ];
  354. }
  355. // PROTEIN & CDS
  356. if ($table_name == 'feature' and
  357. ($bundle->term->name == 'mRNA' or $bundle->term->name == 'transcript')) {
  358. $field_name = 'data__protein_sequence';
  359. $field_type = 'data__protein_sequence';
  360. $info[$field_name] = [
  361. 'field_name' => $field_name,
  362. 'type' => $field_type,
  363. 'cardinality' => 1,
  364. 'locked' => FALSE,
  365. 'storage' => [
  366. 'type' => 'field_chado_storage',
  367. ],
  368. ];
  369. $field_name = 'so__cds';
  370. $field_type = 'so__cds';
  371. $info[$field_name] = [
  372. 'field_name' => $field_name,
  373. 'type' => $field_type,
  374. 'cardinality' => 1,
  375. 'locked' => FALSE,
  376. 'storage' => [
  377. 'type' => 'field_chado_storage',
  378. ],
  379. ];
  380. }
  381. // GENE TRANSCRIPTS
  382. $rel_table = $table_name . '_relationship';
  383. if (chado_table_exists($rel_table) and ($bundle->term->name == 'gene')) {
  384. $field_name = 'so__transcript';
  385. $field_type = 'so__transcript';
  386. $info[$field_name] = [
  387. 'field_name' => $field_name,
  388. 'type' => $field_type,
  389. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  390. 'locked' => FALSE,
  391. 'storage' => [
  392. 'type' => 'field_chado_storage',
  393. ],
  394. ];
  395. }
  396. // ORGANISM TYPE_ID
  397. if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
  398. $field_name = 'taxrank__infraspecific_taxon';
  399. $field_type = 'taxrank__infraspecific_taxon';
  400. $info[$field_name] = [
  401. 'field_name' => $field_name,
  402. 'type' => $field_type,
  403. 'cardinality' => 1,
  404. 'locked' => FALSE,
  405. 'storage' => [
  406. 'type' => 'field_chado_storage',
  407. ],
  408. ];
  409. }
  410. // FEATUREMAP UNITTYPE_ID
  411. if ($table_name == 'featuremap') {
  412. $field_name = 'uo__unit';
  413. $field_type = 'uo__unit';
  414. $info[$field_name] = [
  415. 'field_name' => $field_name,
  416. 'type' => $field_type,
  417. 'cardinality' => 1,
  418. 'locked' => FALSE,
  419. 'storage' => [
  420. 'type' => 'field_chado_storage',
  421. ],
  422. ];
  423. }
  424. // Analysis source
  425. if ($table_name == 'analysis') {
  426. $field_name = 'local__source_data';
  427. $field_type = 'local__source_data';
  428. $info[$field_name] = [
  429. 'field_name' => $field_name,
  430. 'type' => $field_type,
  431. 'cardinality' => 1,
  432. 'locked' => FALSE,
  433. 'storage' => [
  434. 'type' => 'field_chado_storage',
  435. ],
  436. ];
  437. }
  438. // Add an image field to the Organism type. This is a Drupal field and
  439. // not stored in Chado, but is used for backwards compatibility.
  440. if ($table_name == 'organism') {
  441. $field_name = 'data__image';
  442. $info[$field_name] = [
  443. 'field_name' => $field_name,
  444. 'type' => 'image',
  445. 'cardinality' => 1,
  446. 'locked' => FALSE,
  447. 'storage' => [
  448. 'type' => 'field_sql_storage',
  449. ],
  450. ];
  451. }
  452. // Add field for viewing the phylogenetic tree.
  453. if ($table_name == 'phylotree') {
  454. $field_name = 'operation__phylotree_vis';
  455. $field_type = 'operation__phylotree_vis';
  456. $info[$field_name] = [
  457. 'field_name' => $field_name,
  458. 'type' => $field_type,
  459. 'cardinality' => 1,
  460. 'locked' => FALSE,
  461. 'storage' => [
  462. 'type' => 'field_chado_storage',
  463. ],
  464. ];
  465. }
  466. // Protocol.
  467. if ($table_name != 'protocol' and
  468. array_key_exists('protocol_id', $schema['fields'])) {
  469. $field_name = 'sep__protocol';
  470. $field_type = 'sep__protocol';
  471. $info[$field_name] = [
  472. 'field_name' => $field_name,
  473. 'type' => $field_type,
  474. 'cardinality' => 1,
  475. 'locked' => FALSE,
  476. 'storage' => [
  477. 'type' => 'field_chado_storage',
  478. ],
  479. ];
  480. }
  481. // Assay operator.
  482. if ($table_name == 'assay') {
  483. $field_name = 'assay__operator_id';
  484. $field_type = 'local__contact';
  485. $info[$field_name] = [
  486. 'field_name' => $field_name,
  487. 'type' => $field_type,
  488. 'cardinality' => 1,
  489. 'locked' => FALSE,
  490. 'storage' => [
  491. 'type' => 'field_chado_storage',
  492. ],
  493. ];
  494. $field_name = 'efo__array_design';
  495. $field_type = 'efo__array_design';
  496. $info[$field_name] = [
  497. 'field_name' => $field_name,
  498. 'type' => $field_type,
  499. 'cardinality' => 1,
  500. 'locked' => FALSE,
  501. 'storage' => [
  502. 'type' => 'field_chado_storage',
  503. ],
  504. ];
  505. }
  506. // For the pub_id field in the base table.
  507. $schema = chado_get_schema($table_name);
  508. if (array_key_exists('pub_id', $schema['fields']) and $table_name != 'pub') {
  509. // Remove the schema__publication added by the
  510. // tripal_chado_bunde_instnaces_info_base function.
  511. unset($info['schema__publication']);
  512. $field_name = 'schema__publication_single';
  513. $field_type = 'schema__publication';
  514. $info[$field_name] = [
  515. 'field_name' => $field_name,
  516. 'type' => $field_type,
  517. 'cardinality' => 1,
  518. 'locked' => FALSE,
  519. 'storage' => [
  520. 'type' => 'field_chado_storage',
  521. ],
  522. ];
  523. }
  524. // Analysis Id
  525. if (array_key_exists('analysis_id', $schema['fields']) and $table_name != 'analysis') {
  526. $field_name = 'operation__analysis';
  527. $field_type = 'operation__analysis';
  528. $info[$field_name] = [
  529. 'field_name' => $field_name,
  530. 'type' => $field_type,
  531. 'cardinality' => 1,
  532. 'locked' => FALSE,
  533. 'storage' => [
  534. 'type' => 'field_chado_storage',
  535. ],
  536. ];
  537. }
  538. }
  539. /**
  540. *
  541. * @param $details
  542. */
  543. function tripal_chado_bundle_fields_info_linker(&$info, $details, $entity_type, $bundle) {
  544. $table_name = $details['chado_table'];
  545. $type_table = $details['chado_type_table'];
  546. $type_column = $details['chado_type_column'];
  547. $cvterm_id = $details['chado_cvterm_id'];
  548. $type_value = $details['chado_type_value'];
  549. // CONTACTS
  550. $contact_table = $table_name . '_contact';
  551. if (chado_table_exists($contact_table)) {
  552. $schema = chado_get_schema($contact_table);
  553. $pkey = $schema['primary key'][0];
  554. $field_name = $table_name . '_contact';
  555. $field_type = 'chado_linker__contact';
  556. $info[$field_name] = [
  557. 'field_name' => $field_name,
  558. 'type' => $field_type,
  559. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  560. 'locked' => FALSE,
  561. 'storage' => [
  562. 'type' => 'field_chado_storage',
  563. ],
  564. ];
  565. }
  566. // DBXREF
  567. $dbxref_table = $table_name . '_dbxref';
  568. if (chado_table_exists($dbxref_table)) {
  569. $field_name = 'sbo__database_cross_reference';
  570. $field_type = 'sbo__database_cross_reference';
  571. $info[$field_name] = [
  572. 'field_name' => $field_name,
  573. 'type' => $field_type,
  574. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  575. 'locked' => FALSE,
  576. 'storage' => [
  577. 'type' => 'field_chado_storage',
  578. ],
  579. ];
  580. }
  581. // EXPRESSION
  582. // TODO: this should only show up on gene or mRNA bunldes, not every feature.
  583. // $expression_table = $table_name . '_expression';
  584. // if (chado_table_exists($expression_table)) {
  585. // $field_name = 'go__gene_expression';
  586. // $field_type = 'go__gene_expression';
  587. // $info[$field_name] = array(
  588. // 'field_name' => $field_name,
  589. // 'type' => $field_type,
  590. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  591. // 'locked' => FALSE,
  592. // 'storage' => array(
  593. // 'type' => 'field_chado_storage',
  594. // ),
  595. // );
  596. // }
  597. // FEATURELOC
  598. if ($table_name == 'feature') {
  599. $field_name = 'data__sequence_coordinates';
  600. $field_type = 'data__sequence_coordinates';
  601. $info[$field_name] = [
  602. 'field_name' => $field_name,
  603. 'type' => $field_type,
  604. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  605. 'locked' => FALSE,
  606. 'storage' => [
  607. 'type' => 'field_chado_storage',
  608. ],
  609. ];
  610. }
  611. // FEATUREPOS
  612. if ($table_name == 'feature') {
  613. $field_name = 'ogi__location_on_map';
  614. $field_type = 'ogi__location_on_map';
  615. $info[$field_name] = [
  616. 'field_name' => $field_name,
  617. 'type' => $field_type,
  618. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  619. 'locked' => FALSE,
  620. 'storage' => [
  621. 'type' => 'field_chado_storage',
  622. ],
  623. ];
  624. }
  625. // // GENOTYPE
  626. // $genotype_table = $table_name . '_genotype';
  627. // if (chado_table_exists($genotype_table)) {
  628. // $field_name = 'so__genotype';
  629. // $field_type = 'so__genotype';
  630. // $info[$field_name] = array(
  631. // 'field_name' => $field_name,
  632. // 'type' => $field_type,
  633. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  634. // 'locked' => FALSE,
  635. // 'storage' => array(
  636. // 'type' => 'field_chado_storage',
  637. // ),
  638. // );
  639. // }
  640. // // PHENOTYPE
  641. // $phenotype_table = $table_name . '_phenotype';
  642. // if (chado_table_exists($phenotype_table)) {
  643. // $field_name = 'sbo__phenotype';
  644. // $field_type = 'sbo__phenotype';
  645. // $info[$field_name] = array(
  646. // 'field_name' => $field_name,
  647. // 'type' => $field_type,
  648. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  649. // 'locked' => FALSE,
  650. // 'storage' => array(
  651. // 'type' => 'field_chado_storage',
  652. // ),
  653. // );
  654. // }
  655. // PROPERTIES
  656. $prop_table = $table_name . 'prop';
  657. if (chado_table_exists($prop_table)) {
  658. $props = tripal_chado_bundle_get_properties($table_name, $prop_table, $type_table, $type_column, $cvterm_id, $type_value);
  659. foreach ($props as $term) {
  660. $field_name = strtolower(preg_replace('/[^\w]/', '_', $term->dbxref_id->db_id->name . '__' . $term->name));
  661. // The field name can only be 32 chars, but if our name is longer we need
  662. // to add some random chars to ensure we don't have naming conflicts
  663. // with other terms (e.g. mitochondrial_genetic_code and
  664. // mitochondrial_genetic_code_name)
  665. if (strlen($field_name) >= 32) {
  666. $field_name = substr($field_name, 0, 20) . '_' . $term->cvterm_id;
  667. }
  668. $field_type = 'chado_linker__prop';
  669. // Don't try to add a property that uses the same term as another field.
  670. if (array_key_exists($field_name, $info)) {
  671. tripal_report_error('chado_fields', TRIPAL_WARNING,
  672. 'A field of type !type already exists, yet a property wants to use the same term. The property cannot be added.',
  673. ['!type' => $field_name],
  674. ['drupal_set_message' => TRUE]);
  675. continue;
  676. }
  677. $info[$field_name] = [
  678. 'field_name' => $field_name,
  679. 'type' => $field_type,
  680. 'cardinality' => 1,
  681. 'locked' => FALSE,
  682. 'storage' => [
  683. 'type' => 'field_chado_storage',
  684. ],
  685. ];
  686. }
  687. }
  688. // CVTERMS
  689. $term_table = $table_name . '_cvterm';
  690. if (chado_table_exists($term_table)) {
  691. $schema = chado_get_schema($term_table);
  692. $pkey = $schema['primary key'][0];
  693. $lkey = key($schema['foreign keys'][$table_name]['columns']);
  694. $rkey = $schema['foreign keys'][$table_name]['columns'][$lkey];
  695. $field_name = 'sio__annotation';
  696. $field_type = 'sio__annotation';
  697. $info[$field_name] = [
  698. 'field_name' => $field_name,
  699. 'type' => $field_type,
  700. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  701. 'locked' => FALSE,
  702. 'storage' => [
  703. 'type' => 'field_chado_storage',
  704. ],
  705. ];
  706. }
  707. // PUBLICATIONS
  708. $pub_table = $table_name . '_pub';
  709. if (chado_table_exists($pub_table)) {
  710. $field_name = 'schema__publication';
  711. $field_type = 'schema__publication';
  712. $info[$field_name] = [
  713. 'field_name' => $field_name,
  714. 'type' => $field_type,
  715. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  716. 'locked' => FALSE,
  717. 'storage' => [
  718. 'type' => 'field_chado_storage',
  719. ],
  720. ];
  721. }
  722. // PUBLICATIONS (in reverse)
  723. // We want to be able to show all of the content that a publication links
  724. // to. The sio__references field does that.
  725. if ($table_name == 'pub') {
  726. $field_name = 'sio__references';
  727. $field_type = 'sio__references';
  728. $info[$field_name] = [
  729. 'field_name' => $field_name,
  730. 'type' => $field_type,
  731. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  732. 'locked' => FALSE,
  733. 'storage' => [
  734. 'type' => 'field_chado_storage',
  735. ],
  736. ];
  737. }
  738. // RELATIONSHIPS
  739. // If the linker table does not exists then we don't want to add attach.
  740. $rel_table = $table_name . '_relationship';
  741. if (chado_table_exists($rel_table)) {
  742. $field_name = 'sbo__relationship';
  743. $field_type = 'sbo__relationship';
  744. $info[$field_name] = [
  745. 'field_name' => $field_name,
  746. 'type' => $field_type,
  747. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  748. 'locked' => FALSE,
  749. 'storage' => [
  750. 'type' => 'field_chado_storage',
  751. ],
  752. ];
  753. }
  754. // SYNONYMS
  755. $syn_table = $table_name . '_synonym';
  756. if (chado_table_exists($syn_table)) {
  757. $field_name = 'schema__alternate_name';
  758. $field_type = 'schema__alternate_name';
  759. $info[$field_name] = [
  760. 'field_name' => $field_name,
  761. 'type' => $field_type,
  762. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  763. 'locked' => FALSE,
  764. 'storage' => [
  765. 'type' => 'field_chado_storage',
  766. ],
  767. 'settings' => [
  768. ],
  769. ];
  770. }
  771. }
  772. /**
  773. * Impelments hook_create_tripalfield_instance().
  774. *
  775. * This is a Tripal defined hook that supports integration with the
  776. * TripalEntity field.
  777. */
  778. function tripal_chado_bundle_instances_info($entity_type, $bundle) {
  779. $chado_bundle = db_select('chado_bundle', 'cb')
  780. ->fields('cb')
  781. ->condition('bundle_id', $bundle->id)
  782. ->execute()
  783. ->fetchObject();
  784. $details = [
  785. 'chado_cvterm_id' => $chado_bundle->type_id,
  786. 'chado_table' => $chado_bundle->data_table,
  787. 'chado_type_table' => $chado_bundle->type_linker_table,
  788. 'chado_type_id' => $chado_bundle->type_id,
  789. 'chado_type_column' => $chado_bundle->type_column,
  790. 'chado_type_value' => $chado_bundle->type_value,
  791. 'chado_base_type_id' => $chado_bundle->base_type_id,
  792. ];
  793. $info = [];
  794. tripal_chado_bundle_instances_info_base($info, $entity_type, $bundle, $details);
  795. tripal_chado_bundle_instances_info_custom($info, $entity_type, $bundle, $details);
  796. tripal_chado_bundle_instances_info_linker($info, $entity_type, $bundle, $details);
  797. return $info;
  798. }
  799. /**
  800. * Helper function for the hook_create_tripalfield_instance().
  801. *
  802. * Add the field instances that corresond to the columns of the base table.
  803. *
  804. * @param $entity_type
  805. * @param $bundle
  806. * @param $details
  807. */
  808. function tripal_chado_bundle_instances_info_base(&$info, $entity_type, $bundle, $details) {
  809. $fields = [];
  810. // Get Chado information
  811. $table_name = $details['chado_table'];
  812. $type_table = $details['chado_type_table'];
  813. $type_column = $details['chado_type_column'];
  814. $cvterm_id = $details['chado_cvterm_id'];
  815. $type_value = $details['chado_type_value'];
  816. // Iterate through the columns of the table and see if fields have been
  817. // created for each one. If not, then create them.
  818. $schema = chado_get_schema($table_name);
  819. if (!$schema) {
  820. return;
  821. }
  822. $pkey = $schema['primary key'][0];
  823. $columns = $schema['fields'];
  824. foreach ($columns as $column_name => $details) {
  825. // Skip the source columns in the analysis table. We have a custom
  826. // field for those columns
  827. if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
  828. $column_name == 'sourceversion' or $column_name == 'sourcename')) {
  829. continue;
  830. }
  831. // Skip the infraspecific type_id and name from the organism table as we
  832. // have a special field for those.
  833. if ($table_name == 'organism' and ($column_name == 'type_id' or
  834. $column_name == 'infraspecific_name')) {
  835. continue;
  836. }
  837. // Skip the cvterm.is_relationshptype.
  838. if ($table_name == 'cvterm' and $column_name == 'is_relationshiptype') {
  839. continue;
  840. }
  841. // The biosourceprovider_id and taxon_id are handled by custom fields.
  842. if ($table_name == 'biomaterial' and (
  843. $column_name == 'biosourceprovider_id' or $column_name == 'taxon_id')) {
  844. continue;
  845. }
  846. // Don't create base fields for the primary key and the type_id field.
  847. if ($column_name == $pkey or $column_name == $type_column) {
  848. continue;
  849. }
  850. $cvterm = chado_get_semweb_term($table_name, $column_name, ['return_object' => TRUE]);
  851. if (!$cvterm) {
  852. // We already provided an error when creating the base field. So
  853. // don't create another one here.
  854. continue;
  855. }
  856. $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/[^\w]/', '_', $cvterm->name));
  857. $field_name = substr($field_name, 0, 32);
  858. // Skip the primary key field.
  859. if ($column_name == $schema['primary key'][0]) {
  860. continue;
  861. }
  862. // If the type_id defines the content type and it's part of the
  863. // base table and this column is the type_id then skip it.
  864. if (!$type_table and $type_column and $column_name == $type_column) {
  865. continue;
  866. }
  867. // Skip the type ID as it will be handled by a custom field.
  868. if ($column_name == 'type_id') {
  869. continue;
  870. }
  871. $base_info = [
  872. 'field_name' => $field_name,
  873. 'entity_type' => 'TripalEntity',
  874. 'bundle' => $bundle->name,
  875. 'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
  876. 'description' => '',
  877. 'required' => FALSE,
  878. 'settings' => [
  879. 'auto_attach' => TRUE,
  880. 'term_vocabulary' => $cvterm->dbxref_id->db_id->name,
  881. 'term_name' => $cvterm->name,
  882. 'term_accession' => $cvterm->dbxref_id->accession,
  883. 'chado_table' => $table_name,
  884. 'chado_column' => $column_name,
  885. 'base_table' => $table_name,
  886. ],
  887. 'widget' => [
  888. 'settings' => [
  889. 'display_label' => 1,
  890. ],
  891. ],
  892. 'display' => [
  893. 'default' => [
  894. 'label' => 'inline',
  895. 'region' => 'Left',
  896. 'settings' => [],
  897. ],
  898. ],
  899. ];
  900. // Determine if the field is required.
  901. if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
  902. $base_info['required'] = TRUE;
  903. }
  904. // Alter the field info array depending on the column details.
  905. switch ($details['type']) {
  906. case 'char':
  907. $base_info['widget']['type'] = 'text_textfield';
  908. break;
  909. case 'varchar':
  910. $base_info['widget']['type'] = 'text_textfield';
  911. break;
  912. case 'text':
  913. $base_info['display']['default']['label'] = 'above';
  914. $base_info['widget']['type'] = 'text_textarea';
  915. $base_info['settings']['text_processing'] = '1';
  916. $base_info['settings']['format'] = 'full_html';
  917. break;
  918. case 'blob':
  919. // not sure how to support a blob field.
  920. continue 2;
  921. break;
  922. case 'int':
  923. $base_info['widget']['type'] = 'number';
  924. break;
  925. case 'float':
  926. $base_info['widget']['type'] = 'number';
  927. break;
  928. case 'numeric':
  929. $base_info['widget']['type'] = 'number';
  930. break;
  931. case 'serial':
  932. // Serial fields are most likely not needed as a field.
  933. break;
  934. case 'boolean':
  935. $base_info['widget']['type'] = 'options_onoff';
  936. $base_info['required'] = FALSE;
  937. break;
  938. case 'datetime':
  939. $base_info['widget']['type'] = 'date_select';
  940. $base_info['widget']['settings']['increment'] = 1;
  941. $base_info['widget']['settings']['tz_handling'] = 'none';
  942. $base_info['widget']['settings']['collapsible'] = TRUE;
  943. $base_info['widget']['settings']['year_range'] = '-10:+10';
  944. break;
  945. }
  946. // Set some default semantic web information
  947. if ($column_name == 'uniquename') {
  948. $base_info['label'] = 'Identifier';
  949. $base_info['widget']['type'] = 'text_textfield';
  950. if ($details['type'] == 'text') {
  951. unset($base_info['display']['default']['label']);
  952. unset($base_info['settings']['text_processing']);
  953. unset($base_info['settings']['format']);
  954. }
  955. }
  956. if ($base_info['label'] == 'Timeaccessioned') {
  957. $base_info['label'] = 'Time Accessioned';
  958. $base_info['description'] = 'The time that this record was first added to the database.';
  959. }
  960. if ($base_info['label'] == 'Timelastmodified') {
  961. $base_info['label'] = 'Time Last Modified';
  962. $base_info['description'] = 'The time that this record was last modified. The default is the current time.';
  963. }
  964. // Sometimes the boolean fields are listed as integer. We need to
  965. // correct for that.
  966. if ($column_name == 'is_obsolete' or $column_name == 'is_analysis' or
  967. $column_name == 'is_relationshiptype' or $column_name == 'is_for_definition' or
  968. $column_name == 'is_view' or $column_name == 'is_updateable') {
  969. $base_info['widget']['type'] = 'options_onoff';
  970. $base_info['required'] = FALSE;
  971. }
  972. //
  973. // ORGANISM TABLE
  974. //
  975. if ($table_name == 'organism' and $column_name == 'comment') {
  976. $base_info['label'] = 'Description';
  977. }
  978. //
  979. // BIOMATERIAL TABLE
  980. //
  981. if ($table_name == 'biomaterial' and $column_name == 'name') {
  982. $base_info['widget'] = [];
  983. $base_info['widget']['type'] = 'text_textfield';
  984. unset($base_info['display']['default']['label']);
  985. unset($base_info['settings']['text_processing']);
  986. unset($base_info['settings']['format']);
  987. }
  988. //
  989. // FEATUREMAP TABLE
  990. //
  991. if ($table_name == 'featuremap' and $column_name == 'name') {
  992. $base_info['required'] = TRUE;
  993. }
  994. //
  995. // PUB TABLE
  996. //
  997. if ($table_name == 'pub') {
  998. if ($column_name == 'title' or $column_name == 'type_id') {
  999. $base_info['required'] = TRUE;
  1000. }
  1001. if ($column_name == 'uniquename' or $column_name == 'title' or $column_name == 'volumetitle') {
  1002. $base_info['widget']['type'] = 'text_textfield';
  1003. $base_info['settings']['text_processing'] = '0';
  1004. }
  1005. if ($column_name == 'uniquename') {
  1006. $base_info['label'] = 'Unique Local Identifier';
  1007. $base_info['required'] = TRUE;
  1008. $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.';
  1009. }
  1010. if ($column_name == 'title') {
  1011. $base_info['description'] = 'The title of the published work.';
  1012. }
  1013. if ($column_name == 'series_name') {
  1014. $base_info['description'] = 'The name media that produces a series of publications (e.g. journal, conference proceedings, etc.).';
  1015. }
  1016. if ($column_name == 'issue') {
  1017. $base_info['description'] = 'The issue of the series (e.g. journal) where the publication was printed.';
  1018. }
  1019. if ($column_name == 'volume') {
  1020. $base_info['description'] = 'The volume of the series (e.g. journal) where the publication was printed.';
  1021. }
  1022. if ($column_name == 'pyear') {
  1023. $base_info['label'] = 'Publication Year';
  1024. $base_info['required'] = TRUE;
  1025. }
  1026. if ($column_name == 'pages') {
  1027. $base_info['label'] = 'Page Numbers';
  1028. }
  1029. if ($column_name == 'pubplace') {
  1030. $base_info['label'] = 'Publication Location';
  1031. }
  1032. if ($column_name == 'volumetitle') {
  1033. $base_info['label'] = 'Volumn Title';
  1034. $base_info['label'] = 'The title of the volume (if applicable).';
  1035. }
  1036. if ($column_name == 'miniref') {
  1037. $base_info['label'] = 'Mini Local identifier';
  1038. $base_info['description'] = 'Some sites use small identifiers for each publication. if your site uses this please provide the proper miniref for this publication.';
  1039. }
  1040. }
  1041. //
  1042. // ANALYSIS TABLE
  1043. //
  1044. if ($table_name == 'analysis' and $column_name == 'name') {
  1045. $base_info['required'] = TRUE;
  1046. }
  1047. if ($table_name == 'analysis' and $column_name == 'program') {
  1048. $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.';
  1049. $base_info['label'] = 'Program, Pipeline, Workflow or Method Name';
  1050. }
  1051. if ($table_name == 'analysis' and $column_name == 'algorithm') {
  1052. $base_info['label'] = 'Algorithm';
  1053. $base_info['description'] = 'The name of the algorithm used to produce the dataset if different from the program.';
  1054. }
  1055. if ($table_name == 'analysis' and $column_name == 'programversion') {
  1056. $base_info['label'] = 'Program Version';
  1057. $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.';
  1058. }
  1059. if ($table_name == 'analysis' and $column_name == 'timeexecuted') {
  1060. $base_info['label'] = 'Date Performed';
  1061. $base_info['description'] = 'The date and time when the analysis was performed.';
  1062. }
  1063. if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
  1064. $column_name == 'sourceversion' or $column_name == 'sourcename')) {
  1065. // Skip the source columns in the analysis table. We have a custom
  1066. // field for those columns
  1067. continue;
  1068. }
  1069. //
  1070. // PROJECT TABLE
  1071. //
  1072. if ($table_name == 'project' and $column_name == 'description') {
  1073. $base_info['label'] = 'Short Description';
  1074. }
  1075. //
  1076. // CONTACT TABLE
  1077. //
  1078. if ($table_name == 'contact' and $column_name == 'description') {
  1079. $base_info['label'] = 'Short Description';
  1080. }
  1081. //
  1082. // PROTOCOL TABLE
  1083. //
  1084. if ($table_name == 'protocol') {
  1085. if ($column_name == 'protocoldescription') {
  1086. $base_info['label'] = 'Protocol Description';
  1087. }
  1088. if ($column_name == 'uri') {
  1089. $base_info['label'] = 'URI';
  1090. $base_info['widget']['type'] = 'text_textfield';
  1091. $base_info['settings']['text_processing'] = '0';
  1092. }
  1093. if ($column_name == 'name') {
  1094. $base_info['widget']['type'] = 'text_textfield';
  1095. $base_info['settings']['text_processing'] = '0';
  1096. }
  1097. if ($column_name == 'hardwaredescription') {
  1098. $base_info['label'] = 'Instrument Description';
  1099. $base_info['description'] = 'The description of instruments used for this protocol';
  1100. }
  1101. if ($column_name == 'softwaredescription') {
  1102. $base_info['label'] = 'Software Description';
  1103. $base_info['description'] = 'The description of software used for this protocol';
  1104. }
  1105. if ($column_name == 'pub_id') {
  1106. $base_info['label'] = 'Publication';
  1107. }
  1108. }
  1109. //
  1110. // ASSAY TABLE
  1111. //
  1112. if ($table_name == 'assay') {
  1113. if ($column_name == 'name') {
  1114. $base_info['widget']['type'] = 'text_textfield';
  1115. $base_info['settings']['text_processing'] = '0';
  1116. $base_info['required'] = TRUE;
  1117. $base_info['description'] = 'A unique name for this assay..';
  1118. }
  1119. if ($column_name == 'protcol_id') {
  1120. $base_info['label'] = 'Protocol';
  1121. }
  1122. if ($column_name == 'arraybatchidentifier') {
  1123. $base_info['label'] = 'Array Batch Identifier';
  1124. $base_info['widget']['type'] = 'text_textfield';
  1125. $base_info['settings']['text_processing'] = '0';
  1126. $base_info['description'] = 'A unique identifier for the array batch.';
  1127. }
  1128. if ($column_name == 'operator_id') {
  1129. $base_info['label'] = 'Operator';
  1130. $base_info['description'] = 'The individual who performed the assay.';
  1131. }
  1132. if ($column_name == 'arrayidentifier') {
  1133. $base_info['label'] = 'Array Identifier';
  1134. $base_info['widget']['type'] = 'text_textfield';
  1135. $base_info['settings']['text_processing'] = '0';
  1136. $base_info['description'] = 'A unique alternate identifier for the array.';
  1137. }
  1138. if ($column_name == 'arraydesign_id') {
  1139. $base_info['label'] = 'Array Design';
  1140. }
  1141. if ($column_name == 'assaydate') {
  1142. $base_info['label'] = 'Assay Date';
  1143. $base_info['description'] = 'The date the assay was performed';
  1144. }
  1145. }
  1146. //
  1147. // ARRAYDESIGN TABLE
  1148. //
  1149. if ($table_name == 'arraydesign') {
  1150. if ($column_name == 'name' or $column_name == 'version' or
  1151. $column_name == 'array_dimensions' or $column_name == 'element_dimensions') {
  1152. $base_info['widget']['type'] = 'text_textfield';
  1153. $base_info['settings']['text_processing'] = '0';
  1154. }
  1155. if ($column_name == 'platformtype_id') {
  1156. $base_info['label'] = 'Platform type';
  1157. }
  1158. if ($column_name == 'substratetype_id') {
  1159. $base_info['label'] = 'Substrate Type';
  1160. }
  1161. if ($column_name == 'manufacturer_id') {
  1162. $base_info['label'] = 'Manufacturer';
  1163. }
  1164. }
  1165. $info[$field_name] = $base_info;
  1166. }
  1167. }
  1168. /**
  1169. * Helper function for the hook_create_tripalfield_instance().
  1170. *
  1171. * Adds custom fields for base fields. These override the settings provided
  1172. * in the tripal_chado_create_tripalfield_instance_base() function.
  1173. *
  1174. * @param $entity_type
  1175. * @param $bundle
  1176. * @param $details
  1177. */
  1178. function tripal_chado_bundle_instances_info_custom(&$info, $entity_type, $bundle, $details) {
  1179. $table_name = $details['chado_table'];
  1180. $type_table = $details['chado_type_table'];
  1181. $type_column = $details['chado_type_column'];
  1182. $cvterm_id = $details['chado_cvterm_id'];
  1183. $type_value = $details['chado_type_value'];
  1184. $base_type_id = $details['chado_base_type_id'];
  1185. $schema = chado_get_schema($table_name);
  1186. // Add the additional_type field to all tables with a type_id that is not used
  1187. // as the type column nor has a $base_type_id (i.e. the content type uses a
  1188. // prop or linker table to resolve the type).
  1189. if (array_key_exists('type_id', $schema['fields']) and 'type_id' != $type_column and
  1190. !$base_type_id and $table_name != 'organism') {
  1191. $field_name = 'schema__additional_type';
  1192. $is_required = FALSE;
  1193. if (array_key_exists('not null', $schema['fields']['type_id']) and
  1194. $schema['fields']['type_id']['not null']) {
  1195. $is_required = TRUE;
  1196. }
  1197. $label = ucwords(preg_replace('/_/', ' ', $table_name)) . ' Type';
  1198. $default_vocab = '';
  1199. $parent_term = '';
  1200. switch ($table_name) {
  1201. case 'pub':
  1202. $default_vocab = 'tripal_pub';
  1203. $label = 'Publication Type';
  1204. $parent_term = 'TPUB:0000015';
  1205. $description = 'Select the type.';
  1206. break;
  1207. case 'contact':
  1208. $default_vocab = 'tripal_contact';
  1209. $parent_term = 'TCONTACT:0000001';
  1210. $description = 'Select the type.';
  1211. break;
  1212. default:
  1213. $description = t('Enter the name of the term that specifies the type. ' .
  1214. 'The type must be the name of a term in a controlled vocabulary and ' .
  1215. 'the controlled vocabulary should already be loaded into this site.');
  1216. }
  1217. $info[$field_name] = [
  1218. 'field_name' => $field_name,
  1219. 'entity_type' => $entity_type,
  1220. 'bundle' => $bundle->name,
  1221. 'label' => $label,
  1222. 'description' => $description,
  1223. 'required' => $is_required,
  1224. 'settings' => [
  1225. 'auto_attach' => TRUE,
  1226. 'chado_table' => $table_name,
  1227. 'chado_column' => 'type_id',
  1228. 'base_table' => $table_name,
  1229. 'vocabulary' => $default_vocab,
  1230. 'parent_term' => $parent_term,
  1231. 'term_vocabulary' => 'schema',
  1232. 'term_name' => 'additionalType',
  1233. 'term_accession' => 'additionalType',
  1234. ],
  1235. 'widget' => [
  1236. 'type' => 'schema__additional_type_widget',
  1237. 'settings' => [
  1238. 'display_label' => 1,
  1239. ],
  1240. ],
  1241. 'display' => [
  1242. 'default' => [
  1243. 'label' => 'inline',
  1244. 'type' => 'schema__additional_type_formatter',
  1245. 'settings' => [],
  1246. ],
  1247. ],
  1248. ];
  1249. }
  1250. if ($table_name == 'arraydesign') {
  1251. $field_name = 'ncit__technology_platform';
  1252. $default_vocab = '';
  1253. $parent_term = '';
  1254. $description = 'Select the platform type.';
  1255. $info[$field_name] = [
  1256. 'field_name' => $field_name,
  1257. 'entity_type' => $entity_type,
  1258. 'bundle' => $bundle->name,
  1259. 'label' => 'Platform Type',
  1260. 'description' => $description,
  1261. 'required' => TRUE,
  1262. 'settings' => [
  1263. 'auto_attach' => TRUE,
  1264. 'chado_table' => $table_name,
  1265. 'chado_column' => 'platformtype_id',
  1266. 'base_table' => $table_name,
  1267. 'vocabulary' => $default_vocab,
  1268. 'parent_term' => $parent_term,
  1269. 'term_vocabulary' => 'NCIT',
  1270. 'term_name' => 'Technology Platform',
  1271. 'term_accession' => 'C45378',
  1272. ],
  1273. 'widget' => [
  1274. 'type' => 'schema__additional_type_widget',
  1275. 'settings' => [
  1276. 'display_label' => 1,
  1277. ],
  1278. ],
  1279. 'display' => [
  1280. 'default' => [
  1281. 'label' => 'inline',
  1282. 'type' => 'schema__additional_type_formatter',
  1283. 'settings' => [],
  1284. ],
  1285. ],
  1286. ];
  1287. $field_name = 'efo__substrate_type';
  1288. $default_vocab = '';
  1289. $parent_term = '';
  1290. $description = 'Select the substrate type.';
  1291. $info[$field_name] = [
  1292. 'field_name' => $field_name,
  1293. 'entity_type' => $entity_type,
  1294. 'bundle' => $bundle->name,
  1295. 'label' => 'Substrate Type',
  1296. 'description' => $description,
  1297. 'required' => FALSE,
  1298. 'settings' => [
  1299. 'auto_attach' => TRUE,
  1300. 'chado_table' => $table_name,
  1301. 'chado_column' => 'substratetype_id',
  1302. 'base_table' => $table_name,
  1303. 'vocabulary' => $default_vocab,
  1304. 'parent_term' => $parent_term,
  1305. 'term_vocabulary' => 'EFO',
  1306. 'term_name' => 'substrate type',
  1307. 'term_accession' => '0005522',
  1308. ],
  1309. 'widget' => [
  1310. 'type' => 'schema__additional_type_widget',
  1311. 'settings' => [
  1312. 'display_label' => 1,
  1313. ],
  1314. ],
  1315. 'display' => [
  1316. 'default' => [
  1317. 'label' => 'inline',
  1318. 'type' => 'schema__additional_type_formatter',
  1319. 'settings' => [],
  1320. ],
  1321. ],
  1322. ];
  1323. }
  1324. // BASE ORGANISM_ID
  1325. if ($table_name != 'organism' and
  1326. (array_key_exists('organism_id', $schema['fields']) or
  1327. array_key_exists('taxon_id', $schema['fields']))) {
  1328. $field_name = 'obi__organism';
  1329. $is_required = FALSE;
  1330. $table_column = 'organism_id';
  1331. if ($table_name == 'biomaterial') {
  1332. $is_required = FALSE;
  1333. $table_column = 'taxon_id';
  1334. }
  1335. elseif (array_key_exists('not null', $schema['fields']['organism_id']) and
  1336. $schema['fields']['organism_id']['not null']) {
  1337. $is_required = TRUE;
  1338. }
  1339. $info[$field_name] = [
  1340. 'field_name' => $field_name,
  1341. 'entity_type' => $entity_type,
  1342. 'bundle' => $bundle->name,
  1343. 'label' => 'Organism',
  1344. 'description' => 'The full scientific name for a species..',
  1345. 'required' => $is_required,
  1346. 'settings' => [
  1347. 'auto_attach' => TRUE,
  1348. 'chado_table' => $table_name,
  1349. 'chado_column' => $table_column,
  1350. 'base_table' => $table_name,
  1351. 'term_accession' => '0100026',
  1352. 'term_vocabulary' => 'OBI',
  1353. 'term_name' => 'organism',
  1354. ],
  1355. 'widget' => [
  1356. 'type' => 'obi__organism_widget',
  1357. 'settings' => [
  1358. 'display_label' => 1,
  1359. ],
  1360. ],
  1361. 'display' => [
  1362. 'default' => [
  1363. 'label' => 'inline',
  1364. 'type' => 'obi__organism_formatter',
  1365. 'settings' => [],
  1366. ],
  1367. ],
  1368. ];
  1369. }
  1370. if ($table_name == 'biomaterial') {
  1371. $field_name = 'biomaterial__provider_id';
  1372. $field_type = 'local__contact';
  1373. $info[$field_name] = [
  1374. 'field_name' => $field_name,
  1375. 'entity_type' => $entity_type,
  1376. 'bundle' => $bundle->name,
  1377. 'label' => 'Contact',
  1378. 'description' => 'An indvidual or organization that serves as a contact for this record.',
  1379. 'required' => FALSE,
  1380. 'settings' => [
  1381. 'auto_attach' => FALSE,
  1382. 'chado_table' => 'biomaterial',
  1383. 'chado_column' => 'biosourceprovider_id',
  1384. 'base_table' => 'biomaterial',
  1385. 'term_accession' => 'contact',
  1386. 'term_vocabulary' => 'local',
  1387. 'term_name' => 'contact',
  1388. ],
  1389. 'widget' => [
  1390. 'type' => 'local__contact_widget',
  1391. 'settings' => [
  1392. 'display_label' => 1,
  1393. ],
  1394. ],
  1395. 'display' => [
  1396. 'default' => [
  1397. 'label' => 'inline',
  1398. 'type' => 'local__contact_formatter',
  1399. 'settings' => [],
  1400. ],
  1401. ],
  1402. ];
  1403. }
  1404. if ($table_name == 'arraydesign') {
  1405. $field_name = 'efo__array_manufacturer';
  1406. $field_type = 'local__contact';
  1407. $info[$field_name] = [
  1408. 'field_name' => $field_name,
  1409. 'entity_type' => $entity_type,
  1410. 'bundle' => $bundle->name,
  1411. 'label' => 'Manufacturer',
  1412. 'description' => 'A manufacturer\'s contact details',
  1413. 'required' => TRUE,
  1414. 'settings' => [
  1415. 'auto_attach' => FALSE,
  1416. 'chado_table' => 'arraydesign',
  1417. 'chado_column' => 'manufacturer_id',
  1418. 'base_table' => 'arraydesign',
  1419. 'term_vocabulary' => 'EFO',
  1420. 'term_name' => 'aarray manufacturer',
  1421. 'term_accession' => '0001728',
  1422. ],
  1423. 'widget' => [
  1424. 'type' => 'local__contact_widget',
  1425. 'settings' => [
  1426. 'display_label' => 1,
  1427. ],
  1428. ],
  1429. 'display' => [
  1430. 'default' => [
  1431. 'label' => 'inline',
  1432. 'type' => 'local__contact_formatter',
  1433. 'settings' => [],
  1434. ],
  1435. ],
  1436. ];
  1437. }
  1438. // BASE CVTERM
  1439. if ($table_name == 'cvterm') {
  1440. $field_name = 'sio__vocabulary';
  1441. $is_required = TRUE;
  1442. $info[$field_name] = [
  1443. 'field_name' => $field_name,
  1444. 'entity_type' => $entity_type,
  1445. 'bundle' => $bundle->name,
  1446. 'label' => 'Vocabulary',
  1447. 'description' => 'A controlled vocabulary.',
  1448. 'required' => $is_required,
  1449. 'settings' => [
  1450. 'auto_attach' => TRUE,
  1451. 'chado_table' => $table_name,
  1452. 'chado_column' => 'cv_id',
  1453. 'base_table' => $table_name,
  1454. 'term_accession' => '001080',
  1455. 'term_vocabulary' => 'SIO',
  1456. 'term_name' => 'vocabulary',
  1457. ],
  1458. 'widget' => [
  1459. 'type' => 'sio__vocabulary_widget',
  1460. 'settings' => [
  1461. 'display_label' => 1,
  1462. ],
  1463. ],
  1464. 'display' => [
  1465. 'default' => [
  1466. 'label' => 'inline',
  1467. 'type' => 'sio__vocabulary_formatter',
  1468. 'settings' => [],
  1469. ],
  1470. ],
  1471. ];
  1472. }
  1473. // BASE DBXREF
  1474. if (array_key_exists('dbxref_id', $schema['fields'])) {
  1475. $field_name = 'data__accession';
  1476. $required = FALSE;
  1477. if (array_key_exists('not null', $schema['fields']['dbxref_id']) and
  1478. $schema['fields']['dbxref_id']['not null']) {
  1479. $required = TRUE;
  1480. }
  1481. $info[$field_name] = [
  1482. 'field_name' => $field_name,
  1483. 'entity_type' => $entity_type,
  1484. 'bundle' => $bundle->name,
  1485. 'label' => 'Accession',
  1486. 'description' => 'This field specifies the unique stable accession (ID) for
  1487. this record. It requires that this site have a database entry.',
  1488. 'required' => $required,
  1489. 'settings' => [
  1490. 'auto_attach' => TRUE,
  1491. 'chado_table' => $table_name,
  1492. 'chado_column' => 'dbxref_id',
  1493. 'base_table' => $table_name,
  1494. 'term_accession' => '2091',
  1495. 'term_vocabulary' => 'data',
  1496. 'term_name' => 'Accession',
  1497. ],
  1498. 'widget' => [
  1499. 'type' => 'data__accession_widget',
  1500. 'settings' => [
  1501. 'display_label' => 1,
  1502. ],
  1503. ],
  1504. 'display' => [
  1505. 'default' => [
  1506. 'label' => 'inline',
  1507. 'type' => 'data__accession_formatter',
  1508. 'settings' => [],
  1509. ],
  1510. ],
  1511. ];
  1512. }
  1513. // FEATURE MD5CHECKSUM
  1514. if ($table_name == 'feature') {
  1515. $field_name = 'data__sequence_checksum';
  1516. $info[$field_name] = [
  1517. 'field_name' => $field_name,
  1518. 'entity_type' => $entity_type,
  1519. 'bundle' => $bundle->name,
  1520. 'label' => 'Sequence Checksum',
  1521. 'description' => 'The MD5 checksum for the sequence. The checksum here
  1522. will always be unique for the raw unformatted sequence. To verify that the
  1523. sequence has not been corrupted, download the raw sequence and use an MD5 tool
  1524. to calculate the value. If the value calculated is identical the one shown
  1525. here, then the downloaded sequence is uncorrupted.',
  1526. 'required' => FALSE,
  1527. 'settings' => [
  1528. 'auto_attach' => TRUE,
  1529. 'chado_table' => $table_name,
  1530. 'chado_column' => 'md5checksum',
  1531. 'base_table' => $table_name,
  1532. 'term_accession' => '2190',
  1533. 'term_vocabulary' => 'data',
  1534. 'term_name' => 'Sequence checksum',
  1535. ],
  1536. 'widget' => [
  1537. 'type' => 'data__sequence_checksum_widget',
  1538. 'settings' => [
  1539. 'display_label' => 1,
  1540. 'md5_fieldname' => 'feature__md5checksum',
  1541. ],
  1542. ],
  1543. 'display' => [
  1544. 'default' => [
  1545. 'label' => 'inline',
  1546. 'type' => 'data__sequence_checksum_formatter',
  1547. 'settings' => [],
  1548. ],
  1549. ],
  1550. ];
  1551. }
  1552. // FEATURE RESIDUES
  1553. if ($table_name == 'feature') {
  1554. $field_name = 'data__sequence';
  1555. $info[$field_name] = [
  1556. 'field_name' => $field_name,
  1557. 'entity_type' => $entity_type,
  1558. 'bundle' => $bundle->name,
  1559. 'label' => 'Sequence',
  1560. 'description' => 'One or more molecular sequences, possibly with associated annotation.',
  1561. 'required' => FALSE,
  1562. 'settings' => [
  1563. 'auto_attach' => FALSE,
  1564. 'chado_table' => $table_name,
  1565. 'chado_column' => 'residues',
  1566. 'base_table' => $table_name,
  1567. 'term_accession' => '2044',
  1568. 'term_vocabulary' => 'data',
  1569. 'term_name' => 'Sequence',
  1570. ],
  1571. 'widget' => [
  1572. 'type' => 'data__sequence_widget',
  1573. 'settings' => [
  1574. 'display_label' => 1,
  1575. ],
  1576. ],
  1577. 'display' => [
  1578. 'default' => [
  1579. 'label' => 'above',
  1580. 'type' => 'data__sequence_formatter',
  1581. 'settings' => [],
  1582. ],
  1583. ],
  1584. ];
  1585. }
  1586. // FEATURE SEQLEN
  1587. if ($table_name == 'feature') {
  1588. $field_name = 'data__sequence_length';
  1589. $info[$field_name] = [
  1590. 'field_name' => $field_name,
  1591. 'entity_type' => $entity_type,
  1592. 'bundle' => $bundle->name,
  1593. 'label' => 'Sequence Length',
  1594. 'description' => 'The number of residues in the raw sequence. This length
  1595. is only for the assigned raw sequence and does not represent the length of any
  1596. sequences derived from alignments. If this value is zero but aligned sequences
  1597. are present then this record has no official assigned sequence.',
  1598. 'required' => FALSE,
  1599. 'settings' => [
  1600. 'auto_attach' => TRUE,
  1601. 'chado_table' => $table_name,
  1602. 'chado_column' => 'seqlen',
  1603. 'base_table' => $table_name,
  1604. 'term_accession' => '1249',
  1605. 'term_vocabulary' => 'data',
  1606. 'term_name' => 'delete Sequence length',
  1607. ],
  1608. 'widget' => [
  1609. 'type' => 'data__sequence_length_widget',
  1610. 'settings' => [
  1611. 'display_label' => 1,
  1612. ],
  1613. ],
  1614. 'display' => [
  1615. 'default' => [
  1616. 'label' => 'inline',
  1617. 'type' => 'data__sequence_length_formatter',
  1618. 'settings' => [],
  1619. ],
  1620. ],
  1621. ];
  1622. }
  1623. // PROTEIN & CDS SEQUENCES.
  1624. if ($table_name == 'feature' and
  1625. ($bundle->term->name == 'mRNA' or $bundle->term->name == 'transcript')) {
  1626. $field_name = 'data__protein_sequence';
  1627. $info[$field_name] = [
  1628. 'field_name' => $field_name,
  1629. 'entity_type' => $entity_type,
  1630. 'bundle' => $bundle->name,
  1631. 'label' => 'Protein Sequence',
  1632. 'description' => 'Protein sequences.',
  1633. 'required' => FALSE,
  1634. 'settings' => [
  1635. 'auto_attach' => FALSE,
  1636. 'chado_table' => 'feature',
  1637. 'chado_column' => 'residues',
  1638. 'base_table' => 'feature',
  1639. 'term_accession' => '2976',
  1640. 'term_vocabulary' => 'data',
  1641. 'term_name' => 'Protein sequence',
  1642. ],
  1643. 'widget' => [
  1644. 'type' => 'data__protein_sequence_widget',
  1645. 'settings' => [
  1646. 'display_label' => 1,
  1647. ],
  1648. ],
  1649. 'display' => [
  1650. 'default' => [
  1651. 'label' => 'above',
  1652. 'type' => 'data__protein_sequence_formatter',
  1653. 'settings' => [],
  1654. ],
  1655. ],
  1656. ];
  1657. $field_name = 'so__cds';
  1658. $info[$field_name] = [
  1659. 'field_name' => $field_name,
  1660. 'entity_type' => $entity_type,
  1661. 'bundle' => $bundle->name,
  1662. 'label' => 'Coding Sequence (CDS)',
  1663. 'description' => 'Coding sequences.',
  1664. 'required' => FALSE,
  1665. 'settings' => [
  1666. 'auto_attach' => FALSE,
  1667. 'chado_table' => 'featureprop',
  1668. 'chado_column' => 'value',
  1669. 'base_table' => 'feature',
  1670. 'term_vocabulary' => 'SO',
  1671. 'term_name' => 'CDS',
  1672. 'term_accession' => '0000316',
  1673. ],
  1674. 'widget' => [
  1675. 'type' => 'so__cds_widget',
  1676. 'settings' => [
  1677. 'display_label' => 1,
  1678. ],
  1679. ],
  1680. 'display' => [
  1681. 'default' => [
  1682. 'label' => 'above',
  1683. 'type' => 'so__cds_formatter',
  1684. 'settings' => [],
  1685. ],
  1686. ],
  1687. ];
  1688. }
  1689. // GENE TRANSCRIPTS
  1690. $rel_table = $table_name . '_relationship';
  1691. if (chado_table_exists($rel_table) and ($bundle->term->name == 'gene')) {
  1692. $field_name = 'so__transcript';
  1693. $info[$field_name] = [
  1694. 'field_name' => $field_name,
  1695. 'entity_type' => $entity_type,
  1696. 'bundle' => $bundle->name,
  1697. 'label' => 'Transcripts',
  1698. 'description' => 'Transcripts that are part of this gene.',
  1699. 'required' => FALSE,
  1700. 'settings' => [
  1701. 'auto_attach' => FALSE,
  1702. 'chado_table' => $rel_table,
  1703. 'chado_column' => '',
  1704. 'base_table' => $table_name,
  1705. 'term_vocabulary' => 'SO',
  1706. 'term_name' => 'transcript',
  1707. 'term_accession' => '0000673',
  1708. ],
  1709. 'widget' => [
  1710. 'type' => 'so__transcript_widget',
  1711. 'settings' => [
  1712. 'display_label' => 1,
  1713. ],
  1714. ],
  1715. 'display' => [
  1716. 'default' => [
  1717. 'label' => 'above',
  1718. 'type' => 'so__transcript_formatter',
  1719. 'settings' => [],
  1720. ],
  1721. ],
  1722. ];
  1723. }
  1724. // ORGANISM TYPE_ID
  1725. if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
  1726. $field_name = 'taxrank__infraspecific_taxon';
  1727. $info[$field_name] = [
  1728. 'field_name' => $field_name,
  1729. 'entity_type' => $entity_type,
  1730. 'bundle' => $bundle->name,
  1731. 'label' => 'Infraspecific Taxon',
  1732. 'description' => 'The Infraspecific Taxon.',
  1733. 'required' => FALSE,
  1734. 'settings' => [
  1735. 'auto_attach' => TRUE,
  1736. 'chado_table' => 'organism',
  1737. 'chado_column' => 'type_id',
  1738. 'base_table' => 'organism',
  1739. 'term_vocabulary' => 'TAXRANK',
  1740. 'term_name' => 'infraspecific_taxon',
  1741. 'term_accession' => '0000046',
  1742. ],
  1743. 'widget' => [
  1744. 'type' => 'taxrank__infraspecific_taxon_widget',
  1745. 'settings' => [
  1746. 'display_label' => 1,
  1747. ],
  1748. ],
  1749. 'display' => [
  1750. 'default' => [
  1751. 'label' => 'inline',
  1752. 'type' => 'taxrank__infraspecific_taxon_formatter',
  1753. 'settings' => [],
  1754. ],
  1755. ],
  1756. ];
  1757. }
  1758. // FEATURE MAP UNITS
  1759. if ($table_name == 'featuremap') {
  1760. $field_name = 'uo__unit';
  1761. $info[$field_name] = [
  1762. 'field_name' => $field_name,
  1763. 'entity_type' => $entity_type,
  1764. 'bundle' => $bundle->name,
  1765. 'label' => 'Units',
  1766. 'description' => 'The map\'s unit type.',
  1767. 'required' => TRUE,
  1768. 'settings' => [
  1769. 'auto_attach' => TRUE,
  1770. 'chado_table' => $table_name,
  1771. 'chado_column' => 'unittype_id',
  1772. 'base_table' => $table_name,
  1773. 'term_accession' => '0000000',
  1774. 'term_vocabulary' => 'UO',
  1775. 'term_name' => 'unit',
  1776. ],
  1777. 'widget' => [
  1778. 'type' => 'uo__unit_widget',
  1779. 'settings' => [
  1780. 'display_label' => 1,
  1781. ],
  1782. ],
  1783. 'display' => [
  1784. 'default' => [
  1785. 'label' => 'inline',
  1786. 'type' => 'uo__unit_formatter',
  1787. 'settings' => [],
  1788. ],
  1789. ],
  1790. ];
  1791. }
  1792. // the analysis source.
  1793. if ($table_name == 'analysis') {
  1794. $field_name = 'local__source_data';
  1795. $info[$field_name] = [
  1796. 'field_name' => $field_name,
  1797. 'entity_type' => $entity_type,
  1798. 'bundle' => $bundle->name,
  1799. 'label' => 'Data Source',
  1800. 'description' => 'The source where data was obtained for this analysis.',
  1801. 'required' => FALSE,
  1802. 'settings' => [
  1803. 'auto_attach' => TRUE,
  1804. 'chado_table' => $table_name,
  1805. 'chado_column' => 'analysis_id',
  1806. 'base_table' => $table_name,
  1807. 'term_accession' => 'source_data',
  1808. 'term_vocabulary' => 'local',
  1809. 'term_name' => 'source_data',
  1810. ],
  1811. 'widget' => [
  1812. 'type' => 'local__source_data_widget',
  1813. 'settings' => [
  1814. 'display_label' => 1,
  1815. ],
  1816. ],
  1817. 'display' => [
  1818. 'default' => [
  1819. 'label' => 'inline',
  1820. 'type' => 'local__source_data_formatter',
  1821. 'settings' => [],
  1822. ],
  1823. ],
  1824. ];
  1825. }
  1826. // Add an image field to the Organism type. This is a Drupal field and
  1827. // not stored in Chado, but is used for backwards compatibility.
  1828. if ($table_name == 'organism') {
  1829. $field_name = 'data__image';
  1830. $info[$field_name] = [
  1831. 'field_name' => $field_name,
  1832. 'entity_type' => $entity_type,
  1833. 'bundle' => $bundle->name,
  1834. 'label' => 'Organism Image',
  1835. 'description' => 'An image for the organism',
  1836. 'required' => FALSE,
  1837. 'settings' => [
  1838. 'term_vocabulary' => 'data',
  1839. 'term_name' => 'Image',
  1840. 'term_accession' => '2968',
  1841. ],
  1842. 'display' => [
  1843. 'default' => [
  1844. 'label' => 'hidden',
  1845. ],
  1846. ],
  1847. ];
  1848. }
  1849. // Phylotree Viewer
  1850. if ($table_name == 'phylotree') {
  1851. $field_name = 'operation__phylotree_vis';
  1852. $schema = chado_get_schema('phylotree');
  1853. $pkey = $schema['primary key'][0];
  1854. $info[$field_name] = [
  1855. 'field_name' => $field_name,
  1856. 'entity_type' => $entity_type,
  1857. 'bundle' => $bundle->name,
  1858. 'label' => 'Tree View',
  1859. 'description' => 'Rendering of a phylogenetic tree.',
  1860. 'required' => FALSE,
  1861. 'settings' => [
  1862. 'auto_attach' => FALSE,
  1863. 'chado_table' => 'phylotree',
  1864. 'chado_column' => 'type_id',
  1865. 'base_table' => 'phylotree',
  1866. 'term_accession' => '0567',
  1867. 'term_vocabulary' => 'operation',
  1868. 'term_name' => 'Phylogenetic tree visualisation',
  1869. ],
  1870. 'widget' => [
  1871. 'type' => 'operation__phylotree_vis_widget',
  1872. 'settings' => [
  1873. 'display_label' => 0,
  1874. ],
  1875. ],
  1876. 'display' => [
  1877. 'default' => [
  1878. 'label' => 'hidden',
  1879. 'type' => 'operation__phylotree_vis_formatter',
  1880. 'settings' => [],
  1881. ],
  1882. ],
  1883. ];
  1884. }
  1885. // PROTOCOL FIELD
  1886. if ($table_name != 'protocol' and
  1887. (array_key_exists('protocol_id', $schema['fields']))) {
  1888. $field_name = 'sep__protocol';
  1889. $is_required = FALSE;
  1890. $table_column = 'protocol_id';
  1891. if (array_key_exists('not null', $schema['fields']['protocol_id']) and
  1892. $schema['fields']['protocol_id']['not null']) {
  1893. $is_required = TRUE;
  1894. }
  1895. $info[$field_name] = [
  1896. 'field_name' => $field_name,
  1897. 'entity_type' => $entity_type,
  1898. 'bundle' => $bundle->name,
  1899. 'label' => 'Protocol',
  1900. 'description' => 'The parameterizable description of a process',
  1901. 'required' => $is_required,
  1902. 'settings' => [
  1903. 'auto_attach' => TRUE,
  1904. 'chado_table' => $table_name,
  1905. 'chado_column' => $table_column,
  1906. 'base_table' => $table_name,
  1907. 'term_accession' => '00101',
  1908. 'term_vocabulary' => 'sep',
  1909. 'term_name' => 'Protocol',
  1910. ],
  1911. 'widget' => [
  1912. 'type' => 'sep__protocol_widget',
  1913. 'settings' => [
  1914. 'display_label' => 1,
  1915. ],
  1916. ],
  1917. 'display' => [
  1918. 'default' => [
  1919. 'label' => 'inline',
  1920. 'type' => 'sep__protocol_formatter',
  1921. 'settings' => [],
  1922. ],
  1923. ],
  1924. ];
  1925. }
  1926. // pub_id field in table.
  1927. $schema = chado_get_schema($table_name);
  1928. if (array_key_exists('pub_id', $schema['fields']) and $table_name != 'pub') {
  1929. // Remove the schema__publication added by the
  1930. // tripal_chado_bunde_instnaces_info_base function.
  1931. unset($info['schema__publication']);
  1932. $field_name = 'schema__publication_single';
  1933. $info[$field_name] = [
  1934. 'field_name' => $field_name,
  1935. 'entity_type' => $entity_type,
  1936. 'bundle' => $bundle->name,
  1937. 'label' => 'Publication',
  1938. 'description' => 'This record has been referenced or is sourced from these publications.',
  1939. 'required' => FALSE,
  1940. 'settings' => [
  1941. 'auto_attach' => TRUE,
  1942. 'chado_table' => $table_name,
  1943. 'chado_column' => 'pub_id',
  1944. 'base_table' => $table_name,
  1945. 'term_accession' => 'publication',
  1946. 'term_vocabulary' => 'schema',
  1947. 'term_name' => 'publication',
  1948. ],
  1949. 'widget' => [
  1950. 'type' => 'schema__publication_widget',
  1951. 'settings' => [
  1952. 'display_label' => 1,
  1953. ],
  1954. ],
  1955. 'display' => [
  1956. 'default' => [
  1957. 'label' => 'hidden',
  1958. 'type' => 'schema__publication_formatter',
  1959. 'settings' => [],
  1960. ],
  1961. ],
  1962. ];
  1963. }
  1964. if ($table_name == 'assay') {
  1965. // Remove the ncit__operator added by the
  1966. // tripal_chado_bunde_instnaces_info_base function.
  1967. unset($info['ncit__operator']);
  1968. $field_name = 'assay__operator_id';
  1969. $info[$field_name] = [
  1970. 'field_name' => $field_name,
  1971. 'entity_type' => $entity_type,
  1972. 'bundle' => $bundle->name,
  1973. 'label' => 'Operator',
  1974. 'description' => 'The individual responsible for performing the assay.',
  1975. 'required' => TRUE,
  1976. 'settings' => [
  1977. 'auto_attach' => TRUE,
  1978. 'chado_table' => 'assay',
  1979. 'chado_column' => 'operator_id',
  1980. 'base_table' => 'assay',
  1981. 'term_vocabulary' => 'NCIT',
  1982. 'term_name' => 'Operator',
  1983. 'term_accession' => 'C48036',
  1984. ],
  1985. 'widget' => [
  1986. 'type' => 'local__contact_widget',
  1987. 'settings' => [
  1988. 'display_label' => 1,
  1989. ],
  1990. ],
  1991. 'display' => [
  1992. 'default' => [
  1993. 'label' => 'inline',
  1994. 'type' => 'local__contact_formatter',
  1995. 'settings' => [],
  1996. ],
  1997. ],
  1998. ];
  1999. $field_name = 'efo__array_design';
  2000. $info[$field_name] = [
  2001. 'field_name' => $field_name,
  2002. 'entity_type' => $entity_type,
  2003. 'bundle' => $bundle->name,
  2004. 'label' => 'Array design',
  2005. 'description' => 'An instrument design which describes the design of the array.',
  2006. 'required' => TRUE,
  2007. 'settings' => [
  2008. 'auto_attach' => TRUE,
  2009. 'chado_table' => 'assay',
  2010. 'chado_column' => 'arraydesign_id',
  2011. 'base_table' => 'assay',
  2012. 'term_vocabulary' => 'EFO',
  2013. 'term_name' => 'array design',
  2014. 'term_accession' => '0000269',
  2015. ],
  2016. 'widget' => [
  2017. 'type' => 'efo__array_design_widget',
  2018. 'settings' => [
  2019. 'display_label' => 1,
  2020. ],
  2021. ],
  2022. 'display' => [
  2023. 'default' => [
  2024. 'label' => 'inline',
  2025. 'type' => 'efo__array_design_formatter',
  2026. 'settings' => [],
  2027. ],
  2028. ],
  2029. ];
  2030. }
  2031. // Analysis Id
  2032. if (array_key_exists('analysis_id', $schema['fields']) and $table_name != 'analysis') {
  2033. $field_name = 'operation__analysis';
  2034. $is_required = FALSE;
  2035. if (array_key_exists('not null', $schema['fields']['analysis_id']) and
  2036. $schema['fields']['analysis_id']['not null']) {
  2037. $is_required = TRUE;
  2038. }
  2039. $info[$field_name] = [
  2040. 'field_name' => $field_name,
  2041. 'entity_type' => $entity_type,
  2042. 'bundle' => $bundle->name,
  2043. 'label' => 'Analysis',
  2044. 'description' => 'Application of analytical methods to existing data of a specific type.',
  2045. 'required' => $is_required,
  2046. 'settings' => [
  2047. 'auto_attach' => TRUE,
  2048. 'chado_table' => $table_name,
  2049. 'chado_column' => 'analysis_id',
  2050. 'base_table' => $table_name,
  2051. 'term_vocabulary' => 'operation',
  2052. 'term_name' => 'Analysis',
  2053. 'term_accession' => '2945',
  2054. ],
  2055. 'widget' => [
  2056. 'type' => 'operation__analysis_widget',
  2057. 'settings' => [
  2058. 'display_label' => 0,
  2059. ],
  2060. ],
  2061. 'display' => [
  2062. 'default' => [
  2063. 'label' => 'inline',
  2064. 'type' => 'operation__analysis_formatter',
  2065. 'settings' => [],
  2066. ],
  2067. ],
  2068. ];
  2069. }
  2070. }
  2071. /**
  2072. *
  2073. * @param unknown $entity_type
  2074. * @param unknown $bundle
  2075. * @param unknown $details
  2076. */
  2077. function tripal_chado_bundle_instances_info_linker(&$info, $entity_type, $bundle, $details) {
  2078. $table_name = $details['chado_table'];
  2079. $type_table = $details['chado_type_table'];
  2080. $type_column = $details['chado_type_column'];
  2081. $cvterm_id = $details['chado_cvterm_id'];
  2082. $type_value = $details['chado_type_value'];
  2083. // CONTACTS
  2084. $contact_table = $table_name . '_contact';
  2085. if (chado_table_exists($contact_table)) {
  2086. $field_name = $table_name . '_contact';
  2087. $info[$field_name] = $info[$field_name] = [
  2088. 'field_name' => $field_name,
  2089. 'entity_type' => $entity_type,
  2090. 'bundle' => $bundle->name,
  2091. 'label' => 'Contact',
  2092. 'description' => 'Associates an indviddual or organization with this record',
  2093. 'required' => FALSE,
  2094. 'settings' => [
  2095. 'auto_attach' => FALSE,
  2096. 'chado_table' => $contact_table,
  2097. 'base_table' => $table_name,
  2098. 'chado_column' => 'contact_id',
  2099. 'term_accession' => 'contact',
  2100. 'term_vocabulary' => 'local',
  2101. 'term_name' => 'contact',
  2102. ],
  2103. 'widget' => [
  2104. 'type' => 'chado_linker__contact_widget',
  2105. 'settings' => [
  2106. 'display_label' => 1,
  2107. ],
  2108. ],
  2109. 'display' => [
  2110. 'default' => [
  2111. 'label' => 'hidden',
  2112. 'type' => 'chado_linker__contact_formatter',
  2113. 'settings' => [],
  2114. ],
  2115. ],
  2116. ];
  2117. }
  2118. // DBXREF
  2119. $dbxref_table = $table_name . '_dbxref';
  2120. if (chado_table_exists($dbxref_table)) {
  2121. $field_name = 'sbo__database_cross_reference';
  2122. $schema = chado_get_schema($dbxref_table);
  2123. $pkey = $schema['primary key'][0];
  2124. $info[$field_name] = [
  2125. 'field_name' => $field_name,
  2126. 'entity_type' => $entity_type,
  2127. 'bundle' => $bundle->name,
  2128. 'label' => 'Cross Reference',
  2129. 'description' => 'The IDs where this record may be available in other external online databases.',
  2130. 'required' => FALSE,
  2131. 'settings' => [
  2132. 'auto_attach' => FALSE,
  2133. 'chado_table' => $dbxref_table,
  2134. 'chado_column' => $pkey,
  2135. 'base_table' => $table_name,
  2136. 'term_vocabulary' => 'SBO',
  2137. 'term_name' => 'Database Cross Reference',
  2138. 'term_accession' => '0000554',
  2139. ],
  2140. 'widget' => [
  2141. 'type' => 'sbo__database_cross_reference_widget',
  2142. 'settings' => [
  2143. 'display_label' => 1,
  2144. ],
  2145. ],
  2146. 'display' => [
  2147. 'default' => [
  2148. 'label' => 'hidden',
  2149. 'type' => 'sbo__database_cross_reference_formatter',
  2150. 'settings' => [],
  2151. ],
  2152. ],
  2153. ];
  2154. }
  2155. // EXPRESSION
  2156. // TODO: this should only show up on gene or mRNA and the GO must be
  2157. // laoded or this field will crash things.
  2158. // $expression_table = $table_name . '_expression';
  2159. // if (chado_table_exists($expression_table)) {
  2160. // $field_name = 'go__gene_expression';
  2161. // $schema = chado_get_schema($expression_table);
  2162. // $pkey = $schema['primary key'][0];
  2163. // $info[$field_name] = array(
  2164. // 'field_name' => $field_name,
  2165. // 'entity_type' => $entity_type,
  2166. // 'bundle' => $bundle->name,
  2167. // 'label' => 'Gene expression',
  2168. // 'description' => 'Information about the expression of this record.',
  2169. // 'required' => FALSE,
  2170. // 'settings' => array(
  2171. // 'auto_attach' => FALSE,
  2172. // 'chado_table' => $expression_table,
  2173. // 'chado_column' => $pkey,
  2174. // 'base_table' => $table_name,
  2175. // 'term_accession' => '',
  2176. // 'term_vocabulary' => '',
  2177. // 'term_name' => '',
  2178. // ),
  2179. // 'widget' => array(
  2180. // 'type' => 'go__gene_expression_widget',
  2181. // 'settings' => array(
  2182. // 'display_label' => 1,
  2183. // ),
  2184. // ),
  2185. // 'display' => array(
  2186. // 'default' => array(
  2187. // 'label' => 'above',
  2188. // 'type' => 'go__gene_expression_formatter',
  2189. // 'settings' => array(),
  2190. // ),
  2191. // ),
  2192. // );
  2193. // }
  2194. // FEATURELOC
  2195. if ($table_name == 'feature') {
  2196. $field_name = 'data__sequence_coordinates';
  2197. $schema = chado_get_schema('featureloc');
  2198. $pkey = $schema['primary key'][0];
  2199. $info[$field_name] = [
  2200. 'field_name' => $field_name,
  2201. 'entity_type' => $entity_type,
  2202. 'bundle' => $bundle->name,
  2203. 'label' => 'Sequence Coordinates',
  2204. 'description' => 'The locations on other genomic sequences where this
  2205. record has been aligned.',
  2206. 'required' => FALSE,
  2207. 'settings' => [
  2208. 'auto_attach' => FALSE,
  2209. 'chado_table' => 'featureloc',
  2210. 'chado_column' => $pkey,
  2211. 'base_table' => 'feature',
  2212. 'term_accession' => '2012',
  2213. 'term_vocabulary' => 'data',
  2214. 'term_name' => 'Sequence coordinates',
  2215. ],
  2216. 'widget' => [
  2217. 'type' => 'data__sequence_coordinates_widget',
  2218. 'settings' => [
  2219. 'display_label' => 1,
  2220. ],
  2221. ],
  2222. 'display' => [
  2223. 'default' => [
  2224. 'label' => 'hidden',
  2225. 'type' => 'data__sequence_coordinates_formatter',
  2226. 'settings' => [],
  2227. ],
  2228. ],
  2229. ];
  2230. }
  2231. // FEATUREPOS
  2232. if ($table_name == 'feature') {
  2233. $field_name = 'ogi__location_on_map';
  2234. $schema = chado_get_schema('featurepos');
  2235. $pkey = $schema['primary key'][0];
  2236. $info[$field_name] = [
  2237. 'field_name' => $field_name,
  2238. 'entity_type' => $entity_type,
  2239. 'bundle' => $bundle->name,
  2240. 'label' => 'Location on Map',
  2241. 'description' => 'The positions on a genetic map.',
  2242. 'required' => FALSE,
  2243. 'settings' => [
  2244. 'auto_attach' => FALSE,
  2245. 'chado_table' => 'featurepos',
  2246. 'chado_column' => $pkey,
  2247. 'base_table' => 'feature',
  2248. 'term_accession' => '0000021',
  2249. 'term_vocabulary' => 'OGI',
  2250. 'term_name' => 'location on map',
  2251. ],
  2252. 'widget' => [
  2253. 'type' => 'ogi__location_on_map_widget',
  2254. 'settings' => [
  2255. 'display_label' => 1,
  2256. ],
  2257. ],
  2258. 'display' => [
  2259. 'default' => [
  2260. 'label' => 'hidden',
  2261. 'type' => 'ogi__location_on_map_formatter',
  2262. 'settings' => [],
  2263. ],
  2264. ],
  2265. ];
  2266. }
  2267. // // GENOTYPE
  2268. // $genotype_table = $table_name . '_genotype';
  2269. // if (chado_table_exists($genotype_table)) {
  2270. // $field_name = 'so__genotype';
  2271. // $schema = chado_get_schema($genotype_table);
  2272. // $pkey = $schema['primary key'][0];
  2273. // $info[$field_name] = array(
  2274. // 'field_name' => $field_name,
  2275. // 'entity_type' => $entity_type,
  2276. // 'bundle' => $bundle->name,
  2277. // 'label' => 'Genotype',
  2278. // 'description' => 'The genotypes associated with this record.',
  2279. // 'required' => FALSE,
  2280. // 'settings' => array(
  2281. // 'auto_attach' => FALSE,
  2282. // 'chado_table' => $genotype_table,
  2283. // 'chado_column' => $pkey,
  2284. // 'base_table' => $table_name,
  2285. // 'term_accession' => '',
  2286. // 'term_vocabulary' => '',
  2287. // 'term_name' => '',
  2288. // ),
  2289. // 'widget' => array(
  2290. // 'type' => 'so__genotype_widget',
  2291. // 'settings' => array(
  2292. // 'display_label' => 1,
  2293. // ),
  2294. // ),
  2295. // 'display' => array(
  2296. // 'default' => array(
  2297. // 'label' => 'hidden',
  2298. // 'type' => 'so__genotype_formatter',
  2299. // 'settings' => array(),
  2300. // ),
  2301. // ),
  2302. // );
  2303. // }
  2304. // // PHENOTYPE
  2305. // $phenotype_table = $table_name . '_phenotype';
  2306. // if (chado_table_exists($phenotype_table)) {
  2307. // $field_name = 'sbo__phenotype';
  2308. // $schema = chado_get_schema($phenotype_table);
  2309. // $pkey = $schema['primary key'][0];
  2310. // $info[$field_name] = array(
  2311. // 'field_name' => $field_name,
  2312. // 'entity_type' => $entity_type,
  2313. // 'bundle' => $bundle->name,
  2314. // 'label' => 'Phenotype',
  2315. // 'description' => 'The phenotypes associated with this record.',
  2316. // 'required' => FALSE,
  2317. // 'settings' => array(
  2318. // 'auto_attach' => FALSE,
  2319. // 'chado_table' => $phenotype_table,
  2320. // 'chado_column' => $pkey,
  2321. // 'base_table' => $table_name,
  2322. // 'term_accession' => '',
  2323. // 'term_vocabulary' => '',
  2324. // 'term_name' => '',
  2325. // ),
  2326. // 'widget' => array(
  2327. // 'type' => 'sbo__phenotype_widget',
  2328. // 'settings' => array(
  2329. // 'display_label' => 1,
  2330. // ),
  2331. // ),
  2332. // 'display' => array(
  2333. // 'default' => array(
  2334. // 'label' => 'hidden',
  2335. // 'type' => 'sbo__phenotype_formatter',
  2336. // 'settings' => array(),
  2337. // ),
  2338. // ),
  2339. // );
  2340. // }
  2341. // PROPERTIES
  2342. $prop_table = $table_name . 'prop';
  2343. if (chado_table_exists($prop_table)) {
  2344. $schema = chado_get_schema($prop_table);
  2345. $pkey = $schema['primary key'][0];
  2346. $props = tripal_chado_bundle_get_properties($table_name, $prop_table, $type_table, $type_column, $cvterm_id, $type_value);
  2347. foreach ($props as $term) {
  2348. $field_name = strtolower(preg_replace('/[^\w]/', '_', $term->dbxref_id->db_id->name . '__' . $term->name));
  2349. // The field name can only be 32 chars, but if our name is longer we need
  2350. // to add some random chars to ensure we don't have naming conflicts
  2351. // with other terms (e.g. mitochondrial_genetic_code and
  2352. // mitochondrial_genetic_code_name)
  2353. if (strlen($field_name) >= 32) {
  2354. $field_name = substr($field_name, 0, 20) . '_' . $term->cvterm_id;
  2355. }
  2356. $info[$field_name] = [
  2357. 'field_name' => $field_name,
  2358. 'entity_type' => $entity_type,
  2359. 'bundle' => $bundle->name,
  2360. 'label' => ucwords(preg_replace('/_/', ' ', $term->name)),
  2361. 'description' => $term->definition,
  2362. 'required' => FALSE,
  2363. 'settings' => [
  2364. 'auto_attach' => TRUE,
  2365. 'term_vocabulary' => $term->dbxref_id->db_id->name,
  2366. 'term_accession' => $term->dbxref_id->accession,
  2367. 'term_name' => $term->name,
  2368. 'base_table' => $table_name,
  2369. 'chado_table' => $prop_table,
  2370. 'chado_column' => $pkey,
  2371. ],
  2372. 'widget' => [
  2373. 'type' => 'chado_linker__prop_widget',
  2374. 'settings' => [
  2375. 'display_label' => 1,
  2376. ],
  2377. ],
  2378. 'display' => [
  2379. 'default' => [
  2380. 'label' => 'hidden',
  2381. 'type' => 'chado_linker__prop_formatter',
  2382. 'settings' => [],
  2383. ],
  2384. ],
  2385. ];
  2386. // Make some customizations to some fields
  2387. if ($term->name == 'Citation' and $term->cv_id->name == 'tripal_pub') {
  2388. $info[$field_name]['required'] = TRUE;
  2389. $info[$field_name]['description'] = t('All publications must have a unique citation.
  2390. Please enter the full citation for this publication. For PubMed style citations list
  2391. the last name of the author followed by initials. Each author should be separated by a comma. Next comes
  2392. 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.
  2393. 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
  2394. suffer taxonomic influence?</a> J Ethnopharmacol. 2013 Apr 19; 146(3):842-52.</pre>');
  2395. $info[$field_name]['settings']['rows'] = 3;
  2396. }
  2397. if ($term->name == 'Abstract' and $term->cv_id->name == 'tripal_pub') {
  2398. $info[$field_name]['settings']['rows'] = 5;
  2399. }
  2400. }
  2401. }
  2402. // CVTERMS
  2403. $term_table = $table_name . '_cvterm';
  2404. if (chado_table_exists($term_table)) {
  2405. $schema = chado_get_schema($term_table);
  2406. $pkey = $schema['primary key'][0];
  2407. $lkey = key($schema['foreign keys'][$table_name]['columns']);
  2408. $rkey = $schema['foreign keys'][$table_name]['columns'][$lkey];
  2409. $field_name = 'sio__annotation';
  2410. $info[$field_name] = [
  2411. 'field_name' => $field_name,
  2412. 'entity_type' => $entity_type,
  2413. 'bundle' => $bundle->name,
  2414. 'label' => 'Annotations',
  2415. 'description' => 'Annotations that are associated with this record.',
  2416. 'required' => FALSE,
  2417. 'settings' => [
  2418. 'auto_attach' => FALSE,
  2419. 'chado_table' => $term_table,
  2420. 'chado_column' => $pkey,
  2421. 'base_table' => $table_name,
  2422. 'term_vocabulary' => 'SIO',
  2423. 'term_name' => 'annotation',
  2424. 'term_accession' => '001166',
  2425. ],
  2426. 'widget' => [
  2427. 'type' => 'sio__annotation_widget',
  2428. 'settings' => [
  2429. 'display_label' => 1,
  2430. ],
  2431. ],
  2432. 'display' => [
  2433. 'default' => [
  2434. 'label' => 'hidden',
  2435. 'type' => 'sio__annotation_formatter',
  2436. 'settings' => [],
  2437. ],
  2438. ],
  2439. ];
  2440. }
  2441. // PUBLICATIONS
  2442. $pub_table = $table_name . '_pub';
  2443. if (chado_table_exists($pub_table)) {
  2444. $field_name = 'schema__publication';
  2445. $schema = chado_get_schema($pub_table);
  2446. $pkey = $schema['primary key'][0];
  2447. $info[$field_name] = [
  2448. 'field_name' => $field_name,
  2449. 'entity_type' => $entity_type,
  2450. 'bundle' => $bundle->name,
  2451. 'label' => 'Publication',
  2452. 'description' => 'This record has been referenced or is sourced from these publications.',
  2453. 'required' => FALSE,
  2454. 'settings' => [
  2455. 'auto_attach' => FALSE,
  2456. 'chado_table' => $pub_table,
  2457. 'chado_column' => $pkey,
  2458. 'base_table' => $table_name,
  2459. 'term_accession' => 'publication',
  2460. 'term_vocabulary' => 'schema',
  2461. 'term_name' => 'publication',
  2462. ],
  2463. 'widget' => [
  2464. 'type' => 'schema__publication_widget',
  2465. 'settings' => [
  2466. 'display_label' => 1,
  2467. ],
  2468. ],
  2469. 'display' => [
  2470. 'default' => [
  2471. 'label' => 'hidden',
  2472. 'type' => 'schema__publication_formatter',
  2473. 'settings' => [],
  2474. ],
  2475. ],
  2476. ];
  2477. }
  2478. // PUBLICATIONS (in reverse)
  2479. // We want to be able to show all of the content that a publication links
  2480. // to. The sio__references field does that.
  2481. if ($table_name == 'pub') {
  2482. $field_name = 'sio__references';
  2483. $schema = chado_get_schema($table_name);
  2484. $pkey = $schema['primary key'][0];
  2485. $info[$field_name] = [
  2486. 'field_name' => $field_name,
  2487. 'entity_type' => $entity_type,
  2488. 'bundle' => $bundle->name,
  2489. 'label' => 'References',
  2490. 'description' => 'Records that are referred to by the publication.',
  2491. 'required' => FALSE,
  2492. 'settings' => [
  2493. 'auto_attach' => FALSE,
  2494. 'chado_table' => $table_name,
  2495. 'chado_column' => $pkey,
  2496. 'base_table' => $table_name,
  2497. 'term_accession' => '000631',
  2498. 'term_vocabulary' => 'SIO',
  2499. 'term_name' => 'references',
  2500. ],
  2501. 'widget' => [
  2502. 'type' => 'sio__references_widget',
  2503. 'settings' => [
  2504. 'display_label' => 1,
  2505. ],
  2506. ],
  2507. 'display' => [
  2508. 'default' => [
  2509. 'label' => 'hidden',
  2510. 'type' => 'sio__references_formatter',
  2511. 'settings' => [],
  2512. ],
  2513. ],
  2514. ];
  2515. }
  2516. // RELATIONSHIPS
  2517. // If the linker table does not exists then we don't want to add attach.
  2518. $rel_table = $table_name . '_relationship';
  2519. if (chado_table_exists($rel_table)) {
  2520. $field_name = 'sbo__relationship';
  2521. $schema = chado_get_schema($rel_table);
  2522. $pkey = $schema['primary key'][0];
  2523. $info[$field_name] = [
  2524. 'field_name' => $field_name,
  2525. 'entity_type' => $entity_type,
  2526. 'bundle' => $bundle->name,
  2527. 'label' => 'Relationship',
  2528. 'description' => 'Other records with relationships to this record.',
  2529. 'required' => FALSE,
  2530. 'settings' => [
  2531. 'auto_attach' => FALSE,
  2532. 'chado_table' => $rel_table,
  2533. 'chado_column' => $pkey,
  2534. 'base_table' => $table_name,
  2535. 'term_vocabulary' => 'SBO',
  2536. 'term_name' => 'Relationship',
  2537. 'term_accession' => '0000374',
  2538. ],
  2539. 'widget' => [
  2540. 'type' => 'sbo__relationship_widget',
  2541. 'settings' => [
  2542. 'display_label' => 1,
  2543. ],
  2544. ],
  2545. 'display' => [
  2546. 'default' => [
  2547. 'label' => 'hidden',
  2548. 'type' => 'sbo__relationship_formatter',
  2549. 'settings' => [
  2550. 'title' => 'Relationships',
  2551. 'empty' => 'There are no relationships',
  2552. ],
  2553. ],
  2554. ],
  2555. ];
  2556. }
  2557. return;
  2558. // SYNONYMS
  2559. $syn_table = $table_name . '_synonym';
  2560. if (chado_table_exists($syn_table)) {
  2561. $field_name = 'schema__alternate_name';
  2562. $schema = chado_get_schema($syn_table);
  2563. $pkey = $schema['primary key'][0];
  2564. $info[$field_name] = [
  2565. 'field_name' => $field_name,
  2566. 'entity_type' => $entity_type,
  2567. 'bundle' => $bundle->name,
  2568. 'label' => 'Synonyms',
  2569. 'description' => 'Alternate names, aliases or synonyms for this record.',
  2570. 'required' => FALSE,
  2571. 'settings' => [
  2572. 'auto_attach' => FALSE,
  2573. 'chado_table' => $syn_table,
  2574. 'chado_column' => $pkey,
  2575. 'base_table' => $table_name,
  2576. 'term_accession' => 'alternateName',
  2577. 'term_vocabulary' => 'schema',
  2578. 'term_name' => 'alternateName',
  2579. ],
  2580. 'widget' => [
  2581. 'type' => 'schema__alternate_name_widget',
  2582. 'settings' => [
  2583. 'display_label' => 1,
  2584. ],
  2585. ],
  2586. 'display' => [
  2587. 'default' => [
  2588. 'label' => 'hidden',
  2589. 'type' => 'schema__alternate_name_formatter',
  2590. 'settings' => [],
  2591. ],
  2592. ],
  2593. ];
  2594. }
  2595. }
  2596. /**
  2597. * Used to find all of the properties for a given table.
  2598. *
  2599. * @param $table_name
  2600. * The name of the base table.
  2601. * @param unknown $prop_table
  2602. * The name of the property table.
  2603. * @param $type_table
  2604. * The name of the table that contains the type specifier.
  2605. * @param $type_column
  2606. * The name of the column that contains the type specifier.
  2607. *
  2608. * @return
  2609. * An array of cvterm objects for the properties to be added as fields.
  2610. */
  2611. function tripal_chado_bundle_get_properties($table_name, $prop_table, $type_table, $type_column, $cvterm_id, $type_value) {
  2612. $tschema = chado_get_schema($table_name);
  2613. $schema = chado_get_schema($prop_table);
  2614. $tpkey = $tschema['primary key'][0];
  2615. $pkey = $schema['primary key'][0];
  2616. $props = NULL;
  2617. // Property tables can be a bit tricky because not all property types
  2618. // in the prop table are appropriate for each type of data. Also som
  2619. // bundle types are resolved via a property. So, we have to distinguish
  2620. // between these two cases.
  2621. $sql = '';
  2622. $args = [];
  2623. // First, If this is the case where the base table is 'cvterm' then we are wanting
  2624. // to get properties from the cvterm table using the cv_id as the
  2625. // differentiator.
  2626. if ($prop_table == 'cvtermprop') {
  2627. $sql = "
  2628. SELECT DISTINCT P.type_id
  2629. FROM {" . db_escape_table($prop_table) . "} P
  2630. INNER JOIN {" . db_escape_table($table_name) . "} T on T.$tpkey = P.$tpkey
  2631. WHERE T.cv_id = :cv_id
  2632. ";
  2633. $args[':cv_id'] = $type_value;
  2634. $props = chado_query($sql, $args);
  2635. }
  2636. // Second, is this the case where all of the records in the table are
  2637. // of this type? If so, then all properties apply
  2638. else {
  2639. if (!$type_column) {
  2640. $sql = 'SELECT DISTINCT type_id FROM {' . db_escape_table($prop_table) . '}';
  2641. $props = chado_query($sql, $args);
  2642. }
  2643. // Third, if this is the case where a content type is uniquely identified
  2644. // by a type_id value in the base table, then only properties associated
  2645. // with that type ID should be used.
  2646. else {
  2647. if ($type_column and !$type_table) {
  2648. $sql = "
  2649. SELECT DISTINCT P.type_id
  2650. FROM {" . db_escape_table($prop_table) . "} P
  2651. INNER JOIN {" . db_escape_table($table_name) . "} T on T.$tpkey = P.$tpkey
  2652. WHERE T.$type_column = :cvterm_id
  2653. ";
  2654. $args[':cvterm_id'] = $cvterm_id;
  2655. $props = chado_query($sql, $args);
  2656. }
  2657. // Fourth, if this is the case where a content type is uniquely identified
  2658. // via a term/value pair in the prop table.
  2659. else {
  2660. if ($type_column and $type_table == $prop_table and !empty($type_value)) {
  2661. $sql = "
  2662. SELECT DISTINCT P2.type_id
  2663. FROM {" . db_escape_table($prop_table) . "} P1
  2664. INNER JOIN {" . db_escape_table($table_name) . "} T on T.$tpkey = P1.$tpkey
  2665. INNER JOIN {" . db_escape_table($prop_table) . "} P2 on T.$tpkey = P2.$tpkey
  2666. WHERE P1.$type_column = :cvterm_id AND P1.value = :prop_value AND
  2667. P2.type_id != P1.type_id
  2668. ";
  2669. $args[':cvterm_id'] = $cvterm_id;
  2670. $args[':prop_value'] = $type_value;
  2671. $props = chado_query($sql, $args);
  2672. }
  2673. // Fifth, if this is the case where the content type is uniquely identified
  2674. // via another table (e.g. cvterm linking table) and not this prop table.
  2675. else {
  2676. if ($type_column and $type_table != $prop_table and empty($type_value)) {
  2677. $sql = "
  2678. SELECT DISTINCT P.type_id
  2679. FROM {" . db_escape_table($prop_table) . "} P
  2680. INNER JOIN {" . db_escape_table($table_name) . "} T on T.$tpkey = P.$tpkey
  2681. INNER JOIN {" . db_escape_table($type_table) . "} TT on TT.$tpkey = T.$tpkey
  2682. WHERE TT.$type_column = :cvterm_id
  2683. ";
  2684. $args[':cvterm_id'] = $cvterm_id;
  2685. $props = chado_query($sql, $args);
  2686. }
  2687. }
  2688. }
  2689. }
  2690. }
  2691. if (!$props) {
  2692. return [];
  2693. }
  2694. // Iterate through all of the properties and do some final checks to see
  2695. // which ones should be added.
  2696. $prop_arr = [];
  2697. if (!$props) {
  2698. return $prop_arr;
  2699. }
  2700. while ($prop = $props->fetchObject()) {
  2701. $term = chado_generate_var('cvterm', ['cvterm_id' => $prop->type_id]);
  2702. $term = chado_expand_var($term, 'field', 'cvterm.definition');
  2703. // The tripal_analysis_KEGG, tripal_analysis_blast, and
  2704. // tripal_analysis_interpro modules store results in the analysisprop
  2705. // table which is probably not the best place, but we don't want to
  2706. // create a ton of fields for this.
  2707. if ($prop_table == 'analysisprop' and
  2708. ($term->dbxref_id->db_id->name == 'KEGG_BRITE' or
  2709. $term->dbxref_id->db_id->name == 'tripal')) {
  2710. continue;
  2711. }
  2712. // The Tripal publication importer adds properties to publications that
  2713. // are also represented in the table fields. We want editing of pub
  2714. // related fields to always go back to the pub table, so we do not
  2715. // want prop fields to show up.
  2716. if ($table_name == 'pub') {
  2717. $skip_pub_property = FALSE;
  2718. $pub_terms = chado_get_semweb_terms('pub', ['return_object' => TRUE]);
  2719. foreach ($pub_terms as $pub_column => $mapped_term) {
  2720. $term_accession = $term->dbxref_id->db_id->name . ':' . $term->dbxref_id->accession;
  2721. $mapped_accession = $mapped_term->dbxref_id->db_id->name . ':' . $mapped_term->dbxref_id->accession;
  2722. if ($term_accession == $mapped_accession) {
  2723. $skip_pub_property = TRUE;
  2724. }
  2725. }
  2726. if ($skip_pub_property) {
  2727. continue;
  2728. }
  2729. }
  2730. // Add the term to our list!
  2731. $prop_arr[] = $term;
  2732. }
  2733. return $prop_arr;
  2734. }
  2735. /**
  2736. * Implements hook_bundle_create_user_field().
  2737. *
  2738. * A priviledged user has the ability to add new fields to the bundle. The
  2739. * chado_linker__prop and chado_linker__cvterm fields are allowed to be
  2740. * added dynamically by the user. But, Drupal doesn't know how to deal with
  2741. * it, so this function is called for any field attached to a TripalEntity
  2742. * bundle type. Any fields whose TripalField::$module argument is set to
  2743. * 'tripal_chado' and that can be added dynamically will result in a call
  2744. * to this function.
  2745. */
  2746. function tripal_chado_bundle_create_user_field($new_field, $bundle) {
  2747. // Get the table this bundle is mapped to.
  2748. $term = tripal_load_term_entity(['term_id' => $bundle->term_id]);
  2749. $vocab = $term->vocab;
  2750. $params = [
  2751. 'vocabulary' => $vocab->vocabulary,
  2752. 'accession' => $term->accession,
  2753. ];
  2754. $chado_table = $bundle->data_table;
  2755. $chado_type_table = $bundle->type_linker_table;
  2756. $chado_type_column = $bundle->type_column;
  2757. $chado_type_id = $bundle->type_id;
  2758. $chado_type_value = $bundle->type_value;
  2759. // We allow site admins to add new chado_linker__prop fields to an entity.
  2760. // This function will allow us to properly add them. But at this point we
  2761. // don't know the controlled vocabulary term. We'll have to use the
  2762. // defaults and let the user set it using the interface.
  2763. if ($new_field['type'] == 'chado_linker__prop') {
  2764. $table_name = $chado_table . 'prop';
  2765. if (chado_table_exists($table_name)) {
  2766. $schema = chado_get_schema($table_name);
  2767. $pkey = $schema['primary key'][0];
  2768. $field_name = $new_field['field_name'];
  2769. $field_type = 'chado_linker__prop';
  2770. // First add the field.
  2771. field_create_field([
  2772. 'field_name' => $field_name,
  2773. 'type' => $field_type,
  2774. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  2775. 'locked' => FALSE,
  2776. 'storage' => [
  2777. 'type' => 'field_chado_storage',
  2778. ],
  2779. ]);
  2780. // Now add the instance
  2781. field_create_instance([
  2782. 'field_name' => $field_name,
  2783. 'entity_type' => 'TripalEntity',
  2784. 'bundle' => $bundle->name,
  2785. 'label' => $new_field['label'],
  2786. 'description' => '',
  2787. 'required' => FALSE,
  2788. 'settings' => [
  2789. 'auto_attach' => TRUE,
  2790. 'base_table' => $chado_table,
  2791. 'chado_table' => $table_name,
  2792. 'chado_column' => $pkey,
  2793. 'term_vocabulary' => '',
  2794. 'term_accession' => '',
  2795. 'term_name' => '',
  2796. ],
  2797. 'widget' => [
  2798. 'type' => 'chado_linker__prop_widget',
  2799. 'settings' => [
  2800. 'display_label' => 1,
  2801. ],
  2802. ],
  2803. 'display' => [
  2804. 'default' => [
  2805. 'label' => 'inline',
  2806. 'type' => 'chado_linker__prop_formatter',
  2807. 'settings' => [],
  2808. ],
  2809. ],
  2810. ]);
  2811. }
  2812. else {
  2813. drupal_set_message('Cannot add a property field to this entity. Chado does not support properties for this data type.', 'error');
  2814. }
  2815. }
  2816. // We allow site admins to add new chado_linker__cvterm fields to an entity.
  2817. // This function will allow us to properly add them. But at this point we
  2818. // don't know the controlled vocabulary term. We'll have to use the
  2819. // defaults and let the user set it using the interface.
  2820. if ($new_field['type'] == 'chado_linker__cvterm') {
  2821. $table_name = $chado_table . '_cvterm';
  2822. if (chado_table_exists($table_name)) {
  2823. $schema = chado_get_schema($table_name);
  2824. $pkey = $schema['primary key'][0];
  2825. $field_name = $new_field['field_name'];
  2826. $field_type = 'chado_linker__cvterm';
  2827. // First add the field.
  2828. field_create_field([
  2829. 'field_name' => $field_name,
  2830. 'type' => $field_type,
  2831. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  2832. 'locked' => FALSE,
  2833. 'storage' => [
  2834. 'type' => 'field_chado_storage',
  2835. ],
  2836. 'settings' => [
  2837. 'base_table' => $chado_table,
  2838. 'chado_table' => $table_name,
  2839. 'chado_column' => $pkey,
  2840. ],
  2841. ]);
  2842. // Now add the instance
  2843. field_create_instance([
  2844. 'field_name' => $field_name,
  2845. 'entity_type' => 'TripalEntity',
  2846. 'bundle' => $bundle->name,
  2847. 'label' => $new_field['label'],
  2848. 'description' => '',
  2849. 'required' => FALSE,
  2850. 'settings' => [
  2851. 'auto_attach' => TRUE,
  2852. ],
  2853. 'widget' => [
  2854. 'type' => 'chado_linker__cvterm_widget',
  2855. 'settings' => [
  2856. 'display_label' => 1,
  2857. ],
  2858. ],
  2859. 'display' => [
  2860. 'default' => [
  2861. 'label' => 'above',
  2862. 'type' => 'chado_linker__cvterm_formatter',
  2863. 'settings' => [],
  2864. ],
  2865. ],
  2866. ]);
  2867. }
  2868. else {
  2869. drupal_set_message('Cannot add a property field to this entity. Chado does not support annotations for this data type.', 'error');
  2870. }
  2871. }
  2872. }
  2873. /**
  2874. * Allows for altering of a field's instance setting form.
  2875. *
  2876. * This appears to be a Drupal hook but is actually a custom function created
  2877. * by this module. It is called by the tripal_form_alter() function of this
  2878. * module.
  2879. *
  2880. * Here we put additional form elements for any field, regardless if it is
  2881. * a tripalField or not.
  2882. *
  2883. * @param $form
  2884. * The form array. Alterations to the form can be made within this array.
  2885. * @param $form_state
  2886. * The form state array.
  2887. */
  2888. function tripal_chado_field_instance_settings_form_alter(&$form, $form_state) {
  2889. global $language;
  2890. $field = $form['#field'];
  2891. $instance = $form['#instance'];
  2892. $base_table = array_key_exists('base_table', $instance['settings']) ? $instance['settings']['base_table'] : '';
  2893. $chado_table = array_key_exists('chado_table', $instance['settings']) ? $instance['settings']['chado_table'] : '';
  2894. $chado_column = array_key_exists('chado_column', $instance['settings']) ? $instance['settings']['chado_column'] : '';
  2895. if ($chado_table) {
  2896. // Construct a table for the vocabulary information.
  2897. $headers = [];
  2898. $rows = [];
  2899. $rows[] = [
  2900. [
  2901. 'data' => 'Base Table',
  2902. 'header' => TRUE,
  2903. 'width' => '20%',
  2904. ],
  2905. $base_table,
  2906. ];
  2907. $rows[] = [
  2908. [
  2909. 'data' => 'Record Table',
  2910. 'header' => TRUE,
  2911. 'width' => '20%',
  2912. ],
  2913. $chado_table,
  2914. ];
  2915. $rows[] = [
  2916. [
  2917. 'data' => 'ID Column',
  2918. 'header' => TRUE,
  2919. 'width' => '20%',
  2920. ],
  2921. $chado_column,
  2922. ];
  2923. $table = [
  2924. 'header' => $headers,
  2925. 'rows' => $rows,
  2926. 'attributes' => [
  2927. ],
  2928. 'sticky' => FALSE,
  2929. 'caption' => '',
  2930. 'colgroups' => [],
  2931. 'empty' => '',
  2932. ];
  2933. $form['chado_mapping'] = [
  2934. '#type' => 'fieldset',
  2935. '#title' => 'Chado Mapping',
  2936. '#description' => t('This field maps to data in Chado to the following table:'),
  2937. ];
  2938. $form['chado_mapping']['details'] = [
  2939. '#type' => 'item',
  2940. '#markup' => theme_table($table),
  2941. ];
  2942. }
  2943. }
  2944. /**
  2945. * Implements hook_form_FROM_ID_alter()
  2946. */
  2947. function tripal_chado_form_tripalbundle_form_alter(&$form, $form_state) {
  2948. global $language;
  2949. $bundle = $form['#bundle'];
  2950. $term = entity_load('TripalTerm', ['id' => $bundle->term_id]);
  2951. $term = reset($term);
  2952. $vocab = $term->vocab;
  2953. $params = [
  2954. 'vocabulary' => $vocab->vocabulary,
  2955. 'accession' => $term->accession,
  2956. ];
  2957. $chado_table = $bundle->data_table;
  2958. $chado_column = $bundle->type_column;
  2959. $chado_type_table = $bundle->type_linker_table;
  2960. $chado_type_id = $bundle->type_id;
  2961. $chado_type_value = $bundle->type_value;
  2962. // Construct a table for the vocabulary information.
  2963. $headers = [];
  2964. $rows = [];
  2965. $rows[] = [
  2966. [
  2967. 'data' => 'Chado Table',
  2968. 'header' => TRUE,
  2969. 'width' => '20%',
  2970. ],
  2971. $chado_table,
  2972. ];
  2973. if ($chado_column) {
  2974. $rows[] = [
  2975. [
  2976. 'data' => 'Type Column',
  2977. 'header' => TRUE,
  2978. 'width' => '20%',
  2979. ],
  2980. $chado_column,
  2981. ];
  2982. }
  2983. if ($chado_type_table) {
  2984. $rows[] = [
  2985. [
  2986. 'data' => 'Association Table',
  2987. 'header' => TRUE,
  2988. 'width' => '20%',
  2989. ],
  2990. $chado_type_table,
  2991. ];
  2992. }
  2993. if ($chado_type_table and $chado_type_id) {
  2994. $rows[] = [
  2995. [
  2996. 'data' => 'CVTerm Table ID',
  2997. 'header' => TRUE,
  2998. 'width' => '20%',
  2999. ],
  3000. $chado_type_id,
  3001. ];
  3002. }
  3003. if ($chado_type_value) {
  3004. $rows[] = [
  3005. [
  3006. 'data' => 'Property Value',
  3007. 'header' => TRUE,
  3008. 'width' => '20%',
  3009. ],
  3010. $chado_type_value,
  3011. ];
  3012. }
  3013. $table = [
  3014. 'header' => $headers,
  3015. 'rows' => $rows,
  3016. 'attributes' => [
  3017. ],
  3018. 'sticky' => FALSE,
  3019. 'caption' => '',
  3020. 'colgroups' => [],
  3021. 'empty' => '',
  3022. ];
  3023. $form['chado_mapping'] = [
  3024. '#type' => 'item',
  3025. '#title' => 'Chado Mapping',
  3026. '#markup' => theme_table($table),
  3027. '#description' => t('This content type maps to the table in Chado
  3028. listed above. Chado allows multiple data types to be housed
  3029. in a single table. Therefore, the column that is used to
  3030. differentiate between data types is also listed above.'),
  3031. '#weight' => 0,
  3032. ];
  3033. }
  3034. /**
  3035. * Implements hook_field_views_data_alter();
  3036. */
  3037. function tripal_chado_field_views_data_alter(&$result, $field) {
  3038. // This module creates the data__image field for managing images on
  3039. // bio_data content types. But we want it to render correctly
  3040. // so we need to set some handlers.
  3041. if ($field['field_name'] == 'data__image') {
  3042. foreach ($result as $key => $fields) {
  3043. // It's not clear how to identify our bundle types, but they do have
  3044. // a double underscore in their name to separate the vocabulary from
  3045. // the accession, so we'll use that to find them.
  3046. if (preg_match('/__/', $key)) {
  3047. $result[$key]['data__image']['field']['handler'] = 'tripal_views_handler_field_image';
  3048. }
  3049. }
  3050. }
  3051. }