tripal_chado.fields.inc 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246
  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. // TODO: Add settings so that the minutes increment by 1.
  944. // And turn off the timezone, as the Chado field doesn't support it.
  945. break;
  946. }
  947. // Set some default semantic web information
  948. if ($column_name == 'uniquename') {
  949. $base_info['label'] = 'Identifier';
  950. $base_info['widget']['type'] = 'text_textfield';
  951. if ($details['type'] == 'text') {
  952. unset($base_info['display']['default']['label']);
  953. unset($base_info['settings']['text_processing']);
  954. unset($base_info['settings']['format']);
  955. }
  956. }
  957. if ($base_info['label'] == 'Timeaccessioned') {
  958. $base_info['label'] = 'Time Accessioned';
  959. $base_info['description'] = 'The time that this record was first added to the database.';
  960. }
  961. if ($base_info['label'] == 'Timelastmodified') {
  962. $base_info['label'] = 'Time Last Modified';
  963. $base_info['description'] = 'The time that this record was last modified. The default is the current time.';
  964. }
  965. // Sometimes the boolean fields are listed as integer. We need to
  966. // correct for that.
  967. if ($column_name == 'is_obsolete' or $column_name == 'is_analysis' or
  968. $column_name == 'is_relationshiptype' or $column_name == 'is_for_definition' or
  969. $column_name == 'is_view' or $column_name == 'is_updateable') {
  970. $base_info['widget']['type'] = 'options_onoff';
  971. $base_info['required'] = FALSE;
  972. }
  973. //
  974. // ORGANISM TABLE
  975. //
  976. if ($table_name == 'organism' and $column_name == 'comment') {
  977. $base_info['label'] = 'Description';
  978. }
  979. //
  980. // BIOMATERIAL TABLE
  981. //
  982. if ($table_name == 'biomaterial' and $column_name == 'name') {
  983. $base_info['widget'] = [];
  984. $base_info['widget']['type'] = 'text_textfield';
  985. unset($base_info['display']['default']['label']);
  986. unset($base_info['settings']['text_processing']);
  987. unset($base_info['settings']['format']);
  988. }
  989. //
  990. // FEATUREMAP TABLE
  991. //
  992. if ($table_name == 'featuremap' and $column_name == 'name') {
  993. $base_info['required'] = TRUE;
  994. }
  995. //
  996. // PUB TABLE
  997. //
  998. if ($table_name == 'pub') {
  999. if ($column_name == 'title' or $column_name == 'type_id') {
  1000. $base_info['required'] = TRUE;
  1001. }
  1002. if ($column_name == 'uniquename' or $column_name == 'title' or $column_name == 'volumetitle') {
  1003. $base_info['widget']['type'] = 'text_textfield';
  1004. $base_info['settings']['text_processing'] = '0';
  1005. }
  1006. if ($column_name == 'uniquename') {
  1007. $base_info['label'] = 'Unique Local Identifier';
  1008. $base_info['required'] = TRUE;
  1009. $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.';
  1010. }
  1011. if ($column_name == 'title') {
  1012. $base_info['description'] = 'The title of the published work.';
  1013. }
  1014. if ($column_name == 'series_name') {
  1015. $base_info['description'] = 'The name media that produces a series of publications (e.g. journal, conference proceedings, etc.).';
  1016. }
  1017. if ($column_name == 'issue') {
  1018. $base_info['description'] = 'The issue of the series (e.g. journal) where the publication was printed.';
  1019. }
  1020. if ($column_name == 'volume') {
  1021. $base_info['description'] = 'The volume of the series (e.g. journal) where the publication was printed.';
  1022. }
  1023. if ($column_name == 'pyear') {
  1024. $base_info['label'] = 'Publication Year';
  1025. $base_info['required'] = TRUE;
  1026. }
  1027. if ($column_name == 'pages') {
  1028. $base_info['label'] = 'Page Numbers';
  1029. }
  1030. if ($column_name == 'pubplace') {
  1031. $base_info['label'] = 'Publication Location';
  1032. }
  1033. if ($column_name == 'volumetitle') {
  1034. $base_info['label'] = 'Volumn Title';
  1035. $base_info['label'] = 'The title of the volume (if applicable).';
  1036. }
  1037. if ($column_name == 'miniref') {
  1038. $base_info['label'] = 'Mini Local identifier';
  1039. $base_info['description'] = 'Some sites use small identifiers for each publication. if your site uses this please provide the proper miniref for this publication.';
  1040. }
  1041. }
  1042. //
  1043. // ANALYSIS TABLE
  1044. //
  1045. if ($table_name == 'analysis' and $column_name == 'name') {
  1046. $base_info['required'] = TRUE;
  1047. }
  1048. if ($table_name == 'analysis' and $column_name == 'program') {
  1049. $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.';
  1050. $base_info['label'] = 'Program, Pipeline, Workflow or Method Name';
  1051. }
  1052. if ($table_name == 'analysis' and $column_name == 'algorithm') {
  1053. $base_info['label'] = 'Algorithm';
  1054. $base_info['description'] = 'The name of the algorithm used to produce the dataset if different from the program.';
  1055. }
  1056. if ($table_name == 'analysis' and $column_name == 'programversion') {
  1057. $base_info['label'] = 'Program Version';
  1058. $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.';
  1059. }
  1060. if ($table_name == 'analysis' and $column_name == 'timeexecuted') {
  1061. $base_info['label'] = 'Date Performed';
  1062. $base_info['description'] = 'The date and time when the analysis was performed.';
  1063. }
  1064. if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
  1065. $column_name == 'sourceversion' or $column_name == 'sourcename')) {
  1066. // Skip the source columns in the analysis table. We have a custom
  1067. // field for those columns
  1068. continue;
  1069. }
  1070. //
  1071. // PROJECT TABLE
  1072. //
  1073. if ($table_name == 'project' and $column_name == 'description') {
  1074. $base_info['label'] = 'Short Description';
  1075. }
  1076. //
  1077. // CONTACT TABLE
  1078. //
  1079. if ($table_name == 'contact' and $column_name == 'description') {
  1080. $base_info['label'] = 'Short Description';
  1081. }
  1082. //
  1083. // PROTOCOL TABLE
  1084. //
  1085. if ($table_name == 'protocol') {
  1086. if ($column_name == 'protocoldescription') {
  1087. $base_info['label'] = 'Protocol Description';
  1088. }
  1089. if ($column_name == 'uri') {
  1090. $base_info['label'] = 'URI';
  1091. $base_info['widget']['type'] = 'text_textfield';
  1092. $base_info['settings']['text_processing'] = '0';
  1093. }
  1094. if ($column_name == 'name') {
  1095. $base_info['widget']['type'] = 'text_textfield';
  1096. $base_info['settings']['text_processing'] = '0';
  1097. }
  1098. if ($column_name == 'hardwaredescription') {
  1099. $base_info['label'] = 'Instrument Description';
  1100. $base_info['description'] = 'The description of instruments used for this protocol';
  1101. }
  1102. if ($column_name == 'softwaredescription') {
  1103. $base_info['label'] = 'Software Description';
  1104. $base_info['description'] = 'The description of software used for this protocol';
  1105. }
  1106. if ($column_name == 'pub_id') {
  1107. $base_info['label'] = 'Publication';
  1108. }
  1109. }
  1110. //
  1111. // ASSAY TABLE
  1112. //
  1113. if ($table_name == 'assay') {
  1114. if ($column_name == 'name') {
  1115. $base_info['widget']['type'] = 'text_textfield';
  1116. $base_info['settings']['text_processing'] = '0';
  1117. $base_info['required'] = TRUE;
  1118. $base_info['description'] = 'A unique name for this assay..';
  1119. }
  1120. if ($column_name == 'protcol_id') {
  1121. $base_info['label'] = 'Protocol';
  1122. }
  1123. if ($column_name == 'arraybatchidentifier') {
  1124. $base_info['label'] = 'Array Batch Identifier';
  1125. $base_info['widget']['type'] = 'text_textfield';
  1126. $base_info['settings']['text_processing'] = '0';
  1127. $base_info['description'] = 'A unique identifier for the array batch.';
  1128. }
  1129. if ($column_name == 'operator_id') {
  1130. $base_info['label'] = 'Operator';
  1131. $base_info['description'] = 'The individual who performed the assay.';
  1132. }
  1133. if ($column_name == 'arrayidentifier') {
  1134. $base_info['label'] = 'Array Identifier';
  1135. $base_info['widget']['type'] = 'text_textfield';
  1136. $base_info['settings']['text_processing'] = '0';
  1137. $base_info['description'] = 'A unique alternate identifier for the array.';
  1138. }
  1139. if ($column_name == 'arraydesign_id') {
  1140. $base_info['label'] = 'Array Design';
  1141. }
  1142. if ($column_name == 'assaydate') {
  1143. $base_info['label'] = 'Assay Date';
  1144. $base_info['description'] = 'The date the assay was performed';
  1145. }
  1146. }
  1147. //
  1148. // ARRAYDESIGN TABLE
  1149. //
  1150. if ($table_name == 'arraydesign') {
  1151. if ($column_name == 'name' or $column_name == 'version' or
  1152. $column_name == 'array_dimensions' or $column_name == 'element_dimensions') {
  1153. $base_info['widget']['type'] = 'text_textfield';
  1154. $base_info['settings']['text_processing'] = '0';
  1155. }
  1156. if ($column_name == 'platformtype_id') {
  1157. $base_info['label'] = 'Platform type';
  1158. }
  1159. if ($column_name == 'substratetype_id') {
  1160. $base_info['label'] = 'Substrate Type';
  1161. }
  1162. if ($column_name == 'manufacturer_id') {
  1163. $base_info['label'] = 'Manufacturer';
  1164. }
  1165. }
  1166. $info[$field_name] = $base_info;
  1167. }
  1168. }
  1169. /**
  1170. * Helper function for the hook_create_tripalfield_instance().
  1171. *
  1172. * Adds custom fields for base fields. These override the settings provided
  1173. * in the tripal_chado_create_tripalfield_instance_base() function.
  1174. *
  1175. * @param $entity_type
  1176. * @param $bundle
  1177. * @param $details
  1178. */
  1179. function tripal_chado_bundle_instances_info_custom(&$info, $entity_type, $bundle, $details) {
  1180. $table_name = $details['chado_table'];
  1181. $type_table = $details['chado_type_table'];
  1182. $type_column = $details['chado_type_column'];
  1183. $cvterm_id = $details['chado_cvterm_id'];
  1184. $type_value = $details['chado_type_value'];
  1185. $base_type_id = $details['chado_base_type_id'];
  1186. $schema = chado_get_schema($table_name);
  1187. // Add the additional_type field to all tables with a type_id that is not used
  1188. // as the type column nor has a $base_type_id (i.e. the content type uses a
  1189. // prop or linker table to resolve the type).
  1190. if (array_key_exists('type_id', $schema['fields']) and 'type_id' != $type_column and
  1191. !$base_type_id and $table_name != 'organism') {
  1192. $field_name = 'schema__additional_type';
  1193. $is_required = FALSE;
  1194. if (array_key_exists('not null', $schema['fields']['type_id']) and
  1195. $schema['fields']['type_id']['not null']) {
  1196. $is_required = TRUE;
  1197. }
  1198. $label = ucwords(preg_replace('/_/', ' ', $table_name)) . ' Type';
  1199. $default_vocab = '';
  1200. $parent_term = '';
  1201. switch ($table_name) {
  1202. case 'pub':
  1203. $default_vocab = 'tripal_pub';
  1204. $label = 'Publication Type';
  1205. $parent_term = 'TPUB:0000015';
  1206. $description = 'Select the type.';
  1207. break;
  1208. case 'contact':
  1209. $default_vocab = 'tripal_contact';
  1210. $parent_term = 'TCONTACT:0000001';
  1211. $description = 'Select the type.';
  1212. break;
  1213. default:
  1214. $description = t('Enter the name of the term that specifies the type. ' .
  1215. 'The type must be the name of a term in a controlled vocabulary and ' .
  1216. 'the controlled vocabulary should already be loaded into this site.');
  1217. }
  1218. $info[$field_name] = [
  1219. 'field_name' => $field_name,
  1220. 'entity_type' => $entity_type,
  1221. 'bundle' => $bundle->name,
  1222. 'label' => $label,
  1223. 'description' => $description,
  1224. 'required' => $is_required,
  1225. 'settings' => [
  1226. 'auto_attach' => TRUE,
  1227. 'chado_table' => $table_name,
  1228. 'chado_column' => 'type_id',
  1229. 'base_table' => $table_name,
  1230. 'vocabulary' => $default_vocab,
  1231. 'parent_term' => $parent_term,
  1232. 'term_vocabulary' => 'schema',
  1233. 'term_name' => 'additionalType',
  1234. 'term_accession' => 'additionalType',
  1235. ],
  1236. 'widget' => [
  1237. 'type' => 'schema__additional_type_widget',
  1238. 'settings' => [
  1239. 'display_label' => 1,
  1240. ],
  1241. ],
  1242. 'display' => [
  1243. 'default' => [
  1244. 'label' => 'inline',
  1245. 'type' => 'schema__additional_type_formatter',
  1246. 'settings' => [],
  1247. ],
  1248. ],
  1249. ];
  1250. }
  1251. if ($table_name == 'arraydesign') {
  1252. $field_name = 'ncit__technology_platform';
  1253. $default_vocab = '';
  1254. $parent_term = '';
  1255. $description = 'Select the platform type.';
  1256. $info[$field_name] = [
  1257. 'field_name' => $field_name,
  1258. 'entity_type' => $entity_type,
  1259. 'bundle' => $bundle->name,
  1260. 'label' => 'Platform Type',
  1261. 'description' => $description,
  1262. 'required' => TRUE,
  1263. 'settings' => [
  1264. 'auto_attach' => TRUE,
  1265. 'chado_table' => $table_name,
  1266. 'chado_column' => 'platformtype_id',
  1267. 'base_table' => $table_name,
  1268. 'vocabulary' => $default_vocab,
  1269. 'parent_term' => $parent_term,
  1270. 'term_vocabulary' => 'NCIT',
  1271. 'term_name' => 'Technology Platform',
  1272. 'term_accession' => 'C45378',
  1273. ],
  1274. 'widget' => [
  1275. 'type' => 'schema__additional_type_widget',
  1276. 'settings' => [
  1277. 'display_label' => 1,
  1278. ],
  1279. ],
  1280. 'display' => [
  1281. 'default' => [
  1282. 'label' => 'inline',
  1283. 'type' => 'schema__additional_type_formatter',
  1284. 'settings' => [],
  1285. ],
  1286. ],
  1287. ];
  1288. $field_name = 'efo__substrate_type';
  1289. $default_vocab = '';
  1290. $parent_term = '';
  1291. $description = 'Select the substrate type.';
  1292. $info[$field_name] = [
  1293. 'field_name' => $field_name,
  1294. 'entity_type' => $entity_type,
  1295. 'bundle' => $bundle->name,
  1296. 'label' => 'Substrate Type',
  1297. 'description' => $description,
  1298. 'required' => FALSE,
  1299. 'settings' => [
  1300. 'auto_attach' => TRUE,
  1301. 'chado_table' => $table_name,
  1302. 'chado_column' => 'substratetype_id',
  1303. 'base_table' => $table_name,
  1304. 'vocabulary' => $default_vocab,
  1305. 'parent_term' => $parent_term,
  1306. 'term_vocabulary' => 'EFO',
  1307. 'term_name' => 'substrate type',
  1308. 'term_accession' => '0005522',
  1309. ],
  1310. 'widget' => [
  1311. 'type' => 'schema__additional_type_widget',
  1312. 'settings' => [
  1313. 'display_label' => 1,
  1314. ],
  1315. ],
  1316. 'display' => [
  1317. 'default' => [
  1318. 'label' => 'inline',
  1319. 'type' => 'schema__additional_type_formatter',
  1320. 'settings' => [],
  1321. ],
  1322. ],
  1323. ];
  1324. }
  1325. // BASE ORGANISM_ID
  1326. if ($table_name != 'organism' and
  1327. (array_key_exists('organism_id', $schema['fields']) or
  1328. array_key_exists('taxon_id', $schema['fields']))) {
  1329. $field_name = 'obi__organism';
  1330. $is_required = FALSE;
  1331. $table_column = 'organism_id';
  1332. if ($table_name == 'biomaterial') {
  1333. $is_required = FALSE;
  1334. $table_column = 'taxon_id';
  1335. }
  1336. elseif (array_key_exists('not null', $schema['fields']['organism_id']) and
  1337. $schema['fields']['organism_id']['not null']) {
  1338. $is_required = TRUE;
  1339. }
  1340. $info[$field_name] = [
  1341. 'field_name' => $field_name,
  1342. 'entity_type' => $entity_type,
  1343. 'bundle' => $bundle->name,
  1344. 'label' => 'Organism',
  1345. 'description' => 'The full scientific name for a species..',
  1346. 'required' => $is_required,
  1347. 'settings' => [
  1348. 'auto_attach' => TRUE,
  1349. 'chado_table' => $table_name,
  1350. 'chado_column' => $table_column,
  1351. 'base_table' => $table_name,
  1352. 'term_accession' => '0100026',
  1353. 'term_vocabulary' => 'OBI',
  1354. 'term_name' => 'organism',
  1355. ],
  1356. 'widget' => [
  1357. 'type' => 'obi__organism_widget',
  1358. 'settings' => [
  1359. 'display_label' => 1,
  1360. ],
  1361. ],
  1362. 'display' => [
  1363. 'default' => [
  1364. 'label' => 'inline',
  1365. 'type' => 'obi__organism_formatter',
  1366. 'settings' => [],
  1367. ],
  1368. ],
  1369. ];
  1370. }
  1371. if ($table_name == 'biomaterial') {
  1372. $field_name = 'biomaterial__provider_id';
  1373. $field_type = 'local__contact';
  1374. $info[$field_name] = [
  1375. 'field_name' => $field_name,
  1376. 'entity_type' => $entity_type,
  1377. 'bundle' => $bundle->name,
  1378. 'label' => 'Contact',
  1379. 'description' => 'An indvidual or organization that serves as a contact for this record.',
  1380. 'required' => FALSE,
  1381. 'settings' => [
  1382. 'auto_attach' => FALSE,
  1383. 'chado_table' => 'biomaterial',
  1384. 'chado_column' => 'biosourceprovider_id',
  1385. 'base_table' => 'biomaterial',
  1386. 'term_accession' => 'contact',
  1387. 'term_vocabulary' => 'local',
  1388. 'term_name' => 'contact',
  1389. ],
  1390. 'widget' => [
  1391. 'type' => 'local__contact_widget',
  1392. 'settings' => [
  1393. 'display_label' => 1,
  1394. ],
  1395. ],
  1396. 'display' => [
  1397. 'default' => [
  1398. 'label' => 'inline',
  1399. 'type' => 'local__contact_formatter',
  1400. 'settings' => [],
  1401. ],
  1402. ],
  1403. ];
  1404. }
  1405. if ($table_name == 'arraydesign') {
  1406. $field_name = 'efo__array_manufacturer';
  1407. $field_type = 'local__contact';
  1408. $info[$field_name] = [
  1409. 'field_name' => $field_name,
  1410. 'entity_type' => $entity_type,
  1411. 'bundle' => $bundle->name,
  1412. 'label' => 'Manufacturer',
  1413. 'description' => 'A manufacturer\'s contact details',
  1414. 'required' => TRUE,
  1415. 'settings' => [
  1416. 'auto_attach' => FALSE,
  1417. 'chado_table' => 'arraydesign',
  1418. 'chado_column' => 'manufacturer_id',
  1419. 'base_table' => 'arraydesign',
  1420. 'term_vocabulary' => 'EFO',
  1421. 'term_name' => 'aarray manufacturer',
  1422. 'term_accession' => '0001728',
  1423. ],
  1424. 'widget' => [
  1425. 'type' => 'local__contact_widget',
  1426. 'settings' => [
  1427. 'display_label' => 1,
  1428. ],
  1429. ],
  1430. 'display' => [
  1431. 'default' => [
  1432. 'label' => 'inline',
  1433. 'type' => 'local__contact_formatter',
  1434. 'settings' => [],
  1435. ],
  1436. ],
  1437. ];
  1438. }
  1439. // BASE CVTERM
  1440. if ($table_name == 'cvterm') {
  1441. $field_name = 'sio__vocabulary';
  1442. $is_required = TRUE;
  1443. $info[$field_name] = [
  1444. 'field_name' => $field_name,
  1445. 'entity_type' => $entity_type,
  1446. 'bundle' => $bundle->name,
  1447. 'label' => 'Vocabulary',
  1448. 'description' => 'A controlled vocabulary.',
  1449. 'required' => $is_required,
  1450. 'settings' => [
  1451. 'auto_attach' => TRUE,
  1452. 'chado_table' => $table_name,
  1453. 'chado_column' => 'cv_id',
  1454. 'base_table' => $table_name,
  1455. 'term_accession' => '001080',
  1456. 'term_vocabulary' => 'SIO',
  1457. 'term_name' => 'vocabulary',
  1458. ],
  1459. 'widget' => [
  1460. 'type' => 'sio__vocabulary_widget',
  1461. 'settings' => [
  1462. 'display_label' => 1,
  1463. ],
  1464. ],
  1465. 'display' => [
  1466. 'default' => [
  1467. 'label' => 'inline',
  1468. 'type' => 'sio__vocabulary_formatter',
  1469. 'settings' => [],
  1470. ],
  1471. ],
  1472. ];
  1473. }
  1474. // BASE DBXREF
  1475. if (array_key_exists('dbxref_id', $schema['fields'])) {
  1476. $field_name = 'data__accession';
  1477. $required = FALSE;
  1478. if (array_key_exists('not null', $schema['fields']['dbxref_id']) and
  1479. $schema['fields']['dbxref_id']['not null']) {
  1480. $required = TRUE;
  1481. }
  1482. $info[$field_name] = [
  1483. 'field_name' => $field_name,
  1484. 'entity_type' => $entity_type,
  1485. 'bundle' => $bundle->name,
  1486. 'label' => 'Accession',
  1487. 'description' => 'This field specifies the unique stable accession (ID) for
  1488. this record. It requires that this site have a database entry.',
  1489. 'required' => $required,
  1490. 'settings' => [
  1491. 'auto_attach' => TRUE,
  1492. 'chado_table' => $table_name,
  1493. 'chado_column' => 'dbxref_id',
  1494. 'base_table' => $table_name,
  1495. 'term_accession' => '2091',
  1496. 'term_vocabulary' => 'data',
  1497. 'term_name' => 'Accession',
  1498. ],
  1499. 'widget' => [
  1500. 'type' => 'data__accession_widget',
  1501. 'settings' => [
  1502. 'display_label' => 1,
  1503. ],
  1504. ],
  1505. 'display' => [
  1506. 'default' => [
  1507. 'label' => 'inline',
  1508. 'type' => 'data__accession_formatter',
  1509. 'settings' => [],
  1510. ],
  1511. ],
  1512. ];
  1513. }
  1514. // FEATURE MD5CHECKSUM
  1515. if ($table_name == 'feature') {
  1516. $field_name = 'data__sequence_checksum';
  1517. $info[$field_name] = [
  1518. 'field_name' => $field_name,
  1519. 'entity_type' => $entity_type,
  1520. 'bundle' => $bundle->name,
  1521. 'label' => 'Sequence Checksum',
  1522. 'description' => 'The MD5 checksum for the sequence. The checksum here
  1523. will always be unique for the raw unformatted sequence. To verify that the
  1524. sequence has not been corrupted, download the raw sequence and use an MD5 tool
  1525. to calculate the value. If the value calculated is identical the one shown
  1526. here, then the downloaded sequence is uncorrupted.',
  1527. 'required' => FALSE,
  1528. 'settings' => [
  1529. 'auto_attach' => TRUE,
  1530. 'chado_table' => $table_name,
  1531. 'chado_column' => 'md5checksum',
  1532. 'base_table' => $table_name,
  1533. 'term_accession' => '2190',
  1534. 'term_vocabulary' => 'data',
  1535. 'term_name' => 'Sequence checksum',
  1536. ],
  1537. 'widget' => [
  1538. 'type' => 'data__sequence_checksum_widget',
  1539. 'settings' => [
  1540. 'display_label' => 1,
  1541. 'md5_fieldname' => 'feature__md5checksum',
  1542. ],
  1543. ],
  1544. 'display' => [
  1545. 'default' => [
  1546. 'label' => 'inline',
  1547. 'type' => 'data__sequence_checksum_formatter',
  1548. 'settings' => [],
  1549. ],
  1550. ],
  1551. ];
  1552. }
  1553. // FEATURE RESIDUES
  1554. if ($table_name == 'feature') {
  1555. $field_name = 'data__sequence';
  1556. $info[$field_name] = [
  1557. 'field_name' => $field_name,
  1558. 'entity_type' => $entity_type,
  1559. 'bundle' => $bundle->name,
  1560. 'label' => 'Sequence',
  1561. 'description' => 'One or more molecular sequences, possibly with associated annotation.',
  1562. 'required' => FALSE,
  1563. 'settings' => [
  1564. 'auto_attach' => FALSE,
  1565. 'chado_table' => $table_name,
  1566. 'chado_column' => 'residues',
  1567. 'base_table' => $table_name,
  1568. 'term_accession' => '2044',
  1569. 'term_vocabulary' => 'data',
  1570. 'term_name' => 'Sequence',
  1571. ],
  1572. 'widget' => [
  1573. 'type' => 'data__sequence_widget',
  1574. 'settings' => [
  1575. 'display_label' => 1,
  1576. ],
  1577. ],
  1578. 'display' => [
  1579. 'default' => [
  1580. 'label' => 'above',
  1581. 'type' => 'data__sequence_formatter',
  1582. 'settings' => [],
  1583. ],
  1584. ],
  1585. ];
  1586. }
  1587. // FEATURE SEQLEN
  1588. if ($table_name == 'feature') {
  1589. $field_name = 'data__sequence_length';
  1590. $info[$field_name] = [
  1591. 'field_name' => $field_name,
  1592. 'entity_type' => $entity_type,
  1593. 'bundle' => $bundle->name,
  1594. 'label' => 'Sequence Length',
  1595. 'description' => 'The number of residues in the raw sequence. This length
  1596. is only for the assigned raw sequence and does not represent the length of any
  1597. sequences derived from alignments. If this value is zero but aligned sequences
  1598. are present then this record has no official assigned sequence.',
  1599. 'required' => FALSE,
  1600. 'settings' => [
  1601. 'auto_attach' => TRUE,
  1602. 'chado_table' => $table_name,
  1603. 'chado_column' => 'seqlen',
  1604. 'base_table' => $table_name,
  1605. 'term_accession' => '1249',
  1606. 'term_vocabulary' => 'data',
  1607. 'term_name' => 'delete Sequence length',
  1608. ],
  1609. 'widget' => [
  1610. 'type' => 'data__sequence_length_widget',
  1611. 'settings' => [
  1612. 'display_label' => 1,
  1613. ],
  1614. ],
  1615. 'display' => [
  1616. 'default' => [
  1617. 'label' => 'inline',
  1618. 'type' => 'data__sequence_length_formatter',
  1619. 'settings' => [],
  1620. ],
  1621. ],
  1622. ];
  1623. }
  1624. // PROTEIN & CDS SEQUENCES.
  1625. if ($table_name == 'feature' and
  1626. ($bundle->term->name == 'mRNA' or $bundle->term->name == 'transcript')) {
  1627. $field_name = 'data__protein_sequence';
  1628. $info[$field_name] = [
  1629. 'field_name' => $field_name,
  1630. 'entity_type' => $entity_type,
  1631. 'bundle' => $bundle->name,
  1632. 'label' => 'Protein Sequence',
  1633. 'description' => 'Protein sequences.',
  1634. 'required' => FALSE,
  1635. 'settings' => [
  1636. 'auto_attach' => FALSE,
  1637. 'chado_table' => 'feature',
  1638. 'chado_column' => 'residues',
  1639. 'base_table' => 'feature',
  1640. 'term_accession' => '2976',
  1641. 'term_vocabulary' => 'data',
  1642. 'term_name' => 'Protein sequence',
  1643. ],
  1644. 'widget' => [
  1645. 'type' => 'data__protein_sequence_widget',
  1646. 'settings' => [
  1647. 'display_label' => 1,
  1648. ],
  1649. ],
  1650. 'display' => [
  1651. 'default' => [
  1652. 'label' => 'above',
  1653. 'type' => 'data__protein_sequence_formatter',
  1654. 'settings' => [],
  1655. ],
  1656. ],
  1657. ];
  1658. $field_name = 'so__cds';
  1659. $info[$field_name] = [
  1660. 'field_name' => $field_name,
  1661. 'entity_type' => $entity_type,
  1662. 'bundle' => $bundle->name,
  1663. 'label' => 'Coding Sequence (CDS)',
  1664. 'description' => 'Coding sequences.',
  1665. 'required' => FALSE,
  1666. 'settings' => [
  1667. 'auto_attach' => FALSE,
  1668. 'chado_table' => 'featureprop',
  1669. 'chado_column' => 'value',
  1670. 'base_table' => 'feature',
  1671. 'term_vocabulary' => 'SO',
  1672. 'term_name' => 'CDS',
  1673. 'term_accession' => '0000316',
  1674. ],
  1675. 'widget' => [
  1676. 'type' => 'so__cds_widget',
  1677. 'settings' => [
  1678. 'display_label' => 1,
  1679. ],
  1680. ],
  1681. 'display' => [
  1682. 'default' => [
  1683. 'label' => 'above',
  1684. 'type' => 'so__cds_formatter',
  1685. 'settings' => [],
  1686. ],
  1687. ],
  1688. ];
  1689. }
  1690. // GENE TRANSCRIPTS
  1691. $rel_table = $table_name . '_relationship';
  1692. if (chado_table_exists($rel_table) and ($bundle->term->name == 'gene')) {
  1693. $field_name = 'so__transcript';
  1694. $info[$field_name] = [
  1695. 'field_name' => $field_name,
  1696. 'entity_type' => $entity_type,
  1697. 'bundle' => $bundle->name,
  1698. 'label' => 'Transcripts',
  1699. 'description' => 'Transcripts that are part of this gene.',
  1700. 'required' => FALSE,
  1701. 'settings' => [
  1702. 'auto_attach' => FALSE,
  1703. 'chado_table' => $rel_table,
  1704. 'chado_column' => '',
  1705. 'base_table' => $table_name,
  1706. 'term_vocabulary' => 'SO',
  1707. 'term_name' => 'transcript',
  1708. 'term_accession' => '0000673',
  1709. ],
  1710. 'widget' => [
  1711. 'type' => 'so__transcript_widget',
  1712. 'settings' => [
  1713. 'display_label' => 1,
  1714. ],
  1715. ],
  1716. 'display' => [
  1717. 'default' => [
  1718. 'label' => 'above',
  1719. 'type' => 'so__transcript_formatter',
  1720. 'settings' => [],
  1721. ],
  1722. ],
  1723. ];
  1724. }
  1725. // ORGANISM TYPE_ID
  1726. if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
  1727. $field_name = 'taxrank__infraspecific_taxon';
  1728. $info[$field_name] = [
  1729. 'field_name' => $field_name,
  1730. 'entity_type' => $entity_type,
  1731. 'bundle' => $bundle->name,
  1732. 'label' => 'Infraspecific Taxon',
  1733. 'description' => 'The Infraspecific Taxon.',
  1734. 'required' => FALSE,
  1735. 'settings' => [
  1736. 'auto_attach' => TRUE,
  1737. 'chado_table' => 'organism',
  1738. 'chado_column' => 'type_id',
  1739. 'base_table' => 'organism',
  1740. 'term_vocabulary' => 'TAXRANK',
  1741. 'term_name' => 'infraspecific_taxon',
  1742. 'term_accession' => '0000046',
  1743. ],
  1744. 'widget' => [
  1745. 'type' => 'taxrank__infraspecific_taxon_widget',
  1746. 'settings' => [
  1747. 'display_label' => 1,
  1748. ],
  1749. ],
  1750. 'display' => [
  1751. 'default' => [
  1752. 'label' => 'inline',
  1753. 'type' => 'taxrank__infraspecific_taxon_formatter',
  1754. 'settings' => [],
  1755. ],
  1756. ],
  1757. ];
  1758. }
  1759. // FEATURE MAP UNITS
  1760. if ($table_name == 'featuremap') {
  1761. $field_name = 'uo__unit';
  1762. $info[$field_name] = [
  1763. 'field_name' => $field_name,
  1764. 'entity_type' => $entity_type,
  1765. 'bundle' => $bundle->name,
  1766. 'label' => 'Units',
  1767. 'description' => 'The map\'s unit type.',
  1768. 'required' => TRUE,
  1769. 'settings' => [
  1770. 'auto_attach' => TRUE,
  1771. 'chado_table' => $table_name,
  1772. 'chado_column' => 'unittype_id',
  1773. 'base_table' => $table_name,
  1774. 'term_accession' => '0000000',
  1775. 'term_vocabulary' => 'UO',
  1776. 'term_name' => 'unit',
  1777. ],
  1778. 'widget' => [
  1779. 'type' => 'uo__unit_widget',
  1780. 'settings' => [
  1781. 'display_label' => 1,
  1782. ],
  1783. ],
  1784. 'display' => [
  1785. 'default' => [
  1786. 'label' => 'inline',
  1787. 'type' => 'uo__unit_formatter',
  1788. 'settings' => [],
  1789. ],
  1790. ],
  1791. ];
  1792. }
  1793. // the analysis source.
  1794. if ($table_name == 'analysis') {
  1795. $field_name = 'local__source_data';
  1796. $info[$field_name] = [
  1797. 'field_name' => $field_name,
  1798. 'entity_type' => $entity_type,
  1799. 'bundle' => $bundle->name,
  1800. 'label' => 'Data Source',
  1801. 'description' => 'The source where data was obtained for this analysis.',
  1802. 'required' => FALSE,
  1803. 'settings' => [
  1804. 'auto_attach' => TRUE,
  1805. 'chado_table' => $table_name,
  1806. 'chado_column' => 'analysis_id',
  1807. 'base_table' => $table_name,
  1808. 'term_accession' => 'source_data',
  1809. 'term_vocabulary' => 'local',
  1810. 'term_name' => 'source_data',
  1811. ],
  1812. 'widget' => [
  1813. 'type' => 'local__source_data_widget',
  1814. 'settings' => [
  1815. 'display_label' => 1,
  1816. ],
  1817. ],
  1818. 'display' => [
  1819. 'default' => [
  1820. 'label' => 'inline',
  1821. 'type' => 'local__source_data_formatter',
  1822. 'settings' => [],
  1823. ],
  1824. ],
  1825. ];
  1826. }
  1827. // Add an image field to the Organism type. This is a Drupal field and
  1828. // not stored in Chado, but is used for backwards compatibility.
  1829. if ($table_name == 'organism') {
  1830. $field_name = 'data__image';
  1831. $info[$field_name] = [
  1832. 'field_name' => $field_name,
  1833. 'entity_type' => $entity_type,
  1834. 'bundle' => $bundle->name,
  1835. 'label' => 'Organism Image',
  1836. 'description' => 'An image for the organism',
  1837. 'required' => FALSE,
  1838. 'settings' => [
  1839. 'term_vocabulary' => 'data',
  1840. 'term_name' => 'Image',
  1841. 'term_accession' => '2968',
  1842. ],
  1843. 'display' => [
  1844. 'default' => [
  1845. 'label' => 'hidden',
  1846. ],
  1847. ],
  1848. ];
  1849. }
  1850. // Phylotree Viewer
  1851. if ($table_name == 'phylotree') {
  1852. $field_name = 'operation__phylotree_vis';
  1853. $schema = chado_get_schema('phylotree');
  1854. $pkey = $schema['primary key'][0];
  1855. $info[$field_name] = [
  1856. 'field_name' => $field_name,
  1857. 'entity_type' => $entity_type,
  1858. 'bundle' => $bundle->name,
  1859. 'label' => 'Tree View',
  1860. 'description' => 'Rendering of a phylogenetic tree.',
  1861. 'required' => FALSE,
  1862. 'settings' => [
  1863. 'auto_attach' => FALSE,
  1864. 'chado_table' => 'phylotree',
  1865. 'chado_column' => 'type_id',
  1866. 'base_table' => 'phylotree',
  1867. 'term_accession' => '0567',
  1868. 'term_vocabulary' => 'operation',
  1869. 'term_name' => 'Phylogenetic tree visualisation',
  1870. ],
  1871. 'widget' => [
  1872. 'type' => 'operation__phylotree_vis_widget',
  1873. 'settings' => [
  1874. 'display_label' => 0,
  1875. ],
  1876. ],
  1877. 'display' => [
  1878. 'default' => [
  1879. 'label' => 'hidden',
  1880. 'type' => 'operation__phylotree_vis_formatter',
  1881. 'settings' => [],
  1882. ],
  1883. ],
  1884. ];
  1885. }
  1886. // PROTOCOL FIELD
  1887. if ($table_name != 'protocol' and
  1888. (array_key_exists('protocol_id', $schema['fields']))) {
  1889. $field_name = 'sep__protocol';
  1890. $is_required = FALSE;
  1891. $table_column = 'protocol_id';
  1892. if (array_key_exists('not null', $schema['fields']['protocol_id']) and
  1893. $schema['fields']['protocol_id']['not null']) {
  1894. $is_required = TRUE;
  1895. }
  1896. $info[$field_name] = [
  1897. 'field_name' => $field_name,
  1898. 'entity_type' => $entity_type,
  1899. 'bundle' => $bundle->name,
  1900. 'label' => 'Protocol',
  1901. 'description' => 'The parameterizable description of a process',
  1902. 'required' => $is_required,
  1903. 'settings' => [
  1904. 'auto_attach' => TRUE,
  1905. 'chado_table' => $table_name,
  1906. 'chado_column' => $table_column,
  1907. 'base_table' => $table_name,
  1908. 'term_accession' => '00101',
  1909. 'term_vocabulary' => 'sep',
  1910. 'term_name' => 'Protocol',
  1911. ],
  1912. 'widget' => [
  1913. 'type' => 'sep__protocol_widget',
  1914. 'settings' => [
  1915. 'display_label' => 1,
  1916. ],
  1917. ],
  1918. 'display' => [
  1919. 'default' => [
  1920. 'label' => 'inline',
  1921. 'type' => 'sep__protocol_formatter',
  1922. 'settings' => [],
  1923. ],
  1924. ],
  1925. ];
  1926. }
  1927. // pub_id field in table.
  1928. $schema = chado_get_schema($table_name);
  1929. if (array_key_exists('pub_id', $schema['fields']) and $table_name != 'pub') {
  1930. // Remove the schema__publication added by the
  1931. // tripal_chado_bunde_instnaces_info_base function.
  1932. unset($info['schema__publication']);
  1933. $field_name = 'schema__publication_single';
  1934. $info[$field_name] = [
  1935. 'field_name' => $field_name,
  1936. 'entity_type' => $entity_type,
  1937. 'bundle' => $bundle->name,
  1938. 'label' => 'Publication',
  1939. 'description' => 'This record has been referenced or is sourced from these publications.',
  1940. 'required' => FALSE,
  1941. 'settings' => [
  1942. 'auto_attach' => TRUE,
  1943. 'chado_table' => $table_name,
  1944. 'chado_column' => 'pub_id',
  1945. 'base_table' => $table_name,
  1946. 'term_accession' => 'publication',
  1947. 'term_vocabulary' => 'schema',
  1948. 'term_name' => 'publication',
  1949. ],
  1950. 'widget' => [
  1951. 'type' => 'schema__publication_widget',
  1952. 'settings' => [
  1953. 'display_label' => 1,
  1954. ],
  1955. ],
  1956. 'display' => [
  1957. 'default' => [
  1958. 'label' => 'hidden',
  1959. 'type' => 'schema__publication_formatter',
  1960. 'settings' => [],
  1961. ],
  1962. ],
  1963. ];
  1964. }
  1965. if ($table_name == 'assay') {
  1966. // Remove the ncit__operator added by the
  1967. // tripal_chado_bunde_instnaces_info_base function.
  1968. unset($info['ncit__operator']);
  1969. $field_name = 'assay__operator_id';
  1970. $info[$field_name] = [
  1971. 'field_name' => $field_name,
  1972. 'entity_type' => $entity_type,
  1973. 'bundle' => $bundle->name,
  1974. 'label' => 'Operator',
  1975. 'description' => 'The individual responsible for performing the assay.',
  1976. 'required' => TRUE,
  1977. 'settings' => [
  1978. 'auto_attach' => TRUE,
  1979. 'chado_table' => 'assay',
  1980. 'chado_column' => 'operator_id',
  1981. 'base_table' => 'assay',
  1982. 'term_vocabulary' => 'NCIT',
  1983. 'term_name' => 'Operator',
  1984. 'term_accession' => 'C48036',
  1985. ],
  1986. 'widget' => [
  1987. 'type' => 'local__contact_widget',
  1988. 'settings' => [
  1989. 'display_label' => 1,
  1990. ],
  1991. ],
  1992. 'display' => [
  1993. 'default' => [
  1994. 'label' => 'inline',
  1995. 'type' => 'local__contact_formatter',
  1996. 'settings' => [],
  1997. ],
  1998. ],
  1999. ];
  2000. $field_name = 'efo__array_design';
  2001. $info[$field_name] = [
  2002. 'field_name' => $field_name,
  2003. 'entity_type' => $entity_type,
  2004. 'bundle' => $bundle->name,
  2005. 'label' => 'Array design',
  2006. 'description' => 'An instrument design which describes the design of the array.',
  2007. 'required' => TRUE,
  2008. 'settings' => [
  2009. 'auto_attach' => TRUE,
  2010. 'chado_table' => 'assay',
  2011. 'chado_column' => 'arraydesign_id',
  2012. 'base_table' => 'assay',
  2013. 'term_vocabulary' => 'EFO',
  2014. 'term_name' => 'array design',
  2015. 'term_accession' => '0000269',
  2016. ],
  2017. 'widget' => [
  2018. 'type' => 'efo__array_design_widget',
  2019. 'settings' => [
  2020. 'display_label' => 1,
  2021. ],
  2022. ],
  2023. 'display' => [
  2024. 'default' => [
  2025. 'label' => 'inline',
  2026. 'type' => 'efo__array_design_formatter',
  2027. 'settings' => [],
  2028. ],
  2029. ],
  2030. ];
  2031. }
  2032. // Analysis Id
  2033. if (array_key_exists('analysis_id', $schema['fields']) and $table_name != 'analysis') {
  2034. $field_name = 'operation__analysis';
  2035. $is_required = FALSE;
  2036. if (array_key_exists('not null', $schema['fields']['analysis_id']) and
  2037. $schema['fields']['analysis_id']['not null']) {
  2038. $is_required = TRUE;
  2039. }
  2040. $info[$field_name] = [
  2041. 'field_name' => $field_name,
  2042. 'entity_type' => $entity_type,
  2043. 'bundle' => $bundle->name,
  2044. 'label' => 'Analysis',
  2045. 'description' => 'Application of analytical methods to existing data of a specific type.',
  2046. 'required' => $is_required,
  2047. 'settings' => [
  2048. 'auto_attach' => TRUE,
  2049. 'chado_table' => $table_name,
  2050. 'chado_column' => 'analysis_id',
  2051. 'base_table' => $table_name,
  2052. 'term_vocabulary' => 'operation',
  2053. 'term_name' => 'Analysis',
  2054. 'term_accession' => '2945',
  2055. ],
  2056. 'widget' => [
  2057. 'type' => 'operation__analysis_widget',
  2058. 'settings' => [
  2059. 'display_label' => 0,
  2060. ],
  2061. ],
  2062. 'display' => [
  2063. 'default' => [
  2064. 'label' => 'inline',
  2065. 'type' => 'operation__analysis_formatter',
  2066. 'settings' => [],
  2067. ],
  2068. ],
  2069. ];
  2070. }
  2071. }
  2072. /**
  2073. *
  2074. * @param unknown $entity_type
  2075. * @param unknown $bundle
  2076. * @param unknown $details
  2077. */
  2078. function tripal_chado_bundle_instances_info_linker(&$info, $entity_type, $bundle, $details) {
  2079. $table_name = $details['chado_table'];
  2080. $type_table = $details['chado_type_table'];
  2081. $type_column = $details['chado_type_column'];
  2082. $cvterm_id = $details['chado_cvterm_id'];
  2083. $type_value = $details['chado_type_value'];
  2084. // CONTACTS
  2085. $contact_table = $table_name . '_contact';
  2086. if (chado_table_exists($contact_table)) {
  2087. $field_name = $table_name . '_contact';
  2088. $info[$field_name] = $info[$field_name] = [
  2089. 'field_name' => $field_name,
  2090. 'entity_type' => $entity_type,
  2091. 'bundle' => $bundle->name,
  2092. 'label' => 'Contact',
  2093. 'description' => 'Associates an indviddual or organization with this record',
  2094. 'required' => FALSE,
  2095. 'settings' => [
  2096. 'auto_attach' => FALSE,
  2097. 'chado_table' => $contact_table,
  2098. 'base_table' => $table_name,
  2099. 'chado_column' => 'contact_id',
  2100. 'term_accession' => 'contact',
  2101. 'term_vocabulary' => 'local',
  2102. 'term_name' => 'contact',
  2103. ],
  2104. 'widget' => [
  2105. 'type' => 'chado_linker__contact_widget',
  2106. 'settings' => [
  2107. 'display_label' => 1,
  2108. ],
  2109. ],
  2110. 'display' => [
  2111. 'default' => [
  2112. 'label' => 'hidden',
  2113. 'type' => 'chado_linker__contact_formatter',
  2114. 'settings' => [],
  2115. ],
  2116. ],
  2117. ];
  2118. }
  2119. // DBXREF
  2120. $dbxref_table = $table_name . '_dbxref';
  2121. if (chado_table_exists($dbxref_table)) {
  2122. $field_name = 'sbo__database_cross_reference';
  2123. $schema = chado_get_schema($dbxref_table);
  2124. $pkey = $schema['primary key'][0];
  2125. $info[$field_name] = [
  2126. 'field_name' => $field_name,
  2127. 'entity_type' => $entity_type,
  2128. 'bundle' => $bundle->name,
  2129. 'label' => 'Cross Reference',
  2130. 'description' => 'The IDs where this record may be available in other external online databases.',
  2131. 'required' => FALSE,
  2132. 'settings' => [
  2133. 'auto_attach' => FALSE,
  2134. 'chado_table' => $dbxref_table,
  2135. 'chado_column' => $pkey,
  2136. 'base_table' => $table_name,
  2137. 'term_vocabulary' => 'SBO',
  2138. 'term_name' => 'Database Cross Reference',
  2139. 'term_accession' => '0000554',
  2140. ],
  2141. 'widget' => [
  2142. 'type' => 'sbo__database_cross_reference_widget',
  2143. 'settings' => [
  2144. 'display_label' => 1,
  2145. ],
  2146. ],
  2147. 'display' => [
  2148. 'default' => [
  2149. 'label' => 'hidden',
  2150. 'type' => 'sbo__database_cross_reference_formatter',
  2151. 'settings' => [],
  2152. ],
  2153. ],
  2154. ];
  2155. }
  2156. // EXPRESSION
  2157. // TODO: this should only show up on gene or mRNA and the GO must be
  2158. // laoded or this field will crash things.
  2159. // $expression_table = $table_name . '_expression';
  2160. // if (chado_table_exists($expression_table)) {
  2161. // $field_name = 'go__gene_expression';
  2162. // $schema = chado_get_schema($expression_table);
  2163. // $pkey = $schema['primary key'][0];
  2164. // $info[$field_name] = array(
  2165. // 'field_name' => $field_name,
  2166. // 'entity_type' => $entity_type,
  2167. // 'bundle' => $bundle->name,
  2168. // 'label' => 'Gene expression',
  2169. // 'description' => 'Information about the expression of this record.',
  2170. // 'required' => FALSE,
  2171. // 'settings' => array(
  2172. // 'auto_attach' => FALSE,
  2173. // 'chado_table' => $expression_table,
  2174. // 'chado_column' => $pkey,
  2175. // 'base_table' => $table_name,
  2176. // 'term_accession' => '',
  2177. // 'term_vocabulary' => '',
  2178. // 'term_name' => '',
  2179. // ),
  2180. // 'widget' => array(
  2181. // 'type' => 'go__gene_expression_widget',
  2182. // 'settings' => array(
  2183. // 'display_label' => 1,
  2184. // ),
  2185. // ),
  2186. // 'display' => array(
  2187. // 'default' => array(
  2188. // 'label' => 'above',
  2189. // 'type' => 'go__gene_expression_formatter',
  2190. // 'settings' => array(),
  2191. // ),
  2192. // ),
  2193. // );
  2194. // }
  2195. // FEATURELOC
  2196. if ($table_name == 'feature') {
  2197. $field_name = 'data__sequence_coordinates';
  2198. $schema = chado_get_schema('featureloc');
  2199. $pkey = $schema['primary key'][0];
  2200. $info[$field_name] = [
  2201. 'field_name' => $field_name,
  2202. 'entity_type' => $entity_type,
  2203. 'bundle' => $bundle->name,
  2204. 'label' => 'Sequence Coordinates',
  2205. 'description' => 'The locations on other genomic sequences where this
  2206. record has been aligned.',
  2207. 'required' => FALSE,
  2208. 'settings' => [
  2209. 'auto_attach' => FALSE,
  2210. 'chado_table' => 'featureloc',
  2211. 'chado_column' => $pkey,
  2212. 'base_table' => 'feature',
  2213. 'term_accession' => '2012',
  2214. 'term_vocabulary' => 'data',
  2215. 'term_name' => 'Sequence coordinates',
  2216. ],
  2217. 'widget' => [
  2218. 'type' => 'data__sequence_coordinates_widget',
  2219. 'settings' => [
  2220. 'display_label' => 1,
  2221. ],
  2222. ],
  2223. 'display' => [
  2224. 'default' => [
  2225. 'label' => 'hidden',
  2226. 'type' => 'data__sequence_coordinates_formatter',
  2227. 'settings' => [],
  2228. ],
  2229. ],
  2230. ];
  2231. }
  2232. // FEATUREPOS
  2233. if ($table_name == 'feature') {
  2234. $field_name = 'ogi__location_on_map';
  2235. $schema = chado_get_schema('featurepos');
  2236. $pkey = $schema['primary key'][0];
  2237. $info[$field_name] = [
  2238. 'field_name' => $field_name,
  2239. 'entity_type' => $entity_type,
  2240. 'bundle' => $bundle->name,
  2241. 'label' => 'Location on Map',
  2242. 'description' => 'The positions on a genetic map.',
  2243. 'required' => FALSE,
  2244. 'settings' => [
  2245. 'auto_attach' => FALSE,
  2246. 'chado_table' => 'featurepos',
  2247. 'chado_column' => $pkey,
  2248. 'base_table' => 'feature',
  2249. 'term_accession' => '0000021',
  2250. 'term_vocabulary' => 'OGI',
  2251. 'term_name' => 'location on map',
  2252. ],
  2253. 'widget' => [
  2254. 'type' => 'ogi__location_on_map_widget',
  2255. 'settings' => [
  2256. 'display_label' => 1,
  2257. ],
  2258. ],
  2259. 'display' => [
  2260. 'default' => [
  2261. 'label' => 'hidden',
  2262. 'type' => 'ogi__location_on_map_formatter',
  2263. 'settings' => [],
  2264. ],
  2265. ],
  2266. ];
  2267. }
  2268. // // GENOTYPE
  2269. // $genotype_table = $table_name . '_genotype';
  2270. // if (chado_table_exists($genotype_table)) {
  2271. // $field_name = 'so__genotype';
  2272. // $schema = chado_get_schema($genotype_table);
  2273. // $pkey = $schema['primary key'][0];
  2274. // $info[$field_name] = array(
  2275. // 'field_name' => $field_name,
  2276. // 'entity_type' => $entity_type,
  2277. // 'bundle' => $bundle->name,
  2278. // 'label' => 'Genotype',
  2279. // 'description' => 'The genotypes associated with this record.',
  2280. // 'required' => FALSE,
  2281. // 'settings' => array(
  2282. // 'auto_attach' => FALSE,
  2283. // 'chado_table' => $genotype_table,
  2284. // 'chado_column' => $pkey,
  2285. // 'base_table' => $table_name,
  2286. // 'term_accession' => '',
  2287. // 'term_vocabulary' => '',
  2288. // 'term_name' => '',
  2289. // ),
  2290. // 'widget' => array(
  2291. // 'type' => 'so__genotype_widget',
  2292. // 'settings' => array(
  2293. // 'display_label' => 1,
  2294. // ),
  2295. // ),
  2296. // 'display' => array(
  2297. // 'default' => array(
  2298. // 'label' => 'hidden',
  2299. // 'type' => 'so__genotype_formatter',
  2300. // 'settings' => array(),
  2301. // ),
  2302. // ),
  2303. // );
  2304. // }
  2305. // // PHENOTYPE
  2306. // $phenotype_table = $table_name . '_phenotype';
  2307. // if (chado_table_exists($phenotype_table)) {
  2308. // $field_name = 'sbo__phenotype';
  2309. // $schema = chado_get_schema($phenotype_table);
  2310. // $pkey = $schema['primary key'][0];
  2311. // $info[$field_name] = array(
  2312. // 'field_name' => $field_name,
  2313. // 'entity_type' => $entity_type,
  2314. // 'bundle' => $bundle->name,
  2315. // 'label' => 'Phenotype',
  2316. // 'description' => 'The phenotypes associated with this record.',
  2317. // 'required' => FALSE,
  2318. // 'settings' => array(
  2319. // 'auto_attach' => FALSE,
  2320. // 'chado_table' => $phenotype_table,
  2321. // 'chado_column' => $pkey,
  2322. // 'base_table' => $table_name,
  2323. // 'term_accession' => '',
  2324. // 'term_vocabulary' => '',
  2325. // 'term_name' => '',
  2326. // ),
  2327. // 'widget' => array(
  2328. // 'type' => 'sbo__phenotype_widget',
  2329. // 'settings' => array(
  2330. // 'display_label' => 1,
  2331. // ),
  2332. // ),
  2333. // 'display' => array(
  2334. // 'default' => array(
  2335. // 'label' => 'hidden',
  2336. // 'type' => 'sbo__phenotype_formatter',
  2337. // 'settings' => array(),
  2338. // ),
  2339. // ),
  2340. // );
  2341. // }
  2342. // PROPERTIES
  2343. $prop_table = $table_name . 'prop';
  2344. if (chado_table_exists($prop_table)) {
  2345. $props = tripal_chado_bundle_get_properties($table_name, $prop_table, $type_table, $type_column, $cvterm_id, $type_value);
  2346. foreach ($props as $term) {
  2347. $field_name = strtolower(preg_replace('/[^\w]/', '_', $term->dbxref_id->db_id->name . '__' . $term->name));
  2348. // The field name can only be 32 chars, but if our name is longer we need
  2349. // to add some random chars to ensure we don't have naming conflicts
  2350. // with other terms (e.g. mitochondrial_genetic_code and
  2351. // mitochondrial_genetic_code_name)
  2352. if (strlen($field_name) >= 32) {
  2353. $field_name = substr($field_name, 0, 20) . '_' . $term->cvterm_id;
  2354. }
  2355. $info[$field_name] = [
  2356. 'field_name' => $field_name,
  2357. 'entity_type' => $entity_type,
  2358. 'bundle' => $bundle->name,
  2359. 'label' => ucwords(preg_replace('/_/', ' ', $term->name)),
  2360. 'description' => $term->definition,
  2361. 'required' => FALSE,
  2362. 'settings' => [
  2363. 'auto_attach' => TRUE,
  2364. 'term_vocabulary' => $term->dbxref_id->db_id->name,
  2365. 'term_accession' => $term->dbxref_id->accession,
  2366. 'term_name' => $term->name,
  2367. 'base_table' => $table_name,
  2368. 'chado_table' => $prop_table,
  2369. 'chado_column' => $pkey,
  2370. ],
  2371. 'widget' => [
  2372. 'type' => 'chado_linker__prop_widget',
  2373. 'settings' => [
  2374. 'display_label' => 1,
  2375. ],
  2376. ],
  2377. 'display' => [
  2378. 'default' => [
  2379. 'label' => 'hidden',
  2380. 'type' => 'chado_linker__prop_formatter',
  2381. 'settings' => [],
  2382. ],
  2383. ],
  2384. ];
  2385. // Make some customizations to some fields
  2386. if ($term->name == 'Citation' and $term->cv_id->name == 'tripal_pub') {
  2387. $info[$field_name]['required'] = TRUE;
  2388. $info[$field_name]['description'] = t('All publications must have a unique citation.
  2389. Please enter the full citation for this publication. For PubMed style citations list
  2390. the last name of the author followed by initials. Each author should be separated by a comma. Next comes
  2391. 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.
  2392. 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
  2393. suffer taxonomic influence?</a> J Ethnopharmacol. 2013 Apr 19; 146(3):842-52.</pre>');
  2394. $info[$field_name]['settings']['rows'] = 3;
  2395. }
  2396. if ($term->name == 'Abstract' and $term->cv_id->name == 'tripal_pub') {
  2397. $info[$field_name]['settings']['rows'] = 5;
  2398. }
  2399. }
  2400. }
  2401. // CVTERMS
  2402. $term_table = $table_name . '_cvterm';
  2403. if (chado_table_exists($term_table)) {
  2404. $schema = chado_get_schema($term_table);
  2405. $pkey = $schema['primary key'][0];
  2406. $lkey = key($schema['foreign keys'][$table_name]['columns']);
  2407. $rkey = $schema['foreign keys'][$table_name]['columns'][$lkey];
  2408. $field_name = 'sio__annotation';
  2409. $info[$field_name] = [
  2410. 'field_name' => $field_name,
  2411. 'entity_type' => $entity_type,
  2412. 'bundle' => $bundle->name,
  2413. 'label' => 'Annotations',
  2414. 'description' => 'Annotations that are associated with this record.',
  2415. 'required' => FALSE,
  2416. 'settings' => [
  2417. 'auto_attach' => FALSE,
  2418. 'chado_table' => $term_table,
  2419. 'chado_column' => $pkey,
  2420. 'base_table' => $table_name,
  2421. 'term_vocabulary' => 'SIO',
  2422. 'term_name' => 'annotation',
  2423. 'term_accession' => '001166',
  2424. ],
  2425. 'widget' => [
  2426. 'type' => 'sio__annotation_widget',
  2427. 'settings' => [
  2428. 'display_label' => 1,
  2429. ],
  2430. ],
  2431. 'display' => [
  2432. 'default' => [
  2433. 'label' => 'hidden',
  2434. 'type' => 'sio__annotation_formatter',
  2435. 'settings' => [],
  2436. ],
  2437. ],
  2438. ];
  2439. }
  2440. // PUBLICATIONS
  2441. $pub_table = $table_name . '_pub';
  2442. if (chado_table_exists($pub_table)) {
  2443. $field_name = 'schema__publication';
  2444. $schema = chado_get_schema($pub_table);
  2445. $pkey = $schema['primary key'][0];
  2446. $info[$field_name] = [
  2447. 'field_name' => $field_name,
  2448. 'entity_type' => $entity_type,
  2449. 'bundle' => $bundle->name,
  2450. 'label' => 'Publication',
  2451. 'description' => 'This record has been referenced or is sourced from these publications.',
  2452. 'required' => FALSE,
  2453. 'settings' => [
  2454. 'auto_attach' => FALSE,
  2455. 'chado_table' => $pub_table,
  2456. 'chado_column' => $pkey,
  2457. 'base_table' => $table_name,
  2458. 'term_accession' => 'publication',
  2459. 'term_vocabulary' => 'schema',
  2460. 'term_name' => 'publication',
  2461. ],
  2462. 'widget' => [
  2463. 'type' => 'schema__publication_widget',
  2464. 'settings' => [
  2465. 'display_label' => 1,
  2466. ],
  2467. ],
  2468. 'display' => [
  2469. 'default' => [
  2470. 'label' => 'hidden',
  2471. 'type' => 'schema__publication_formatter',
  2472. 'settings' => [],
  2473. ],
  2474. ],
  2475. ];
  2476. }
  2477. // PUBLICATIONS (in reverse)
  2478. // We want to be able to show all of the content that a publication links
  2479. // to. The sio__references field does that.
  2480. if ($table_name == 'pub') {
  2481. $field_name = 'sio__references';
  2482. $schema = chado_get_schema($table_name);
  2483. $pkey = $schema['primary key'][0];
  2484. $info[$field_name] = [
  2485. 'field_name' => $field_name,
  2486. 'entity_type' => $entity_type,
  2487. 'bundle' => $bundle->name,
  2488. 'label' => 'References',
  2489. 'description' => 'Records that are referred to by the publication.',
  2490. 'required' => FALSE,
  2491. 'settings' => [
  2492. 'auto_attach' => FALSE,
  2493. 'chado_table' => $table_name,
  2494. 'chado_column' => $pkey,
  2495. 'base_table' => $table_name,
  2496. 'term_accession' => '000631',
  2497. 'term_vocabulary' => 'SIO',
  2498. 'term_name' => 'references',
  2499. ],
  2500. 'widget' => [
  2501. 'type' => 'sio__references_widget',
  2502. 'settings' => [
  2503. 'display_label' => 1,
  2504. ],
  2505. ],
  2506. 'display' => [
  2507. 'default' => [
  2508. 'label' => 'hidden',
  2509. 'type' => 'sio__references_formatter',
  2510. 'settings' => [],
  2511. ],
  2512. ],
  2513. ];
  2514. }
  2515. // RELATIONSHIPS
  2516. // If the linker table does not exists then we don't want to add attach.
  2517. $rel_table = $table_name . '_relationship';
  2518. if (chado_table_exists($rel_table)) {
  2519. $field_name = 'sbo__relationship';
  2520. $schema = chado_get_schema($rel_table);
  2521. $pkey = $schema['primary key'][0];
  2522. $info[$field_name] = [
  2523. 'field_name' => $field_name,
  2524. 'entity_type' => $entity_type,
  2525. 'bundle' => $bundle->name,
  2526. 'label' => 'Relationship',
  2527. 'description' => 'Other records with relationships to this record.',
  2528. 'required' => FALSE,
  2529. 'settings' => [
  2530. 'auto_attach' => FALSE,
  2531. 'chado_table' => $rel_table,
  2532. 'chado_column' => $pkey,
  2533. 'base_table' => $table_name,
  2534. 'term_vocabulary' => 'SBO',
  2535. 'term_name' => 'Relationship',
  2536. 'term_accession' => '0000374',
  2537. ],
  2538. 'widget' => [
  2539. 'type' => 'sbo__relationship_widget',
  2540. 'settings' => [
  2541. 'display_label' => 1,
  2542. ],
  2543. ],
  2544. 'display' => [
  2545. 'default' => [
  2546. 'label' => 'hidden',
  2547. 'type' => 'sbo__relationship_formatter',
  2548. 'settings' => [
  2549. 'title' => 'Relationships',
  2550. 'empty' => 'There are no relationships',
  2551. ],
  2552. ],
  2553. ],
  2554. ];
  2555. }
  2556. return;
  2557. // SYNONYMS
  2558. $syn_table = $table_name . '_synonym';
  2559. if (chado_table_exists($syn_table)) {
  2560. $field_name = 'schema__alternate_name';
  2561. $schema = chado_get_schema($syn_table);
  2562. $pkey = $schema['primary key'][0];
  2563. $info[$field_name] = [
  2564. 'field_name' => $field_name,
  2565. 'entity_type' => $entity_type,
  2566. 'bundle' => $bundle->name,
  2567. 'label' => 'Synonyms',
  2568. 'description' => 'Alternate names, aliases or synonyms for this record.',
  2569. 'required' => FALSE,
  2570. 'settings' => [
  2571. 'auto_attach' => FALSE,
  2572. 'chado_table' => $syn_table,
  2573. 'chado_column' => $pkey,
  2574. 'base_table' => $table_name,
  2575. 'term_accession' => 'alternateName',
  2576. 'term_vocabulary' => 'schema',
  2577. 'term_name' => 'alternateName',
  2578. ],
  2579. 'widget' => [
  2580. 'type' => 'schema__alternate_name_widget',
  2581. 'settings' => [
  2582. 'display_label' => 1,
  2583. ],
  2584. ],
  2585. 'display' => [
  2586. 'default' => [
  2587. 'label' => 'hidden',
  2588. 'type' => 'schema__alternate_name_formatter',
  2589. 'settings' => [],
  2590. ],
  2591. ],
  2592. ];
  2593. }
  2594. }
  2595. /**
  2596. * Used to find all of the properties for a given table.
  2597. *
  2598. * @param $table_name
  2599. * The name of the base table.
  2600. * @param unknown $prop_table
  2601. * The name of the property table.
  2602. * @param $type_table
  2603. * The name of the table that contains the type specifier.
  2604. * @param $type_column
  2605. * The name of the column that contains the type specifier.
  2606. *
  2607. * @return
  2608. * An array of cvterm objects for the properties to be added as fields.
  2609. */
  2610. function tripal_chado_bundle_get_properties($table_name, $prop_table, $type_table, $type_column, $cvterm_id, $type_value) {
  2611. $tschema = chado_get_schema($table_name);
  2612. $schema = chado_get_schema($prop_table);
  2613. $tpkey = $tschema['primary key'][0];
  2614. $pkey = $schema['primary key'][0];
  2615. $props = NULL;
  2616. // Property tables can be a bit tricky because not all property types
  2617. // in the prop table are appropriate for each type of data. Also som
  2618. // bundle types are resolved via a property. So, we have to distinguish
  2619. // between these two cases.
  2620. $sql = '';
  2621. $args = [];
  2622. // First, If this is the case where the base table is 'cvterm' then we are wanting
  2623. // to get properties from the cvterm table using the cv_id as the
  2624. // differentiator.
  2625. if ($prop_table == 'cvtermprop') {
  2626. $sql = "
  2627. SELECT DISTINCT P.type_id
  2628. FROM {" . db_escape_table($prop_table) . "} P
  2629. INNER JOIN {" . db_escape_table($table_name) . "} T on T.$tpkey = P.$tpkey
  2630. WHERE T.cv_id = :cv_id
  2631. ";
  2632. $args[':cv_id'] = $type_value;
  2633. $props = chado_query($sql, $args);
  2634. }
  2635. // Second, is this the case where all of the records in the table are
  2636. // of this type? If so, then all properties apply
  2637. else {
  2638. if (!$type_column) {
  2639. $sql = 'SELECT DISTINCT type_id FROM {' . db_escape_table($prop_table) . '}';
  2640. $props = chado_query($sql, $args);
  2641. }
  2642. // Third, if this is the case where a content type is uniquely identified
  2643. // by a type_id value in the base table, then only properties associated
  2644. // with that type ID should be used.
  2645. else {
  2646. if ($type_column and !$type_table) {
  2647. $sql = "
  2648. SELECT DISTINCT P.type_id
  2649. FROM {" . db_escape_table($prop_table) . "} P
  2650. INNER JOIN {" . db_escape_table($table_name) . "} T on T.$tpkey = P.$tpkey
  2651. WHERE T.$type_column = :cvterm_id
  2652. ";
  2653. $args[':cvterm_id'] = $cvterm_id;
  2654. $props = chado_query($sql, $args);
  2655. }
  2656. // Fourth, if this is the case where a content type is uniquely identified
  2657. // via a term/value pair in the prop table.
  2658. else {
  2659. if ($type_column and $type_table == $prop_table and !empty($type_value)) {
  2660. $sql = "
  2661. SELECT DISTINCT P2.type_id
  2662. FROM {" . db_escape_table($prop_table) . "} P1
  2663. INNER JOIN {" . db_escape_table($table_name) . "} T on T.$tpkey = P1.$tpkey
  2664. INNER JOIN {" . db_escape_table($prop_table) . "} P2 on T.$tpkey = P2.$tpkey
  2665. WHERE P1.$type_column = :cvterm_id AND P1.value = :prop_value AND
  2666. P2.type_id != P1.type_id
  2667. ";
  2668. $args[':cvterm_id'] = $cvterm_id;
  2669. $args[':prop_value'] = $type_value;
  2670. $props = chado_query($sql, $args);
  2671. }
  2672. // Fifth, if this is the case where the content type is uniquely identified
  2673. // via another table (e.g. cvterm linking table) and not this prop table.
  2674. else {
  2675. if ($type_column and $type_table != $prop_table and empty($type_value)) {
  2676. $sql = "
  2677. SELECT DISTINCT P.type_id
  2678. FROM {" . db_escape_table($prop_table) . "} P
  2679. INNER JOIN {" . db_escape_table($table_name) . "} T on T.$tpkey = P.$tpkey
  2680. INNER JOIN {" . db_escape_table($type_table) . "} TT on TT.$tpkey = T.$tpkey
  2681. WHERE TT.$type_column = :cvterm_id
  2682. ";
  2683. $args[':cvterm_id'] = $cvterm_id;
  2684. $props = chado_query($sql, $args);
  2685. }
  2686. }
  2687. }
  2688. }
  2689. }
  2690. if (!$props) {
  2691. return [];
  2692. }
  2693. // Iterate through all of the properties and do some final checks to see
  2694. // which ones should be added.
  2695. $prop_arr = [];
  2696. if (!$props) {
  2697. return $prop_arr;
  2698. }
  2699. while ($prop = $props->fetchObject()) {
  2700. $term = chado_generate_var('cvterm', ['cvterm_id' => $prop->type_id]);
  2701. $term = chado_expand_var($term, 'field', 'cvterm.definition');
  2702. // The tripal_analysis_KEGG, tripal_analysis_blast, and
  2703. // tripal_analysis_interpro modules store results in the analysisprop
  2704. // table which is probably not the best place, but we don't want to
  2705. // create a ton of fields for this.
  2706. if ($prop_table == 'analysisprop' and
  2707. ($term->dbxref_id->db_id->name == 'KEGG_BRITE' or
  2708. $term->dbxref_id->db_id->name == 'tripal')) {
  2709. continue;
  2710. }
  2711. // The Tripal publication importer adds properties to publications that
  2712. // are also represented in the table fields. We want editing of pub
  2713. // related fields to always go back to the pub table, so we do not
  2714. // want prop fields to show up.
  2715. if ($table_name == 'pub') {
  2716. $skip_pub_property = FALSE;
  2717. $pub_terms = chado_get_semweb_terms('pub', ['return_object' => TRUE]);
  2718. foreach ($pub_terms as $pub_column => $mapped_term) {
  2719. $term_accession = $term->dbxref_id->db_id->name . ':' . $term->dbxref_id->accession;
  2720. $mapped_accession = $mapped_term->dbxref_id->db_id->name . ':' . $mapped_term->dbxref_id->accession;
  2721. if ($term_accession == $mapped_accession) {
  2722. $skip_pub_property = TRUE;
  2723. }
  2724. }
  2725. if ($skip_pub_property) {
  2726. continue;
  2727. }
  2728. }
  2729. // Add the term to our list!
  2730. $prop_arr[] = $term;
  2731. }
  2732. return $prop_arr;
  2733. }
  2734. /**
  2735. * Implements hook_bundle_create_user_field().
  2736. *
  2737. * A priviledged user has the ability to add new fields to the bundle. The
  2738. * chado_linker__prop and chado_linker__cvterm fields are allowed to be
  2739. * added dynamically by the user. But, Drupal doesn't know how to deal with
  2740. * it, so this function is called for any field attached to a TripalEntity
  2741. * bundle type. Any fields whose TripalField::$module argument is set to
  2742. * 'tripal_chado' and that can be added dynamically will result in a call
  2743. * to this function.
  2744. */
  2745. function tripal_chado_bundle_create_user_field($new_field, $bundle) {
  2746. // Get the table this bundle is mapped to.
  2747. $term = tripal_load_term_entity(['term_id' => $bundle->term_id]);
  2748. $vocab = $term->vocab;
  2749. $params = [
  2750. 'vocabulary' => $vocab->vocabulary,
  2751. 'accession' => $term->accession,
  2752. ];
  2753. $chado_table = $bundle->data_table;
  2754. $chado_type_table = $bundle->type_linker_table;
  2755. $chado_type_column = $bundle->type_column;
  2756. $chado_type_id = $bundle->type_id;
  2757. $chado_type_value = $bundle->type_value;
  2758. // We allow site admins to add new chado_linker__prop fields to an entity.
  2759. // This function will allow us to properly add them. But at this point we
  2760. // don't know the controlled vocabulary term. We'll have to use the
  2761. // defaults and let the user set it using the interface.
  2762. if ($new_field['type'] == 'chado_linker__prop') {
  2763. $table_name = $chado_table . 'prop';
  2764. if (chado_table_exists($table_name)) {
  2765. $schema = chado_get_schema($table_name);
  2766. $pkey = $schema['primary key'][0];
  2767. $field_name = $new_field['field_name'];
  2768. $field_type = 'chado_linker__prop';
  2769. // First add the field.
  2770. field_create_field([
  2771. 'field_name' => $field_name,
  2772. 'type' => $field_type,
  2773. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  2774. 'locked' => FALSE,
  2775. 'storage' => [
  2776. 'type' => 'field_chado_storage',
  2777. ],
  2778. ]);
  2779. // Now add the instance
  2780. field_create_instance([
  2781. 'field_name' => $field_name,
  2782. 'entity_type' => 'TripalEntity',
  2783. 'bundle' => $bundle->name,
  2784. 'label' => $new_field['label'],
  2785. 'description' => '',
  2786. 'required' => FALSE,
  2787. 'settings' => [
  2788. 'auto_attach' => TRUE,
  2789. 'base_table' => $chado_table,
  2790. 'chado_table' => $table_name,
  2791. 'chado_column' => $pkey,
  2792. 'term_vocabulary' => '',
  2793. 'term_accession' => '',
  2794. 'term_name' => '',
  2795. ],
  2796. 'widget' => [
  2797. 'type' => 'chado_linker__prop_widget',
  2798. 'settings' => [
  2799. 'display_label' => 1,
  2800. ],
  2801. ],
  2802. 'display' => [
  2803. 'default' => [
  2804. 'label' => 'inline',
  2805. 'type' => 'chado_linker__prop_formatter',
  2806. 'settings' => [],
  2807. ],
  2808. ],
  2809. ]);
  2810. }
  2811. else {
  2812. drupal_set_message('Cannot add a property field to this entity. Chado does not support properties for this data type.', 'error');
  2813. }
  2814. }
  2815. // We allow site admins to add new chado_linker__cvterm fields to an entity.
  2816. // This function will allow us to properly add them. But at this point we
  2817. // don't know the controlled vocabulary term. We'll have to use the
  2818. // defaults and let the user set it using the interface.
  2819. if ($new_field['type'] == 'chado_linker__cvterm') {
  2820. $table_name = $chado_table . '_cvterm';
  2821. if (chado_table_exists($table_name)) {
  2822. $schema = chado_get_schema($table_name);
  2823. $pkey = $schema['primary key'][0];
  2824. $field_name = $new_field['field_name'];
  2825. $field_type = 'chado_linker__cvterm';
  2826. // First add the field.
  2827. field_create_field([
  2828. 'field_name' => $field_name,
  2829. 'type' => $field_type,
  2830. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  2831. 'locked' => FALSE,
  2832. 'storage' => [
  2833. 'type' => 'field_chado_storage',
  2834. ],
  2835. 'settings' => [
  2836. 'base_table' => $chado_table,
  2837. 'chado_table' => $table_name,
  2838. 'chado_column' => $pkey,
  2839. ],
  2840. ]);
  2841. // Now add the instance
  2842. field_create_instance([
  2843. 'field_name' => $field_name,
  2844. 'entity_type' => 'TripalEntity',
  2845. 'bundle' => $bundle->name,
  2846. 'label' => $new_field['label'],
  2847. 'description' => '',
  2848. 'required' => FALSE,
  2849. 'settings' => [
  2850. 'auto_attach' => TRUE,
  2851. ],
  2852. 'widget' => [
  2853. 'type' => 'chado_linker__cvterm_widget',
  2854. 'settings' => [
  2855. 'display_label' => 1,
  2856. ],
  2857. ],
  2858. 'display' => [
  2859. 'default' => [
  2860. 'label' => 'above',
  2861. 'type' => 'chado_linker__cvterm_formatter',
  2862. 'settings' => [],
  2863. ],
  2864. ],
  2865. ]);
  2866. }
  2867. else {
  2868. drupal_set_message('Cannot add a property field to this entity. Chado does not support annotations for this data type.', 'error');
  2869. }
  2870. }
  2871. }
  2872. /**
  2873. * Allows for altering of a field's instance setting form.
  2874. *
  2875. * This appears to be a Drupal hook but is actually a custom function created
  2876. * by this module. It is called by the tripal_form_alter() function of this
  2877. * module.
  2878. *
  2879. * Here we put additional form elements for any field, regardless if it is
  2880. * a tripalField or not.
  2881. *
  2882. * @param $form
  2883. * The form array. Alterations to the form can be made within this array.
  2884. * @param $form_state
  2885. * The form state array.
  2886. */
  2887. function tripal_chado_field_instance_settings_form_alter(&$form, $form_state) {
  2888. global $language;
  2889. $field = $form['#field'];
  2890. $instance = $form['#instance'];
  2891. $base_table = array_key_exists('base_table', $instance['settings']) ? $instance['settings']['base_table'] : '';
  2892. $chado_table = array_key_exists('chado_table', $instance['settings']) ? $instance['settings']['chado_table'] : '';
  2893. $chado_column = array_key_exists('chado_column', $instance['settings']) ? $instance['settings']['chado_column'] : '';
  2894. if ($chado_table) {
  2895. // Construct a table for the vocabulary information.
  2896. $headers = [];
  2897. $rows = [];
  2898. $rows[] = [
  2899. [
  2900. 'data' => 'Base Table',
  2901. 'header' => TRUE,
  2902. 'width' => '20%',
  2903. ],
  2904. $base_table,
  2905. ];
  2906. $rows[] = [
  2907. [
  2908. 'data' => 'Record Table',
  2909. 'header' => TRUE,
  2910. 'width' => '20%',
  2911. ],
  2912. $chado_table,
  2913. ];
  2914. $rows[] = [
  2915. [
  2916. 'data' => 'ID Column',
  2917. 'header' => TRUE,
  2918. 'width' => '20%',
  2919. ],
  2920. $chado_column,
  2921. ];
  2922. $table = [
  2923. 'header' => $headers,
  2924. 'rows' => $rows,
  2925. 'attributes' => [
  2926. ],
  2927. 'sticky' => FALSE,
  2928. 'caption' => '',
  2929. 'colgroups' => [],
  2930. 'empty' => '',
  2931. ];
  2932. $form['chado_mapping'] = [
  2933. '#type' => 'fieldset',
  2934. '#title' => 'Chado Mapping',
  2935. '#description' => t('This field maps to data in Chado to the following table:'),
  2936. ];
  2937. $form['chado_mapping']['details'] = [
  2938. '#type' => 'item',
  2939. '#markup' => theme_table($table),
  2940. ];
  2941. }
  2942. }
  2943. /**
  2944. * Implements hook_form_FROM_ID_alter()
  2945. */
  2946. function tripal_chado_form_tripalbundle_form_alter(&$form, $form_state) {
  2947. global $language;
  2948. $bundle = $form['#bundle'];
  2949. $term = entity_load('TripalTerm', ['id' => $bundle->term_id]);
  2950. $term = reset($term);
  2951. $vocab = $term->vocab;
  2952. $params = [
  2953. 'vocabulary' => $vocab->vocabulary,
  2954. 'accession' => $term->accession,
  2955. ];
  2956. $chado_table = $bundle->data_table;
  2957. $chado_column = $bundle->type_column;
  2958. $chado_type_table = $bundle->type_linker_table;
  2959. $chado_type_id = $bundle->type_id;
  2960. $chado_type_value = $bundle->type_value;
  2961. // Construct a table for the vocabulary information.
  2962. $headers = [];
  2963. $rows = [];
  2964. $rows[] = [
  2965. [
  2966. 'data' => 'Chado Table',
  2967. 'header' => TRUE,
  2968. 'width' => '20%',
  2969. ],
  2970. $chado_table,
  2971. ];
  2972. if ($chado_column) {
  2973. $rows[] = [
  2974. [
  2975. 'data' => 'Type Column',
  2976. 'header' => TRUE,
  2977. 'width' => '20%',
  2978. ],
  2979. $chado_column,
  2980. ];
  2981. }
  2982. if ($chado_type_table) {
  2983. $rows[] = [
  2984. [
  2985. 'data' => 'Association Table',
  2986. 'header' => TRUE,
  2987. 'width' => '20%',
  2988. ],
  2989. $chado_type_table,
  2990. ];
  2991. }
  2992. if ($chado_type_table and $chado_type_id) {
  2993. $rows[] = [
  2994. [
  2995. 'data' => 'CVTerm Table ID',
  2996. 'header' => TRUE,
  2997. 'width' => '20%',
  2998. ],
  2999. $chado_type_id,
  3000. ];
  3001. }
  3002. if ($chado_type_value) {
  3003. $rows[] = [
  3004. [
  3005. 'data' => 'Property Value',
  3006. 'header' => TRUE,
  3007. 'width' => '20%',
  3008. ],
  3009. $chado_type_value,
  3010. ];
  3011. }
  3012. $table = [
  3013. 'header' => $headers,
  3014. 'rows' => $rows,
  3015. 'attributes' => [
  3016. ],
  3017. 'sticky' => FALSE,
  3018. 'caption' => '',
  3019. 'colgroups' => [],
  3020. 'empty' => '',
  3021. ];
  3022. $form['chado_mapping'] = [
  3023. '#type' => 'item',
  3024. '#title' => 'Chado Mapping',
  3025. '#markup' => theme_table($table),
  3026. '#description' => t('This content type maps to the table in Chado
  3027. listed above. Chado allows multiple data types to be housed
  3028. in a single table. Therefore, the column that is used to
  3029. differentiate between data types is also listed above.'),
  3030. '#weight' => 0,
  3031. ];
  3032. }
  3033. /**
  3034. * Implements hook_field_views_data_alter();
  3035. */
  3036. function tripal_chado_field_views_data_alter(&$result, $field) {
  3037. // This module creates the data__image field for managing images on
  3038. // bio_data content types. But we want it to render correctly
  3039. // so we need to set some handlers.
  3040. if ($field['field_name'] == 'data__image') {
  3041. foreach ($result as $key => $fields) {
  3042. // It's not clear how to identify our bundle types, but they do have
  3043. // a double underscore in their name to separate the vocabulary from
  3044. // the accession, so we'll use that to find them.
  3045. if (preg_match('/__/', $key)) {
  3046. $result[$key]['data__image']['field']['handler'] = 'tripal_views_handler_field_image';
  3047. }
  3048. }
  3049. }
  3050. }