tripal_chado.fields.inc 101 KB

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