tripal_chado.fields.inc 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505
  1. <?php
  2. function tripal_chado_field_widget_info() {
  3. return array(
  4. 'chado_base_dbxref_id' => array(
  5. 'label' => 'Site specific Accession',
  6. 'field types' => array('tripal_key_value'),
  7. ),
  8. 'chado_base_organism_id' => array(
  9. 'label' => 'Organism',
  10. 'field types' => array('tripal_key_value')
  11. ),
  12. 'chado_feature_md5checsum' => array(
  13. 'label' => 'Sequence Checksum',
  14. 'field types' => array('tripal_key_value')
  15. ),
  16. 'chado_feature_residues' => array(
  17. 'label' => 'Sequence',
  18. 'field types' => array('tripal_key_value')
  19. ),
  20. 'chado_feature_seqlen' => array(
  21. 'label' => 'Sequence Length',
  22. 'field types' => array('tripal_key_value')
  23. ),
  24. 'chado_gene_transcripts' => array(
  25. 'label' => 'Transcripts',
  26. 'field types' => array('tripal_key_value')
  27. ),
  28. 'chado_linker_contact' => array(
  29. 'label' => 'Contacts',
  30. 'field types' => array('tripal_key_value')
  31. ),
  32. 'chado_linker_dbxref' => array(
  33. 'label' => 'Cross References',
  34. 'field types' => array('tripal_key_value')
  35. ),
  36. 'chado_linker_expression' => array(
  37. 'label' => 'Expression',
  38. 'field types' => array('tripal_key_value')
  39. ),
  40. 'chado_linker_featureloc' => array(
  41. 'label' => 'Positions',
  42. 'field types' => array('tripal_key_value')
  43. ),
  44. );
  45. }
  46. /**
  47. * Implements hook_field_create_info().
  48. *
  49. * This is a Tripal defined hook that supports integration with the
  50. * TripalEntity field.
  51. */
  52. function tripal_chado_create_tripalfields2($entity_type, $bundle) {
  53. // Get the table this bundle is mapped to.
  54. $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
  55. $vocab = $term->vocab;
  56. $params = array(
  57. 'vocabulary' => $vocab->vocabulary,
  58. 'accession' => $term->accession,
  59. );
  60. $mapped_table = chado_get_cvterm_mapping($params);
  61. // Get the details about the mapping of this bundle to the Chado table:
  62. $details = array(
  63. 'chado_cv_id' => $mapped_table->cvterm->cv_id->cv_id,
  64. 'chado_cvterm_id' => $mapped_table->cvterm->cvterm_id,
  65. 'chado_table' => $mapped_table->chado_table,
  66. 'chado_type_table' => $mapped_table->chado_table,
  67. 'chado_type_column' => $mapped_table->chado_field,
  68. );
  69. $info = array();
  70. // Create the fields for each column in the table.
  71. tripal_chado_create_tripalfields_base($info, $details, $entity_type, $bundle);
  72. // Create custom fields.
  73. tripal_chado_create_tripalfields_custom($info, $details, $entity_type, $bundle);
  74. // Create fields for linking tables.
  75. tripal_chado_create_tripalfields_linker($info, $details, $entity_type, $bundle);
  76. return $info;
  77. }
  78. /**
  79. *
  80. * @param unknown $details
  81. */
  82. function tripal_chado_create_tripalfields_base(&$info, $details, $entity_type, $bundle) {
  83. $table_name = $details['chado_table'];
  84. $type_table = $details['chado_type_table'];
  85. $type_field = $details['chado_type_column'];
  86. $cv_id = $details['chado_cv_id'];
  87. $cvterm_id = $details['chado_cvterm_id'];
  88. // Iterate through the columns of the table and see if fields have been
  89. // created for each one. If not, then create them.
  90. $schema = chado_get_schema($table_name);
  91. if (!$schema) {
  92. return;
  93. }
  94. // Get the list of columns for this table and create a new field for each one.
  95. $columns = $schema['fields'];
  96. foreach ($columns as $column_name => $details) {
  97. $field_name = $table_name . '__' . $column_name;
  98. // Skip fields with a custom field:
  99. if ($field_name == 'dbxref_id' or $field_name == 'organism_id') {
  100. continue;
  101. }
  102. if ($table_name == 'feature' and ($field_name == 'md5checksum' or
  103. $field_name == 'residues' or $field_name == 'seqlen')) {
  104. continue;
  105. }
  106. if ($table_name == 'organism' and ($field_name == 'type_id')) {
  107. continue;
  108. }
  109. // Skip the primary key field.
  110. if ($column_name == $schema['primary key'][0]) {
  111. continue;
  112. }
  113. // Skip the type field.
  114. if ($table_name == $type_table and $column_name == $type_field) {
  115. continue;
  116. }
  117. // Set some defaults for the field.
  118. $base_info = array(
  119. 'field_name' => $field_name,
  120. 'type' => '',
  121. 'cardinality' => 1,
  122. 'locked' => FALSE,
  123. 'storage' => array(
  124. 'type' => 'field_chado_storage',
  125. ),
  126. 'settings' => array(
  127. 'chado_table' => $table_name,
  128. 'chado_column' => $column_name,
  129. 'semantic_web' => tripal_get_chado_semweb_term($table_name, $column_name),
  130. ),
  131. );
  132. // Alter the field info array depending on the column details.
  133. switch($details['type']) {
  134. case 'char':
  135. $base_info['type'] = 'text';
  136. $base_info['settings']['max_length'] = $details['length'];
  137. break;
  138. case 'varchar':
  139. $base_info['type'] = 'text';
  140. $base_info['settings']['max_length'] = $details['length'];
  141. break;
  142. case 'text':
  143. $base_info['type'] = 'text';
  144. $base_info['settings']['max_length'] = 17179869184;
  145. $base_info['settings']['text_processing'] = 1;
  146. break;
  147. case 'blob':
  148. // not sure how to support a blob field.
  149. continue;
  150. break;
  151. case 'int':
  152. $base_info['type'] = 'number_integer';
  153. break;
  154. case 'float':
  155. $base_info['type'] = 'number_float';
  156. $base_info['settings']['precision'] = 10;
  157. $base_info['settings']['scale'] = 2;
  158. $base_info['settings']['decimal_separator'] = '.';
  159. break;
  160. case 'numeric':
  161. $base_info['type'] = 'number_decimal';
  162. break;
  163. case 'serial':
  164. // Serial fields are most likely not needed as a field.
  165. break;
  166. case 'boolean':
  167. $base_info['type'] = 'list_boolean';
  168. $base_info['settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
  169. break;
  170. case 'datetime':
  171. // Use the Drupal Date and Date API to create the field/widget
  172. $base_info['type'] = 'datetime';
  173. break;
  174. }
  175. // Set some default semantic web information
  176. if ($column_name == 'uniquename') {
  177. $base_info['settings']['text_processing'] = 0;
  178. }
  179. //
  180. // PUB TABLE
  181. //
  182. elseif ($table_name == 'pub' and $column_name == 'uniquename') {
  183. $base_info['type'] = 'text';
  184. $base_info['settings']['text_processing'] = 0;
  185. }
  186. //
  187. // ANALYSIS TABLE
  188. //
  189. elseif ($table_name == 'analysis' and $column_name == 'sourceuri') {
  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_create_tripalfields_custom(&$info, $details, $entity_type, $bundle) {
  201. $table_name = $details['chado_table'];
  202. $type_table = $details['chado_type_table'];
  203. $type_field = $details['chado_type_column'];
  204. $cv_id = $details['chado_cv_id'];
  205. $cvterm_id = $details['chado_cvterm_id'];
  206. $schema = chado_get_schema($table_name);
  207. // BASE DBXREF
  208. if (array_key_exists('dbxref_id', $schema['fields'])) {
  209. $field_name = $table_name . '__dbxref_id';
  210. $field_type = 'chado_base__dbxref_id';
  211. $info[$field_name] = array(
  212. 'field_name' => $field_name,
  213. 'type' => $field_type,
  214. 'cardinality' => 1,
  215. 'locked' => FALSE,
  216. 'storage' => array(
  217. 'type' => 'field_chado_storage',
  218. ),
  219. 'settings' => array(
  220. 'chado_table' => $table_name,
  221. 'chado_column' => 'dbxref_id',
  222. 'semantic_web' => tripal_get_chado_semweb_term($table_name, 'dbxref_id'),
  223. ),
  224. );
  225. }
  226. // BASE ORGANISM_ID
  227. if ($table_name != 'organism' and array_key_exists('organism_id', $schema['fields'])) {
  228. $field_name = $table_name . '__organism_id';
  229. $field_type = 'chado_base__organism_id';
  230. $info[$field_name] = array(
  231. 'field_name' => $field_name,
  232. 'type' => $field_type,
  233. 'cardinality' => 1,
  234. 'locked' => FALSE,
  235. 'storage' => array(
  236. 'type' => 'field_chado_storage',
  237. ),
  238. 'settings' => array(
  239. 'chado_table' => $table_name,
  240. 'chado_column' => 'organism_id',
  241. 'semantic_web' => tripal_get_chado_semweb_term($table_name, 'organism_id'),
  242. ),
  243. );
  244. }
  245. // FEATURE MD5CHECKSUM
  246. if ($table_name == 'feature') {
  247. $field_name = $table_name . '__md5checksum';
  248. $field_type = 'chado_feature__md5checksum';
  249. $info[$field_name] = array(
  250. 'field_name' => $field_name,
  251. 'type' => $field_type,
  252. 'cardinality' => 1,
  253. 'locked' => FALSE,
  254. 'storage' => array(
  255. 'type' => 'field_chado_storage',
  256. ),
  257. 'settings' => array(
  258. 'chado_table' => $table_name,
  259. 'chado_column' => 'md5checksum',
  260. 'semantic_web' => tripal_get_chado_semweb_term($table_name, 'md5checksum'),
  261. ),
  262. );
  263. }
  264. // FEATURE RESIDUES
  265. if ($table_name == 'feature') {
  266. $field_name = 'feature__residues';
  267. $field_type = 'chado_feature__residues';
  268. $info[$field_name] = array(
  269. 'field_name' => $field_name,
  270. 'type' => $field_type,
  271. 'cardinality' => 1,
  272. 'locked' => FALSE,
  273. 'storage' => array(
  274. 'type' => 'field_chado_storage',
  275. ),
  276. 'settings' => array(
  277. 'chado_table' => $table_name,
  278. 'chado_column' => 'residues',
  279. 'semantic_web' => tripal_get_chado_semweb_term($table_name, 'residues'),
  280. ),
  281. );
  282. }
  283. // FEATURE SEQLEN
  284. if ($table_name == 'feature') {
  285. $field_name = 'feature__seqlen';
  286. $field_type = 'chado_feature__seqlen';
  287. $info[$field_name] = array(
  288. 'field_name' => $field_name,
  289. 'type' => $field_type,
  290. 'cardinality' => 1,
  291. 'locked' => FALSE,
  292. 'storage' => array(
  293. 'type' => 'field_chado_storage',
  294. ),
  295. 'settings' => array(
  296. 'chado_table' => $table_name,
  297. 'chado_column' => 'seqlen',
  298. 'semantic_web' => tripal_get_chado_semweb_term($table_name, 'seqlen'),
  299. ),
  300. );
  301. }
  302. // GENE TRANSCRIPTS
  303. $rel_table = $table_name . '_relationship';
  304. if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
  305. $field_name = 'gene_transcripts';
  306. $field_type = 'chado_gene__transcripts';
  307. $info[$field_name] = array(
  308. 'field_name' => $field_name,
  309. 'type' => $field_type,
  310. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  311. 'locked' => FALSE,
  312. 'storage' => array(
  313. 'type' => 'field_chado_storage',
  314. ),
  315. 'settings' => array(
  316. 'chado_table' => $rel_table,
  317. 'chado_column' => 'md5checksum',
  318. 'base_table' => $table_name,
  319. 'semantic_web' => 'SO:0000673',
  320. ),
  321. );
  322. }
  323. // ORGANISM TYPE_ID
  324. if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
  325. $field_name = 'organism__type_id';
  326. $field_type = 'chado_organism__type_id';
  327. $info[$field_name] = array(
  328. 'field_name' => $field_name,
  329. 'type' => $field_type,
  330. 'cardinality' => 1,
  331. 'locked' => FALSE,
  332. 'storage' => array(
  333. 'type' => 'field_chado_storage',
  334. ),
  335. 'settings' => array(
  336. 'chado_table' => 'organism',
  337. 'chado_column' => 'type_id',
  338. 'semantic_web' => tripal_get_chado_semweb_term('organism', 'type_id'),
  339. ),
  340. );
  341. }
  342. }
  343. /**
  344. *
  345. * @param unknown $details
  346. */
  347. function tripal_chado_create_tripalfields_linker(&$info, $details, $entity_type, $bundle) {
  348. $table_name = $details['chado_table'];
  349. $type_table = $details['chado_type_table'];
  350. $type_field = $details['chado_type_column'];
  351. $cv_id = $details['chado_cv_id'];
  352. $cvterm_id = $details['chado_cvterm_id'];
  353. // CONTACTS
  354. $contact_table = $table_name . '_contact';
  355. if (chado_table_exists($contact_table)) {
  356. $schema = chado_get_schema($contact_table);
  357. $pkey = $schema['primary key'][0];
  358. $field_name = $table_name . '_contact';
  359. $field_type = 'chado_linker__contact';
  360. $info[$field_name] = array(
  361. 'field_name' => $field_name,
  362. 'type' => $field_type,
  363. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  364. 'locked' => FALSE,
  365. 'storage' => array(
  366. 'type' => 'field_chado_storage',
  367. ),
  368. 'settings' => array(
  369. 'chado_table' => $contact_table,
  370. 'chado_column' => 'contact_id',
  371. 'base_table' => $table_name,
  372. 'semantic_web' => 'local:contact'
  373. ),
  374. );
  375. }
  376. // CVTERM
  377. $cvterm_table = $table_name . '_cvterm';
  378. if (chado_table_exists($cvterm_table)) {
  379. $field_name = $table_name . '_cvterm';
  380. $field_type = 'chado_linker__cvterm_adder';
  381. $info[$field_name] = array(
  382. 'field_name' => $field_name,
  383. 'type' => $field_type,
  384. 'cardinality' => 1,
  385. 'locked' => FALSE,
  386. 'storage' => array(
  387. 'type' => 'field_chado_storage',
  388. ),
  389. 'settings' => array(
  390. ),
  391. );
  392. }
  393. // DBXREF
  394. $dbxref_table = $table_name . '_dbxref';
  395. if (chado_table_exists($dbxref_table)) {
  396. $dbxref_table = $table_name . '_dbxref';
  397. $schema = chado_get_schema($dbxref_table);
  398. $pkey = $schema['primary key'][0];
  399. $field_name = $table_name . '_dbxref';
  400. $field_type = 'chado_linker__dbxref';
  401. $info[$field_name] = array(
  402. 'field_name' => $field_name,
  403. 'type' => $field_type,
  404. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  405. 'locked' => FALSE,
  406. 'storage' => array(
  407. 'type' => 'field_chado_storage',
  408. ),
  409. 'settings' => array(
  410. 'chado_table' => $dbxref_table,
  411. 'chado_column' => $pkey,
  412. 'base_table' => $table_name,
  413. 'semantic_web' => 'SBO:0000554',
  414. ),
  415. );
  416. }
  417. // EXPRESSION
  418. $expression_table = $table_name . '_expression';
  419. if (chado_table_exists($expression_table)) {
  420. $schema = chado_get_schema($expression_table);
  421. $pkey = $schema['primary key'][0];
  422. $field_name = $table_name . '_expression';
  423. $field_type = 'chado_linker__expression';
  424. $info[$field_name] = array(
  425. 'field_name' => $field_name,
  426. 'type' => $field_type,
  427. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  428. 'locked' => FALSE,
  429. 'storage' => array(
  430. 'type' => 'field_chado_storage',
  431. ),
  432. 'settings' => array(
  433. 'chado_table' => $expression_table,
  434. 'chado_column' => $pkey,
  435. 'base_table' => $table_name,
  436. 'semantic_web' => 'local:expression',
  437. ),
  438. );
  439. }
  440. // FEATURELOC
  441. if ($table_name == 'feature') {
  442. $schema = chado_get_schema('featureloc');
  443. $pkey = $schema['primary key'][0];
  444. $field_name = 'featureloc';
  445. $field_type = 'chado_linker__featureloc';
  446. $info[$field_name] = array(
  447. 'field_name' => $field_name,
  448. 'type' => $field_type,
  449. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  450. 'locked' => FALSE,
  451. 'storage' => array(
  452. 'type' => 'field_chado_storage',
  453. ),
  454. 'settings' => array(
  455. 'chado_table' => 'featureloc',
  456. 'chado_column' => $pkey,
  457. 'base_table' => 'feature',
  458. 'semantic_web' => 'SO:position_of',
  459. ),
  460. );
  461. }
  462. // FEATUREPOS
  463. if ($table_name == 'feature') {
  464. $schema = chado_get_schema('featurepos');
  465. $pkey = $schema['primary key'][0];
  466. $field_name = 'featurepos';
  467. $field_type = 'chado_linker__featurepos';
  468. $info[$field_name] = array(
  469. 'field_name' => $field_name,
  470. 'type' => $field_type,
  471. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  472. 'locked' => FALSE,
  473. 'storage' => array(
  474. 'type' => 'field_chado_storage',
  475. ),
  476. 'settings' => array(
  477. 'chado_table' => 'featurepos',
  478. 'chado_column' => $pkey,
  479. 'base_table' => 'feature',
  480. 'semantic_web' => 'SO:position_of',
  481. ),
  482. );
  483. }
  484. // GENOTYPE
  485. $genotype_table = $table_name . '_genotype';
  486. if (chado_table_exists($genotype_table)) {
  487. $schema = chado_get_schema($genotype_table);
  488. $pkey = $schema['primary key'][0];
  489. $field_name = $table_name . '_genotype';
  490. $field_type = 'chado_linker__genotype';
  491. $info[$field_name] = array(
  492. 'field_name' => $field_name,
  493. 'type' => $field_type,
  494. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  495. 'locked' => FALSE,
  496. 'storage' => array(
  497. 'type' => 'field_chado_storage',
  498. ),
  499. 'settings' => array(
  500. 'chado_table' => $genotype_table,
  501. 'chado_column' => $pkey,
  502. 'semantic_web' => 'SO:0001027',
  503. 'base_table' => $table_name,
  504. ),
  505. );
  506. }
  507. // PHENOTYPE
  508. $phenotype_table = $table_name . '_phenotype';
  509. if (chado_table_exists($phenotype_table)) {
  510. $schema = chado_get_schema($phenotype_table);
  511. $pkey = $schema['primary key'][0];
  512. $field_name = $table_name . '_phenotype';
  513. $field_type = 'chado_linker__phenotype';
  514. $info[$field_name] = array(
  515. 'field_name' => $field_name,
  516. 'type' => $field_type,
  517. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  518. 'locked' => FALSE,
  519. 'storage' => array(
  520. 'type' => 'field_chado_storage',
  521. ),
  522. 'settings' => array(
  523. 'chado_table' => $phenotype_table,
  524. 'chado_column' => $pkey,
  525. 'base_table' => $table_name,
  526. 'semantic_web' => 'SBO:0000358',
  527. ),
  528. );
  529. }
  530. // PROPERTIES
  531. $prop_table = $table_name . 'prop';
  532. if (chado_table_exists($prop_table)) {
  533. $field_name = $table_name . 'prop';
  534. $field_type = 'chado_linker__prop_adder';
  535. $info[$field_name] = array(
  536. 'field_name' => $field_name,
  537. 'type' => $field_type,
  538. 'cardinality' => 1,
  539. 'locked' => FALSE,
  540. 'storage' => array(
  541. 'type' => 'field_chado_storage',
  542. ),
  543. 'settings' => array(
  544. 'base_table' => $table_name
  545. ),
  546. );
  547. }
  548. // PUBLICATIONS
  549. $pub_table = $table_name . '_pub';
  550. if (chado_table_exists($pub_table)) {
  551. $schema = chado_get_schema($pub_table);
  552. $pkey = $schema['primary key'][0];
  553. $field_name = $table_name . '_pub';
  554. $field_type = 'chado_linker__pub';
  555. $info[$field_name] = array(
  556. 'field_name' => $field_name,
  557. 'type' => $field_type,
  558. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  559. 'locked' => FALSE,
  560. 'storage' => array(
  561. 'type' => 'field_chado_storage',
  562. ),
  563. 'settings' => array(
  564. 'chado_table' => $pub_table,
  565. 'chado_column' => $pkey,
  566. 'base_table' => $table_name,
  567. 'semantic_web' => 'schema:publication',
  568. ),
  569. );
  570. }
  571. // RELATIONSHIPS
  572. // If the linker table does not exists then we don't want to add attach.
  573. $rel_table = $table_name . '_relationship';
  574. if (chado_table_exists($rel_table)) {
  575. $schema = chado_get_schema($rel_table);
  576. $pkey = $schema['primary key'][0];
  577. $field_name = $table_name . '_relationship';
  578. $field_type = 'chado_linker__relationship';
  579. $info[$field_name] = array(
  580. 'field_name' => $field_name,
  581. 'type' => $field_type,
  582. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  583. 'locked' => FALSE,
  584. 'storage' => array(
  585. 'type' => 'field_chado_storage',
  586. ),
  587. 'settings' => array(
  588. 'chado_table' => $rel_table,
  589. 'chado_column' => $pkey,
  590. 'base_table' => $table_name,
  591. 'semantic_web' => 'SBO:0000374',
  592. ),
  593. );
  594. }
  595. // SYNONYMS
  596. $syn_table = $table_name . '_synonym';
  597. if (chado_table_exists($syn_table)) {
  598. $schema = chado_get_schema($syn_table);
  599. $pkey = $schema['primary key'][0];
  600. $field_name = $table_name . '_synonym';
  601. $field_type = 'chado_linker__synonym';
  602. $info[$field_name] = array(
  603. 'field_name' => $field_name,
  604. 'type' => $field_type,
  605. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  606. 'locked' => FALSE,
  607. 'storage' => array(
  608. 'type' => 'field_chado_storage',
  609. ),
  610. 'settings' => array(
  611. 'chado_table' => $syn_table,
  612. 'chado_column' => $pkey,
  613. 'base_table' => $table_name,
  614. 'semantic_web' => 'schema:alternateName',
  615. ),
  616. );
  617. }
  618. }
  619. /**
  620. * Impelments hook_create_tripalfield_instance().
  621. *
  622. * This is a Tripal defined hook that supports integration with the
  623. * TripalEntity field.
  624. */
  625. function tripal_chado_create_tripalfield_instance2($entity_type, $bundle) {
  626. $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
  627. $vocab = $term->vocab;
  628. $params = array(
  629. 'vocabulary' => $vocab->vocabulary,
  630. 'accession' => $term->accession,
  631. );
  632. $mapped_table = chado_get_cvterm_mapping($params);
  633. // Get the details about the mapping of this bundle to the Chado table:
  634. $details = array(
  635. 'chado_cv_id' => $mapped_table->cvterm->cv_id->cv_id,
  636. 'chado_cvterm_id' => $mapped_table->cvterm->cvterm_id,
  637. 'chado_table' => $mapped_table->chado_table,
  638. 'chado_type_table' => $mapped_table->chado_table,
  639. 'chado_type_column' => $mapped_table->chado_field,
  640. );
  641. tripal_chado_create_tripalfield_instance_base($info, $entity_type, $bundle, $details);
  642. tripal_chado_create_tripalfield_instance_custom($info, $entity_type, $bundle, $details);
  643. tripal_chado_create_tripalfield_instance_linker($info, $entity_type, $bundle, $details);
  644. return $info;
  645. }
  646. /**
  647. * Helper function for the hook_create_tripalfield_instance().
  648. *
  649. * Add the field instances that corresond to the columns of the base table.
  650. *
  651. * @param $entity_type
  652. * @param $bundle
  653. * @param $details
  654. */
  655. function tripal_chado_create_tripalfield_instance_base(&$info, $entity_type, $bundle, $details) {
  656. $fields = array();
  657. // Get Chado information
  658. $table_name = $details['chado_table'];
  659. $type_table = $details['chado_type_table'];
  660. $type_field = $details['chado_type_column'];
  661. $cv_id = $details['chado_cv_id'];
  662. $cvterm_id = $details['chado_cvterm_id'];
  663. // Iterate through the columns of the table and see if fields have been
  664. // created for each one. If not, then create them.
  665. $schema = chado_get_schema($table_name);
  666. if (!$schema) {
  667. return;
  668. }
  669. $columns = $schema['fields'];
  670. foreach ($columns as $column_name => $details) {
  671. $field_name = $table_name . '__' . $column_name;
  672. // Skip the primary key field.
  673. if ($column_name == $schema['primary key'][0]) {
  674. continue;
  675. }
  676. // Skip the type field.
  677. if ($table_name == $type_table and $column_name == $type_field) {
  678. continue;
  679. }
  680. $base_info = array(
  681. 'field_name' => $field_name,
  682. 'entity_type' => 'TripalEntity',
  683. 'bundle' => $bundle->name,
  684. 'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
  685. 'description' => '',
  686. 'required' => FALSE,
  687. 'settings' => array(
  688. 'auto_attach' => TRUE,
  689. ),
  690. 'widget' => array(
  691. 'settings' => array(
  692. 'display_label' => 1,
  693. ),
  694. ),
  695. 'display' => array(
  696. 'default' => array(
  697. 'label' => 'inline',
  698. 'settings' => array(),
  699. ),
  700. ),
  701. );
  702. // Determine if the field is required.
  703. if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
  704. $base_info['required'] = TRUE;
  705. }
  706. // Alter the field info array depending on the column details.
  707. switch($details['type']) {
  708. case 'char':
  709. $base_info['widget']['type'] = 'text_textfield';
  710. break;
  711. case 'varchar':
  712. $base_info['widget']['type'] = 'text_textfield';
  713. break;
  714. case 'text':
  715. $base_info['widget']['type'] = 'text_textarea';
  716. $base_info['widget']['settings']['format'] = filter_default_format();
  717. break;
  718. case 'blob':
  719. // not sure how to support a blob field.
  720. continue;
  721. break;
  722. case 'int':
  723. $base_info['widget']['type'] = 'number';
  724. break;
  725. case 'float':
  726. $base_info['widget']['type'] = 'number';
  727. break;
  728. case 'numeric':
  729. $base_info['widget']['type'] = 'number';
  730. break;
  731. case 'serial':
  732. // Serial fields are most likely not needed as a field.
  733. break;
  734. case 'boolean':
  735. $base_info['widget']['type'] = 'options_onoff';
  736. $base_info['required'] = FALSE;
  737. break;
  738. case 'datetime':
  739. $base_info['widget']['type'] = 'date_select';
  740. $base_info['widget']['settings']['increment'] = 1;
  741. $base_info['widget']['settings']['tz_handling'] = 'none';
  742. $base_info['widget']['settings']['collapsible'] = TRUE;
  743. // TODO: Add settings so that the minutes increment by 1.
  744. // And turn off the timezone, as the Chado field doesn't support it.
  745. break;
  746. }
  747. // Set some default semantic web information
  748. if ($column_name == 'uniquename') {
  749. $base_info['label'] = 'Identifier';
  750. $base_info['widget_type'] = 'text_textfield';
  751. }
  752. elseif ($base_info['label'] == 'Timeaccessioned') {
  753. $base_info['label'] = 'Time Accessioned';
  754. $base_info['description'] = 'Please enter the time that this record was first added to the database.';
  755. }
  756. elseif ($base_info['label'] == 'Timelastmodified') {
  757. $base_info['label'] = 'Time Last Modified';
  758. $base_info['description'] = 'Please enter the time that this record was last modified. The default is the current time.';
  759. }
  760. //
  761. // ORGANISM TABLE
  762. //
  763. elseif ($table_name == 'organism' and $column_name == 'comment') {
  764. $base_info['label'] = 'Description';
  765. }
  766. //
  767. // PUB TABLE
  768. //
  769. elseif ($table_name == 'pub' and $column_name == 'uniquename') {
  770. $base_info['widget_type'] = 'text_textfield';
  771. }
  772. //
  773. // ANALYSIS TABLE
  774. //
  775. elseif ($table_name == 'analysis' and $column_name == 'program') {
  776. $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.';
  777. $base_info['label'] = 'Program, Pipeline, Workflow or Method Name.';
  778. }
  779. elseif ($table_name == 'analysis' and $column_name == 'sourceuri') {
  780. $base_info['widget_type'] = 'text_textfield';
  781. $base_info['label'] = 'Source URL';
  782. $base_info['description'] = 'The URL where the original source data was derived. Ideally, this should link to the page where more information about the source data can be found.';
  783. }
  784. elseif ($table_name == 'analysis' and $column_name == 'sourcename') {
  785. $base_info['label'] = 'Source Name';
  786. $base_info['description'] = 'The name of the source data. This could be a file name, data set or a small description for how the data was collected. For long descriptions use the larger description field.';
  787. }
  788. elseif ($table_name == 'analysis' and $column_name == 'sourceversion') {
  789. $base_info['label'] = 'Source Version';
  790. $base_info['description'] = 'If hte source data set has a version include it here.';
  791. }
  792. elseif ($table_name == 'analysis' and $column_name == 'algorithm') {
  793. $base_info['label'] = 'Source Version';
  794. $base_info['description'] = 'The name of the algorithm used to produce the dataset if different from the program.';
  795. }
  796. elseif ($table_name == 'analysis' and $column_name == 'programversion') {
  797. $base_info['label'] = 'Program Version';
  798. $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.';
  799. }
  800. //
  801. // PROJECT TABLE
  802. //
  803. elseif ($table_name == 'project' and $column_name == 'description') {
  804. $base_info['label'] = 'Short Description';
  805. }
  806. $info[$field_name] = $base_info;
  807. }
  808. }
  809. /**
  810. * Helper function for the hook_create_tripalfield_instance().
  811. *
  812. * Adds custom fields for base fields. These override the settings provided
  813. * in the tripal_chado_create_tripalfield_instance_base() function.
  814. *
  815. * @param $entity_type
  816. * @param $bundle
  817. * @param $details
  818. */
  819. function tripal_chado_create_tripalfield_instance_custom(&$info, $entity_type, $bundle, $details) {
  820. $table_name = $details['chado_table'];
  821. $type_table = $details['chado_type_table'];
  822. $type_field = $details['chado_type_column'];
  823. $cv_id = $details['chado_cv_id'];
  824. $cvterm_id = $details['chado_cvterm_id'];
  825. $schema = chado_get_schema($table_name);
  826. // BASE DBXREF
  827. if (array_key_exists('dbxref_id', $schema['fields'])) {
  828. $field_name = $table_name . '__dbxref_id';
  829. $info[$field_name] = array(
  830. 'field_name' => $field_name,
  831. 'entity_type' => $entity_type,
  832. 'bundle' => $bundle->name,
  833. 'label' => 'Accession',
  834. 'description' => 'This field specifies the unique stable accession (ID) for
  835. this record. It requires that this site have a database entry.',
  836. 'required' => FALSE,
  837. 'settings' => array(
  838. 'auto_attach' => TRUE,
  839. ),
  840. 'widget' => array(
  841. 'type' => 'chado_base__dbxref_id_widget',
  842. 'settings' => array(
  843. 'display_label' => 1,
  844. ),
  845. ),
  846. 'display' => array(
  847. 'default' => array(
  848. 'label' => 'inline',
  849. 'type' => 'chado_base__dbxref_id_formatter',
  850. 'settings' => array(),
  851. ),
  852. ),
  853. );
  854. }
  855. // BASE ORGANISM_ID
  856. if ($table_name != 'organism' and array_key_exists('organism_id', $schema['fields'])) {
  857. $field_name = $table_name . '__organism_id';
  858. $is_required = FALSE;
  859. if (array_key_exists('not null', $schema['fields']['organism_id']) and
  860. $schema['fields']['organism_id']['not null']) {
  861. $is_required = TRUE;
  862. }
  863. $info[$field_name] = array(
  864. 'field_name' => $field_name,
  865. 'entity_type' => $entity_type,
  866. 'bundle' => $bundle->name,
  867. 'label' => 'Organism',
  868. 'description' => 'Select an organism.',
  869. 'required' => $is_required,
  870. 'settings' => array(
  871. 'auto_attach' => TRUE,
  872. ),
  873. 'widget' => array(
  874. 'type' => 'chado_base__organism_id_widget',
  875. 'settings' => array(
  876. 'display_label' => 1,
  877. ),
  878. ),
  879. 'display' => array(
  880. 'default' => array(
  881. 'label' => 'inline',
  882. 'type' => 'chado_base__organism_id_formatter',
  883. 'settings' => array(),
  884. ),
  885. ),
  886. );
  887. }
  888. // FEATURE MD5CHECKSUM
  889. if ($table_name == 'feature') {
  890. $field_name = $table_name . '__md5checksum';
  891. $info[$field_name] = array(
  892. 'field_name' => $field_name,
  893. 'entity_type' => $entity_type,
  894. 'bundle' => $bundle->name,
  895. 'label' => 'Sequence Checksum',
  896. 'description' => 'The MD5 checksum for the sequence. The checksum here
  897. will always be unique for the raw unformatted sequence. To verify that the
  898. sequence has not been corrupted, download the raw sequence and use an MD5 tool
  899. to calculate the value. If the value calculated is identical the one shown
  900. here, then the downloaded sequence is uncorrupted.',
  901. 'required' => FALSE,
  902. 'settings' => array(
  903. 'auto_attach' => TRUE,
  904. ),
  905. 'widget' => array(
  906. 'type' => 'chado_feature__md5checksum_widget',
  907. 'settings' => array(
  908. 'display_label' => 1,
  909. 'md5_fieldname' => 'feature__md5checksum',
  910. ),
  911. ),
  912. 'display' => array(
  913. 'default' => array(
  914. 'label' => 'inline',
  915. 'type' => 'chado_feature__md5checksum_formatter',
  916. 'settings' => array(),
  917. ),
  918. ),
  919. );
  920. }
  921. // FEATURE RESIDUES
  922. if ($table_name == 'feature') {
  923. $field_name = 'feature__residues';
  924. $info[$field_name] = array(
  925. 'field_name' => $field_name,
  926. 'entity_type' => $entity_type,
  927. 'bundle' => $bundle->name,
  928. 'label' => 'Sequences',
  929. 'description' => 'All available sequences for this record.',
  930. 'required' => FALSE,
  931. 'settings' => array(
  932. 'auto_attach' => FALSE,
  933. ),
  934. 'widget' => array(
  935. 'type' => 'chado_feature__residues_widget',
  936. 'settings' => array(
  937. 'display_label' => 1,
  938. ),
  939. ),
  940. 'display' => array(
  941. 'default' => array(
  942. 'label' => 'above',
  943. 'type' => 'chado_feature__residues_formatter',
  944. 'settings' => array(),
  945. ),
  946. ),
  947. );
  948. }
  949. // FEATURE SEQLEN
  950. if ($table_name == 'feature') {
  951. $field_name = 'feature__seqlen';
  952. $info[$field_name] = array(
  953. 'field_name' => $field_name,
  954. 'entity_type' => $entity_type,
  955. 'bundle' => $bundle->name,
  956. 'label' => 'Raw Sequence Length',
  957. 'description' => 'The number of residues in the raw sequence. This length
  958. is only for the assigned raw sequence and does not represent the length of any
  959. sequences derived from alignments. If this value is zero but aligned sequences
  960. are present then this record has no official assigned sequence.',
  961. 'required' => FALSE,
  962. 'settings' => array(
  963. 'auto_attach' => TRUE,
  964. ),
  965. 'widget' => array(
  966. 'type' => 'chado_feature__seqlen_widget',
  967. 'settings' => array(
  968. 'display_label' => 1,
  969. ),
  970. ),
  971. 'display' => array(
  972. 'default' => array(
  973. 'label' => 'inline',
  974. 'type' => 'chado_feature__seqlen_formatter',
  975. 'settings' => array(),
  976. ),
  977. ),
  978. );
  979. }
  980. // GENE TRANSCRIPTS
  981. $rel_table = $table_name . '_relationship';
  982. if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
  983. $field_name = 'gene_transcripts';
  984. $info[$field_name] = array(
  985. 'field_name' => $field_name,
  986. 'entity_type' => $entity_type,
  987. 'bundle' => $bundle->name,
  988. 'label' => 'Transcripts',
  989. 'description' => 'These transcripts are associated with this gene.',
  990. 'required' => FALSE,
  991. 'settings' => array(
  992. 'auto_attach' => FALSE,
  993. ),
  994. 'widget' => array(
  995. 'type' => 'chado_gene__transcripts_widget',
  996. 'settings' => array(
  997. 'display_label' => 1,
  998. ),
  999. ),
  1000. 'display' => array(
  1001. 'default' => array(
  1002. 'label' => 'above',
  1003. 'type' => 'chado_gene__transcripts_formatter',
  1004. 'settings' => array(),
  1005. ),
  1006. ),
  1007. );
  1008. }
  1009. // ORGANISM TYPE_ID
  1010. if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
  1011. $field_name = 'organism__type_id';
  1012. $info[$field_name] = array(
  1013. 'field_name' => $field_name,
  1014. 'entity_type' => $entity_type,
  1015. 'bundle' => $bundle->name,
  1016. 'label' => 'Infraspecific Type',
  1017. 'description' => 'The Infraspecific Type.',
  1018. 'required' => FALSE,
  1019. 'settings' => array(
  1020. 'auto_attach' => TRUE,
  1021. ),
  1022. 'widget' => array(
  1023. 'type' => 'chado_organism__type_id_widget',
  1024. 'settings' => array(
  1025. 'display_label' => 1,
  1026. ),
  1027. ),
  1028. 'display' => array(
  1029. 'default' => array(
  1030. 'label' => 'inline',
  1031. 'type' => 'chado_organism__type_id_formatter',
  1032. 'settings' => array(),
  1033. ),
  1034. ),
  1035. );
  1036. }
  1037. }
  1038. /**
  1039. *
  1040. * @param unknown $entity_type
  1041. * @param unknown $bundle
  1042. * @param unknown $details
  1043. */
  1044. function tripal_chado_create_tripalfield_instance_linker(&$info, $entity_type, $bundle, $details) {
  1045. $table_name = $details['chado_table'];
  1046. $type_table = $details['chado_type_table'];
  1047. $type_field = $details['chado_type_column'];
  1048. $cv_id = $details['chado_cv_id'];
  1049. $cvterm_id = $details['chado_cvterm_id'];
  1050. // CONTACTS
  1051. $contact_table = $table_name . '_contact';
  1052. if (chado_table_exists($contact_table)) {
  1053. $field_name = $table_name . '_contact';
  1054. $info[$field_name] = array(
  1055. 'field_name' => $field_name,
  1056. 'entity_type' => $entity_type,
  1057. 'bundle' => $bundle->name,
  1058. 'label' => 'Contacts',
  1059. 'description' => 'An individual, organization or entity that has had
  1060. some responsibility for the creation, delivery or maintenance of
  1061. the associated data.',
  1062. 'required' => FALSE,
  1063. 'settings' => array(
  1064. 'auto_attach' => FALSE,
  1065. ),
  1066. 'widget' => array(
  1067. 'type' => 'chado_linker__contact_widget',
  1068. 'settings' => array(
  1069. 'display_label' => 1,
  1070. ),
  1071. ),
  1072. 'display' => array(
  1073. 'default' => array(
  1074. 'label' => 'above',
  1075. 'type' => 'chado_linker__contact_formatter',
  1076. 'settings' => array(),
  1077. ),
  1078. ),
  1079. );
  1080. }
  1081. // CVTERM
  1082. $cvterm_table = $table_name . '_cvterm';
  1083. if (chado_table_exists($cvterm_table)) {
  1084. $field_name = $table_name . '_cvterm';
  1085. $info[$field_name] = array(
  1086. 'field_name' => $field_name,
  1087. 'entity_type' => $entity_type,
  1088. 'bundle' => $bundle->name,
  1089. 'label' => 'Add Annotation Types',
  1090. 'description' => 'Add additional annotations types to this record.',
  1091. 'required' => FALSE,
  1092. 'settings' => array(
  1093. 'auto_attach' => FALSE,
  1094. ),
  1095. 'widget' => array(
  1096. 'type' => 'chado_linker__cvterm_adder_widget',
  1097. 'settings' => array(
  1098. 'display_label' => 1,
  1099. ),
  1100. ),
  1101. 'display' => array(
  1102. 'default' => array(
  1103. 'label' => 'above',
  1104. 'type' => 'chado_linker__cvterm_adder_formatter',
  1105. 'settings' => array(),
  1106. ),
  1107. ),
  1108. );
  1109. }
  1110. // DBXREF
  1111. $dbxref_table = $table_name . '_dbxref';
  1112. if (chado_table_exists($dbxref_table)) {
  1113. $field_name = $table_name . '_dbxref';
  1114. $info[$field_name] = array(
  1115. 'field_name' => $field_name,
  1116. 'entity_type' => $entity_type,
  1117. 'bundle' => $bundle->name,
  1118. 'label' => 'Cross References',
  1119. 'description' => 'The IDs where this record may be available in other external online databases.',
  1120. 'required' => FALSE,
  1121. 'settings' => array(
  1122. 'auto_attach' => FALSE,
  1123. ),
  1124. 'widget' => array(
  1125. 'type' => 'chado_linker__dbxref_widget',
  1126. 'settings' => array(
  1127. 'display_label' => 1,
  1128. ),
  1129. ),
  1130. 'display' => array(
  1131. 'default' => array(
  1132. 'label' => 'inline',
  1133. 'type' => 'chado_linker__dbxref_formatter',
  1134. 'settings' => array(),
  1135. ),
  1136. ),
  1137. );
  1138. }
  1139. // EXPRESSION
  1140. $expression_table = $table_name . '_expression';
  1141. if (chado_table_exists($expression_table)) {
  1142. $field_name = $table_name . '_expression';
  1143. $info[$field_name] = array(
  1144. 'field_name' => $field_name,
  1145. 'entity_type' => $entity_type,
  1146. 'bundle' => $bundle->name,
  1147. 'label' => 'Expression',
  1148. 'description' => 'Information about the expression of this record.',
  1149. 'required' => FALSE,
  1150. 'settings' => array(
  1151. 'auto_attach' => FALSE,
  1152. ),
  1153. 'widget' => array(
  1154. 'type' => 'chado_linker__expression_widget',
  1155. 'settings' => array(
  1156. 'display_label' => 1,
  1157. ),
  1158. ),
  1159. 'display' => array(
  1160. 'default' => array(
  1161. 'label' => 'above',
  1162. 'type' => 'chado_linker__expression_formatter',
  1163. 'settings' => array(),
  1164. ),
  1165. ),
  1166. );
  1167. }
  1168. // FEATURELOC
  1169. if ($table_name == 'feature') {
  1170. $field_name = 'featureloc';
  1171. $info[$field_name] = array(
  1172. 'field_name' => $field_name,
  1173. 'entity_type' => $entity_type,
  1174. 'bundle' => $bundle->name,
  1175. 'label' => 'Aligned Locations',
  1176. 'description' => 'The locations on other genomic sequences where this
  1177. record has been aligned.',
  1178. 'required' => FALSE,
  1179. 'settings' => array(
  1180. 'auto_attach' => FALSE,
  1181. ),
  1182. 'widget' => array(
  1183. 'type' => 'chado_linker__featureloc_widget',
  1184. 'settings' => array(
  1185. 'display_label' => 1,
  1186. ),
  1187. ),
  1188. 'display' => array(
  1189. 'default' => array(
  1190. 'label' => 'above',
  1191. 'type' => 'chado_linker__featureloc_formatter',
  1192. 'settings' => array(),
  1193. ),
  1194. ),
  1195. );
  1196. }
  1197. // FEATUREPOS
  1198. if ($table_name == 'feature') {
  1199. $field_name = 'featurepos';
  1200. $info[$field_name] = array(
  1201. 'field_name' => $field_name,
  1202. 'entity_type' => $entity_type,
  1203. 'bundle' => $bundle->name,
  1204. 'label' => 'Map Positions',
  1205. 'description' => 'The positions on a genetic map.',
  1206. 'required' => FALSE,
  1207. 'settings' => array(
  1208. 'auto_attach' => FALSE,
  1209. ),
  1210. 'widget' => array(
  1211. 'type' => 'chado_linker__featurepos_widget',
  1212. 'settings' => array(
  1213. 'display_label' => 1,
  1214. ),
  1215. ),
  1216. 'display' => array(
  1217. 'default' => array(
  1218. 'label' => 'above',
  1219. 'type' => 'chado_linker__featurepos_formatter',
  1220. 'settings' => array(),
  1221. ),
  1222. ),
  1223. );
  1224. }
  1225. // GENOTYPE
  1226. $genotype_table = $table_name . '_genotype';
  1227. if (chado_table_exists($genotype_table)) {
  1228. $field_name = $table_name . '_genotype';
  1229. $info[$field_name] = array(
  1230. 'field_name' => $field_name,
  1231. 'entity_type' => $entity_type,
  1232. 'bundle' => $bundle->name,
  1233. 'label' => 'Genotypes',
  1234. 'description' => 'The genotypes associated with this record.',
  1235. 'required' => FALSE,
  1236. 'settings' => array(
  1237. 'auto_attach' => FALSE,
  1238. ),
  1239. 'widget' => array(
  1240. 'type' => 'chado_linker__genotype_widget',
  1241. 'settings' => array(
  1242. 'display_label' => 1,
  1243. ),
  1244. ),
  1245. 'display' => array(
  1246. 'default' => array(
  1247. 'label' => 'above',
  1248. 'type' => 'chado_linker__genotype_formatter',
  1249. 'settings' => array(),
  1250. ),
  1251. ),
  1252. );
  1253. }
  1254. // PHENOTYPE
  1255. $phenotype_table = $table_name . '_phenotype';
  1256. if (chado_table_exists($phenotype_table)) {
  1257. $field_name = $table_name . '_phenotype';
  1258. $info[$field_name] = array(
  1259. 'field_name' => $field_name,
  1260. 'entity_type' => $entity_type,
  1261. 'bundle' => $bundle->name,
  1262. 'label' => 'Phenotypes',
  1263. 'description' => 'The phenotypes associated with this record.',
  1264. 'required' => FALSE,
  1265. 'settings' => array(
  1266. 'auto_attach' => FALSE,
  1267. ),
  1268. 'widget' => array(
  1269. 'type' => 'chado_linker__phenotype_widget',
  1270. 'settings' => array(
  1271. 'display_label' => 1,
  1272. ),
  1273. ),
  1274. 'display' => array(
  1275. 'default' => array(
  1276. 'label' => 'above',
  1277. 'type' => 'chado_linker__phenotype_formatter',
  1278. 'settings' => array(),
  1279. ),
  1280. ),
  1281. );
  1282. }
  1283. // PROPERTIES
  1284. $prop_table = $table_name . 'prop';
  1285. if (chado_table_exists($prop_table)) {
  1286. $field_name = $table_name . 'prop';
  1287. $info[$field_name] = array(
  1288. 'field_name' => $field_name,
  1289. 'entity_type' => $entity_type,
  1290. 'bundle' => $bundle->name,
  1291. 'label' => 'Add Properties',
  1292. 'description' => 'Add additional property types to this record.',
  1293. 'required' => FALSE,
  1294. 'settings' => array(
  1295. 'auto_attach' => FALSE,
  1296. ),
  1297. 'widget' => array(
  1298. 'type' => 'chado_linker__prop_adder_widget',
  1299. 'settings' => array(
  1300. 'display_label' => 1,
  1301. ),
  1302. ),
  1303. 'display' => array(
  1304. 'default' => array(
  1305. 'label' => 'above',
  1306. 'type' => 'chado_linker__prop_adder_formatter',
  1307. 'settings' => array(),
  1308. ),
  1309. ),
  1310. );
  1311. }
  1312. // PUBLICATIONS
  1313. $pub_table = $table_name . '_pub';
  1314. if (chado_table_exists($pub_table)) {
  1315. $field_name = $table_name . '_pub';
  1316. $info[$field_name] = array(
  1317. 'field_name' => $field_name,
  1318. 'entity_type' => $entity_type,
  1319. 'bundle' => $bundle->name,
  1320. 'label' => 'Publications',
  1321. 'description' => 'This record has been referenced or is sourced from
  1322. these publications.',
  1323. 'required' => FALSE,
  1324. 'settings' => array(
  1325. 'auto_attach' => FALSE,
  1326. ),
  1327. 'widget' => array(
  1328. 'type' => 'chado_linker__pub_widget',
  1329. 'settings' => array(
  1330. 'display_label' => 1,
  1331. ),
  1332. ),
  1333. 'display' => array(
  1334. 'default' => array(
  1335. 'label' => 'above',
  1336. 'type' => 'chado_linker__pub_formatter',
  1337. 'settings' => array(),
  1338. ),
  1339. ),
  1340. );
  1341. }
  1342. // RELATIONSHIPS
  1343. // If the linker table does not exists then we don't want to add attach.
  1344. $rel_table = $table_name . '_relationship';
  1345. if (chado_table_exists($rel_table)) {
  1346. $field_name = $table_name . '_relationship';
  1347. $info[$field_name] = array(
  1348. 'field_name' => $field_name,
  1349. 'entity_type' => $entity_type,
  1350. 'bundle' => $bundle->name,
  1351. 'label' => 'Relationships',
  1352. 'description' => 'Other records with relationships to this record.',
  1353. 'required' => FALSE,
  1354. 'settings' => array(
  1355. 'auto_attach' => FALSE,
  1356. ),
  1357. 'widget' => array(
  1358. 'type' => 'chado_linker__relationship_widget',
  1359. 'settings' => array(
  1360. 'display_label' => 1,
  1361. ),
  1362. ),
  1363. 'display' => array(
  1364. 'default' => array(
  1365. 'label' => 'above',
  1366. 'type' => 'chado_linker__relationship_formatter',
  1367. 'settings' => array(),
  1368. ),
  1369. ),
  1370. );
  1371. }
  1372. // SYNONYMS
  1373. $syn_table = $table_name . '_synonym';
  1374. if (chado_table_exists($syn_table)) {
  1375. $field_name = $table_name . '_synonym';
  1376. $info[$field_name] = array(
  1377. 'field_name' => $field_name,
  1378. 'entity_type' => $entity_type,
  1379. 'bundle' => $bundle->name,
  1380. 'label' => 'Synonyms',
  1381. 'description' => 'Alternate names, aliases or synonyms for this record.',
  1382. 'required' => FALSE,
  1383. 'settings' => array(
  1384. 'auto_attach' => FALSE,
  1385. ),
  1386. 'widget' => array(
  1387. 'type' => 'chado_linker__synonym_widget',
  1388. 'settings' => array(
  1389. 'display_label' => 1,
  1390. ),
  1391. ),
  1392. 'display' => array(
  1393. 'default' => array(
  1394. 'label' => 'inline',
  1395. 'type' => 'chado_linker__synonym_formatter',
  1396. 'settings' => array(),
  1397. ),
  1398. ),
  1399. );
  1400. }
  1401. }
  1402. /**
  1403. * Implements hook_form_FORM_ID_alter().
  1404. *
  1405. * The field_ui_field_overview_form is used for ordering and configuring the
  1406. * fields attached to an entity.
  1407. *
  1408. * This function removes the property adder field as that is really not meant
  1409. * for users to show or manage.
  1410. */
  1411. function tripal_chado_form_field_ui_field_overview_form_alter(&$form, &$form_state, $form_id) {
  1412. // Remove the kvproperty_addr field as it isn't ever displayed. It's just used
  1413. // on the add/edit form of an entity for adding new property fields.
  1414. $fields_names = element_children($form['fields']);
  1415. foreach ($fields_names as $field_name) {
  1416. $field_info = field_info_field($field_name);
  1417. if ($field_info['type'] == 'kvproperty_adder') {
  1418. unset($form['fields'][$field_name]);
  1419. }
  1420. if ($field_info['type'] == 'cvterm_class_adder') {
  1421. unset($form['fields'][$field_name]);
  1422. }
  1423. }
  1424. }