tripal_chado.fields.inc 42 KB

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