tripal_chado.fields.inc 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395
  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[] = 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. *
  554. * This is a Tripal defined hook that supports integration with the
  555. * TripalEntity field.
  556. */
  557. function tripal_chado_create_tripalfield_instance($entity_type, $bundle) {
  558. $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
  559. $vocab = $term->vocab;
  560. $params = array(
  561. 'vocabulary' => $vocab->vocabulary,
  562. 'accession' => $term->accession,
  563. );
  564. $mapped_table = chado_get_cvterm_mapping($params);
  565. // Get the details about the mapping of this bundle to the Chado table:
  566. $details = array(
  567. 'chado_cv_id' => $mapped_table->cvterm->cv_id->cv_id,
  568. 'chado_cvterm_id' => $mapped_table->cvterm->cvterm_id,
  569. 'chado_table' => $mapped_table->chado_table,
  570. 'chado_type_table' => $mapped_table->chado_table,
  571. 'chado_type_column' => $mapped_table->chado_field,
  572. );
  573. tripal_chado_create_tripalfield_instance_base($info, $entity_type, $bundle, $details);
  574. tripal_chado_create_tripalfield_instance_custom($info, $entity_type, $bundle, $details);
  575. tripal_chado_create_tripalfield_instance_linker($info, $entity_type, $bundle, $details);
  576. return $info;
  577. }
  578. /**
  579. *
  580. * @param unknown $entity_type
  581. * @param unknown $bundle
  582. * @param unknown $details
  583. */
  584. function tripal_chado_create_tripalfield_instance_base(&$info, $entity_type, $bundle, $details) {
  585. $fields = array();
  586. // Get Chado information
  587. $table_name = $details['chado_table'];
  588. $type_table = $details['chado_type_table'];
  589. $type_field = $details['chado_type_column'];
  590. $cv_id = $details['chado_cv_id'];
  591. $cvterm_id = $details['chado_cvterm_id'];
  592. // Iterate through the columns of the table and see if fields have been
  593. // created for each one. If not, then create them.
  594. $schema = chado_get_schema($table_name);
  595. if (!$schema) {
  596. return;
  597. }
  598. $columns = $schema['fields'];
  599. foreach ($columns as $column_name => $details) {
  600. $field_name = $table_name . '__' . $column_name;
  601. // Skip the primary key field.
  602. if ($column_name == $schema['primary key'][0]) {
  603. continue;
  604. }
  605. // Skip the type field.
  606. if ($table_name == $type_table and $column_name == $type_field) {
  607. continue;
  608. }
  609. $base_info = array(
  610. 'field_name' => $field_name,
  611. 'entity_type' => 'TripalEntity',
  612. 'bundle' => $bundle->name,
  613. 'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
  614. 'description' => '',
  615. 'required' => FALSE,
  616. 'settings' => array(
  617. 'auto_attach' => TRUE,
  618. ),
  619. 'widget' => array(
  620. 'settings' => array(
  621. 'display_label' => 1,
  622. ),
  623. ),
  624. 'display' => array(
  625. 'default' => array(
  626. 'label' => 'inline',
  627. 'settings' => array(),
  628. ),
  629. ),
  630. );
  631. // Determine if the field is required.
  632. if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
  633. $base_info['required'] = TRUE;
  634. }
  635. // Alter the field info array depending on the column details.
  636. switch($details['type']) {
  637. case 'char':
  638. $base_info['widget']['type'] = 'text_textfield';
  639. break;
  640. case 'varchar':
  641. $base_info['widget']['type'] = 'text_textfield';
  642. break;
  643. case 'text':
  644. $base_info['widget']['type'] = 'text_textarea';
  645. $base_info['widget']['settings']['format'] = filter_default_format();
  646. break;
  647. case 'blob':
  648. // not sure how to support a blob field.
  649. continue;
  650. break;
  651. case 'int':
  652. $base_info['widget']['type'] = 'number';
  653. break;
  654. case 'float':
  655. $base_info['widget']['type'] = 'number';
  656. break;
  657. case 'numeric':
  658. $base_info['widget']['type'] = 'number';
  659. break;
  660. case 'serial':
  661. // Serial fields are most likely not needed as a field.
  662. break;
  663. case 'boolean':
  664. $base_info['widget']['type'] = 'options_onoff';
  665. break;
  666. case 'datetime':
  667. $base_info['widget']['type'] = 'date_select';
  668. $base_info['widget']['settings']['increment'] = 1;
  669. $base_info['widget']['settings']['tz_handling'] = 'none';
  670. $base_info['widget']['settings']['collapsible'] = TRUE;
  671. // TODO: Add settings so that the minutes increment by 1.
  672. // And turn off the timezone, as the Chado field doesn't support it.
  673. break;
  674. }
  675. // Set some default semantic web information
  676. if ($column_name == 'uniquename') {
  677. $base_info['label'] = 'Identifier';
  678. $base_info['widget_type'] = 'text_textfield';
  679. }
  680. elseif ($base_info['label'] == 'Timeaccessioned') {
  681. $base_info['label'] = 'Time Accessioned';
  682. $base_info['description'] = 'Please enter the time that this record was first added to the database.';
  683. }
  684. elseif ($base_info['label'] == 'Timelastmodified') {
  685. $base_info['label'] = 'Time Last Modified';
  686. $base_info['description'] = 'Please enter the time that this record was last modified. The default is the current time.';
  687. }
  688. //
  689. // ORGANISM TABLE
  690. //
  691. elseif ($table_name == 'organism' and $column_name == 'comment') {
  692. $base_info['label'] = 'Description';
  693. }
  694. //
  695. // PUB TABLE
  696. //
  697. elseif ($table_name == 'pub' and $column_name == 'uniquename') {
  698. $base_info['widget_type'] = 'text_textfield';
  699. }
  700. //
  701. // ANALYSIS TABLE
  702. //
  703. elseif ($table_name == 'analysis' and $column_name == 'program') {
  704. $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.';
  705. $base_info['label'] = 'Program, Pipeline, Workflow or Method Name.';
  706. }
  707. elseif ($table_name == 'analysis' and $column_name == 'sourceuri') {
  708. $base_info['widget_type'] = 'text_textfield';
  709. $base_info['label'] = 'Source URL';
  710. $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.';
  711. }
  712. elseif ($table_name == 'analysis' and $column_name == 'sourcename') {
  713. $base_info['label'] = 'Source Name';
  714. $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.';
  715. }
  716. elseif ($table_name == 'analysis' and $column_name == 'sourceversion') {
  717. $base_info['label'] = 'Source Version';
  718. $base_info['description'] = 'If hte source data set has a version include it here.';
  719. }
  720. elseif ($table_name == 'analysis' and $column_name == 'algorithm') {
  721. $base_info['label'] = 'Source Version';
  722. $base_info['description'] = 'The name of the algorithm used to produce the dataset if different from the program.';
  723. }
  724. elseif ($table_name == 'analysis' and $column_name == 'programversion') {
  725. $base_info['label'] = 'Program Version';
  726. $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.';
  727. }
  728. //
  729. // PROJECT TABLE
  730. //
  731. elseif ($table_name == 'project' and $column_name == 'description') {
  732. $base_info['label'] = 'Short Description';
  733. }
  734. $info[] = $base_info;
  735. }
  736. }
  737. /**
  738. *
  739. * @param unknown $entity_type
  740. * @param unknown $bundle
  741. * @param unknown $details
  742. */
  743. function tripal_chado_create_tripalfield_instance_custom(&$info, $entity_type, $bundle, $details) {
  744. $table_name = $details['chado_table'];
  745. $type_table = $details['chado_type_table'];
  746. $type_field = $details['chado_type_column'];
  747. $cv_id = $details['chado_cv_id'];
  748. $cvterm_id = $details['chado_cvterm_id'];
  749. $schema = chado_get_schema($table_name);
  750. // BASE DBXREF
  751. if (array_key_exists('dbxref_id', $schema['fields'])) {
  752. $field_name = $table_name . '__dbxref_id';
  753. $info[] = array(
  754. 'field_name' => $field_name,
  755. 'entity_type' => $entity_type,
  756. 'bundle' => $bundle->name,
  757. 'label' => 'Accession',
  758. 'description' => 'This field specifies the unique stable accession (ID) for
  759. this record. It requires that this site have a database entry.',
  760. 'required' => FALSE,
  761. 'settings' => array(
  762. 'auto_attach' => TRUE,
  763. ),
  764. 'widget' => array(
  765. 'type' => 'chado_base__dbxref_id_widget',
  766. 'settings' => array(
  767. 'display_label' => 1,
  768. ),
  769. ),
  770. 'display' => array(
  771. 'default' => array(
  772. 'label' => 'inline',
  773. 'type' => 'chado_base__dbxref_id_formatter',
  774. 'settings' => array(),
  775. ),
  776. ),
  777. );
  778. }
  779. // BASE ORGANISM_ID
  780. if ($table_name != 'organism' and array_key_exists('organism_id', $schema['fields'])) {
  781. $field_name = $table_name . '__organism_id';
  782. $is_required = FALSE;
  783. if (array_key_exists('not null', $schema['fields']['organism_id']) and
  784. $schema['fields']['organism_id']['not null']) {
  785. $is_required = TRUE;
  786. }
  787. $info[] = array(
  788. 'field_name' => $field_name,
  789. 'entity_type' => $entity_type,
  790. 'bundle' => $bundle->name,
  791. 'label' => 'Organism',
  792. 'description' => 'Select an organism.',
  793. 'required' => $is_required,
  794. 'settings' => array(
  795. 'auto_attach' => TRUE,
  796. ),
  797. 'widget' => array(
  798. 'type' => 'chado_base__organism_id_widget',
  799. 'settings' => array(
  800. 'display_label' => 1,
  801. ),
  802. ),
  803. 'display' => array(
  804. 'default' => array(
  805. 'label' => 'inline',
  806. 'type' => 'chado_base__organism_id_formatter',
  807. 'settings' => array(),
  808. ),
  809. ),
  810. );
  811. }
  812. // FEATURE MD5CHECKSUM
  813. if ($table_name == 'feature') {
  814. $field_name = $table_name . '__md5checksum';
  815. $info[] = array(
  816. 'field_name' => $field_name,
  817. 'entity_type' => $entity_type,
  818. 'bundle' => $bundle->name,
  819. 'label' => 'Sequence Checksum',
  820. 'description' => 'The MD5 checksum for the sequence. The checksum here
  821. will always be unique for the raw unformatted sequence. To verify that the
  822. sequence has not been corrupted, download the raw sequence and use an MD5 tool
  823. to calculate the value. If the value calculated is identical the one shown
  824. here, then the downloaded sequence is uncorrupted.',
  825. 'required' => FALSE,
  826. 'settings' => array(
  827. 'auto_attach' => TRUE,
  828. ),
  829. 'widget' => array(
  830. 'type' => 'chado_feature__md5checksum_widget',
  831. 'settings' => array(
  832. 'display_label' => 1,
  833. 'md5_fieldname' => 'feature__md5checksum',
  834. ),
  835. ),
  836. 'display' => array(
  837. 'default' => array(
  838. 'label' => 'inline',
  839. 'type' => 'chado_feature__md5checksum_formatter',
  840. 'settings' => array(),
  841. ),
  842. ),
  843. );
  844. }
  845. // FEATURE RESIDUES
  846. if ($table_name == 'feature') {
  847. $field_name = 'feature__residues';
  848. $info[] = array(
  849. 'field_name' => $field_name,
  850. 'entity_type' => $entity_type,
  851. 'bundle' => $bundle->name,
  852. 'label' => 'Sequences',
  853. 'description' => 'All available sequences for this record.',
  854. 'required' => FALSE,
  855. 'settings' => array(
  856. 'auto_attach' => FALSE,
  857. ),
  858. 'widget' => array(
  859. 'type' => 'chado_feature__residues_widget',
  860. 'settings' => array(
  861. 'display_label' => 1,
  862. ),
  863. ),
  864. 'display' => array(
  865. 'default' => array(
  866. 'label' => 'above',
  867. 'type' => 'chado_feature__residues_formatter',
  868. 'settings' => array(),
  869. ),
  870. ),
  871. );
  872. }
  873. // FEATURE SEQLEN
  874. if ($table_name == 'feature') {
  875. $field_name = 'feature__seqlen';
  876. $info[] = array(
  877. 'field_name' => $field_name,
  878. 'entity_type' => $entity_type,
  879. 'bundle' => $bundle->name,
  880. 'label' => 'Raw Sequence Length',
  881. 'description' => 'The number of residues in the raw sequence. This length
  882. is only for the assigned raw sequence and does not represent the length of any
  883. sequences derived from alignments. If this value is zero but aligned sequences
  884. are present then this record has no official assigned sequence.',
  885. 'required' => FALSE,
  886. 'settings' => array(
  887. 'auto_attach' => TRUE,
  888. ),
  889. 'widget' => array(
  890. 'type' => 'chado_feature__seqlen_widget',
  891. 'settings' => array(
  892. 'display_label' => 1,
  893. ),
  894. ),
  895. 'display' => array(
  896. 'default' => array(
  897. 'label' => 'inline',
  898. 'type' => 'chado_feature__seqlen_formatter',
  899. 'settings' => array(),
  900. ),
  901. ),
  902. );
  903. }
  904. // GENE TRANSCRIPTS
  905. $rel_table = $table_name . '_relationship';
  906. if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
  907. $field_name = 'gene_transcripts';
  908. $info[] = array(
  909. 'field_name' => $field_name,
  910. 'entity_type' => $entity_type,
  911. 'bundle' => $bundle->name,
  912. 'label' => 'Transcripts',
  913. 'description' => 'These transcripts are associated with this gene.',
  914. 'required' => FALSE,
  915. 'settings' => array(
  916. 'auto_attach' => FALSE,
  917. ),
  918. 'widget' => array(
  919. 'type' => 'chado_gene__transcripts_widget',
  920. 'settings' => array(
  921. 'display_label' => 1,
  922. ),
  923. ),
  924. 'display' => array(
  925. 'default' => array(
  926. 'label' => 'above',
  927. 'type' => 'chado_gene__transcripts_formatter',
  928. 'settings' => array(),
  929. ),
  930. ),
  931. );
  932. }
  933. // ORGANISM TYPE_ID
  934. if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
  935. $field_name = 'organism__type_id';
  936. $info[] = array(
  937. 'field_name' => $field_name,
  938. 'entity_type' => $entity_type,
  939. 'bundle' => $bundle->name,
  940. 'label' => 'Infraspecific Type',
  941. 'description' => 'The Infraspecific Type.',
  942. 'required' => FALSE,
  943. 'settings' => array(
  944. 'auto_attach' => TRUE,
  945. ),
  946. 'widget' => array(
  947. 'type' => 'chado_organism__type_id_widget',
  948. 'settings' => array(
  949. 'display_label' => 1,
  950. ),
  951. ),
  952. 'display' => array(
  953. 'default' => array(
  954. 'label' => 'inline',
  955. 'type' => 'chado_organism__type_id_formatter',
  956. 'settings' => array(),
  957. ),
  958. ),
  959. );
  960. }
  961. }
  962. /**
  963. *
  964. * @param unknown $entity_type
  965. * @param unknown $bundle
  966. * @param unknown $details
  967. */
  968. function tripal_chado_create_tripalfield_instance_linker(&$info, $entity_type, $bundle, $details) {
  969. $table_name = $details['chado_table'];
  970. $type_table = $details['chado_type_table'];
  971. $type_field = $details['chado_type_column'];
  972. $cv_id = $details['chado_cv_id'];
  973. $cvterm_id = $details['chado_cvterm_id'];
  974. // CONTACTS
  975. $contact_table = $table_name . '_contact';
  976. if (chado_table_exists($contact_table)) {
  977. $field_name = $table_name . '_contact';
  978. $info[] = array(
  979. 'field_name' => $field_name,
  980. 'entity_type' => $entity_type,
  981. 'bundle' => $bundle->name,
  982. 'label' => 'Contacts',
  983. 'description' => 'An individual, organization or entity that has had
  984. some responsibility for the creation, delivery or maintenance of
  985. the associated data.',
  986. 'required' => FALSE,
  987. 'settings' => array(
  988. 'auto_attach' => FALSE,
  989. ),
  990. 'widget' => array(
  991. 'type' => 'chado_linker__contact_widget',
  992. 'settings' => array(
  993. 'display_label' => 1,
  994. ),
  995. ),
  996. 'display' => array(
  997. 'default' => array(
  998. 'label' => 'above',
  999. 'type' => 'chado_linker__contact_formatter',
  1000. 'settings' => array(),
  1001. ),
  1002. ),
  1003. );
  1004. }
  1005. // CVTERM
  1006. $cvterm_table = $table_name . '_cvterm';
  1007. if (chado_table_exists($cvterm_table)) {
  1008. $field_name = $table_name . '_cvterm';
  1009. $info[] = array(
  1010. 'field_name' => $field_name,
  1011. 'entity_type' => $entity_type,
  1012. 'bundle' => $bundle->name,
  1013. 'label' => 'Add Annotation Types',
  1014. 'description' => 'Add additional annotations types to this record.',
  1015. 'required' => FALSE,
  1016. 'settings' => array(
  1017. 'auto_attach' => FALSE,
  1018. ),
  1019. 'widget' => array(
  1020. 'type' => 'chado_linker__cvterm_adder_widget',
  1021. 'settings' => array(
  1022. 'display_label' => 1,
  1023. ),
  1024. ),
  1025. 'display' => array(
  1026. 'default' => array(
  1027. 'label' => 'above',
  1028. 'type' => 'chado_linker__cvterm_adder_formatter',
  1029. 'settings' => array(),
  1030. ),
  1031. ),
  1032. );
  1033. }
  1034. // DBXREF
  1035. $dbxref_table = $table_name . '_dbxref';
  1036. if (chado_table_exists($dbxref_table)) {
  1037. $info[] = array(
  1038. 'field_name' => $field_name,
  1039. 'entity_type' => $entity_type,
  1040. 'bundle' => $bundle->name,
  1041. 'label' => 'Cross References',
  1042. 'description' => 'The IDs where this record may be available in other external online databases.',
  1043. 'required' => FALSE,
  1044. 'settings' => array(
  1045. 'auto_attach' => FALSE,
  1046. ),
  1047. 'widget' => array(
  1048. 'type' => 'chado_linker__dbxref_widget',
  1049. 'settings' => array(
  1050. 'display_label' => 1,
  1051. ),
  1052. ),
  1053. 'display' => array(
  1054. 'default' => array(
  1055. 'label' => 'inline',
  1056. 'type' => 'chado_linker__dbxref_formatter',
  1057. 'settings' => array(),
  1058. ),
  1059. ),
  1060. );
  1061. }
  1062. // EXPRESSION
  1063. $expression_table = $table_name . '_expression';
  1064. if (chado_table_exists($expression_table)) {
  1065. $field_name = $table_name . '_expression';
  1066. $info[] = array(
  1067. 'field_name' => $field_name,
  1068. 'entity_type' => $entity_type,
  1069. 'bundle' => $bundle->name,
  1070. 'label' => 'Expression',
  1071. 'description' => 'Information about the expression of this record.',
  1072. 'required' => FALSE,
  1073. 'settings' => array(
  1074. 'auto_attach' => FALSE,
  1075. ),
  1076. 'widget' => array(
  1077. 'type' => 'chado_linker__expression_widget',
  1078. 'settings' => array(
  1079. 'display_label' => 1,
  1080. ),
  1081. ),
  1082. 'display' => array(
  1083. 'default' => array(
  1084. 'label' => 'above',
  1085. 'type' => 'chado_linker__expression_formatter',
  1086. 'settings' => array(),
  1087. ),
  1088. ),
  1089. );
  1090. }
  1091. // FEATURELOC
  1092. if ($table_name == 'feature') {
  1093. $field_name = 'featureloc';
  1094. $info[] = array(
  1095. 'field_name' => $field_name,
  1096. 'entity_type' => $entity_type,
  1097. 'bundle' => $bundle->name,
  1098. 'label' => 'Aligned Locations',
  1099. 'description' => 'The locations on other genomic sequences where this
  1100. record has been aligned.',
  1101. 'required' => FALSE,
  1102. 'settings' => array(
  1103. 'auto_attach' => FALSE,
  1104. ),
  1105. 'widget' => array(
  1106. 'type' => 'chado_linker__featureloc_widget',
  1107. 'settings' => array(
  1108. 'display_label' => 1,
  1109. ),
  1110. ),
  1111. 'display' => array(
  1112. 'default' => array(
  1113. 'label' => 'above',
  1114. 'type' => 'chado_linker__featureloc_formatter',
  1115. 'settings' => array(),
  1116. ),
  1117. ),
  1118. );
  1119. }
  1120. // GENOTYPE
  1121. $genotype_table = $table_name . '_genotype';
  1122. if (chado_table_exists($genotype_table)) {
  1123. $field_name = $table_name . '_genotype';
  1124. $info[] = array(
  1125. 'field_name' => $field_name,
  1126. 'entity_type' => $entity_type,
  1127. 'bundle' => $bundle->name,
  1128. 'label' => 'Genotypes',
  1129. 'description' => 'The genotypes associated with this record.',
  1130. 'required' => FALSE,
  1131. 'settings' => array(
  1132. 'auto_attach' => FALSE,
  1133. ),
  1134. 'widget' => array(
  1135. 'type' => 'chado_linker__genotype_widget',
  1136. 'settings' => array(
  1137. 'display_label' => 1,
  1138. ),
  1139. ),
  1140. 'display' => array(
  1141. 'default' => array(
  1142. 'label' => 'above',
  1143. 'type' => 'chado_linker__genotype_formatter',
  1144. 'settings' => array(),
  1145. ),
  1146. ),
  1147. );
  1148. }
  1149. // PHENOTYPE
  1150. $phenotype_table = $table_name . '_phenotype';
  1151. if (chado_table_exists($phenotype_table)) {
  1152. $field_name = $table_name . '_phenotype';
  1153. $info[] = array(
  1154. 'field_name' => $field_name,
  1155. 'entity_type' => $entity_type,
  1156. 'bundle' => $bundle->name,
  1157. 'label' => 'Phenotypes',
  1158. 'description' => 'The phenotypes associated with this record.',
  1159. 'required' => FALSE,
  1160. 'settings' => array(
  1161. 'auto_attach' => FALSE,
  1162. ),
  1163. 'widget' => array(
  1164. 'type' => 'chado_linker__phenotype_widget',
  1165. 'settings' => array(
  1166. 'display_label' => 1,
  1167. ),
  1168. ),
  1169. 'display' => array(
  1170. 'default' => array(
  1171. 'label' => 'above',
  1172. 'type' => 'chado_linker__phenotype_formatter',
  1173. 'settings' => array(),
  1174. ),
  1175. ),
  1176. );
  1177. }
  1178. // PROPERTIES
  1179. $prop_table = $table_name . 'prop';
  1180. if (chado_table_exists($prop_table)) {
  1181. $field_name = $table_name . 'prop';
  1182. $info[] = array(
  1183. 'field_name' => $field_name,
  1184. 'entity_type' => $entity_type,
  1185. 'bundle' => $bundle->name,
  1186. 'label' => 'Add Properties',
  1187. 'description' => 'Add additional property types to this record.',
  1188. 'required' => FALSE,
  1189. 'settings' => array(
  1190. 'auto_attach' => FALSE,
  1191. ),
  1192. 'widget' => array(
  1193. 'type' => 'chado_linker__prop_adder_widget',
  1194. 'settings' => array(
  1195. 'display_label' => 1,
  1196. ),
  1197. ),
  1198. 'display' => array(
  1199. 'default' => array(
  1200. 'label' => 'above',
  1201. 'type' => 'chado_linker__prop_adder_formatter',
  1202. 'settings' => array(),
  1203. ),
  1204. ),
  1205. );
  1206. }
  1207. // PUBLICATIONS
  1208. $pub_table = $table_name . '_pub';
  1209. if (chado_table_exists($pub_table)) {
  1210. $field_name = $table_name . '_pub';
  1211. $info[] = array(
  1212. 'field_name' => $field_name,
  1213. 'entity_type' => $entity_type,
  1214. 'bundle' => $bundle->name,
  1215. 'label' => 'Publications',
  1216. 'description' => 'This record has been referenced or is sourced from
  1217. these publications.',
  1218. 'required' => FALSE,
  1219. 'settings' => array(
  1220. 'auto_attach' => FALSE,
  1221. ),
  1222. 'widget' => array(
  1223. 'type' => 'chado_linker__pub_widget',
  1224. 'settings' => array(
  1225. 'display_label' => 1,
  1226. ),
  1227. ),
  1228. 'display' => array(
  1229. 'default' => array(
  1230. 'label' => 'above',
  1231. 'type' => 'chado_linker__pub_formatter',
  1232. 'settings' => array(),
  1233. ),
  1234. ),
  1235. );
  1236. }
  1237. // RELATIONSHIPS
  1238. // If the linker table does not exists then we don't want to add attach.
  1239. $rel_table = $table_name . '_relationship';
  1240. if (chado_table_exists($rel_table)) {
  1241. $field_name = $table_name . '_relationship';
  1242. $info[] = array(
  1243. 'field_name' => $field_name,
  1244. 'entity_type' => $entity_type,
  1245. 'bundle' => $bundle->name,
  1246. 'label' => 'Relationships',
  1247. 'description' => 'Other records with relationships to this record.',
  1248. 'required' => FALSE,
  1249. 'settings' => array(
  1250. 'auto_attach' => FALSE,
  1251. ),
  1252. 'widget' => array(
  1253. 'type' => 'chado_linker__relationship_widget',
  1254. 'settings' => array(
  1255. 'display_label' => 1,
  1256. ),
  1257. ),
  1258. 'display' => array(
  1259. 'default' => array(
  1260. 'label' => 'above',
  1261. 'type' => 'chado_linker__relationship_formatter',
  1262. 'settings' => array(),
  1263. ),
  1264. ),
  1265. );
  1266. }
  1267. // SYNONYMS
  1268. $syn_table = $table_name . '_synonym';
  1269. if (chado_table_exists($syn_table)) {
  1270. $field_name = $table_name . '_synonym';
  1271. $info[] = array(
  1272. 'field_name' => $field_name,
  1273. 'entity_type' => $entity_type,
  1274. 'bundle' => $bundle->name,
  1275. 'label' => 'Synonyms',
  1276. 'description' => 'Alternate names, aliases or synonyms for this record.',
  1277. 'required' => FALSE,
  1278. 'settings' => array(
  1279. 'auto_attach' => FALSE,
  1280. ),
  1281. 'widget' => array(
  1282. 'type' => 'chado_linker__synonym_widget',
  1283. 'settings' => array(
  1284. 'display_label' => 1,
  1285. ),
  1286. ),
  1287. 'display' => array(
  1288. 'default' => array(
  1289. 'label' => 'inline',
  1290. 'type' => 'chado_linker__synonym_formatter',
  1291. 'settings' => array(),
  1292. ),
  1293. ),
  1294. );
  1295. }
  1296. }
  1297. /**
  1298. * Implements hook_form_FORM_ID_alter().
  1299. *
  1300. * The field_ui_field_overview_form is used for ordering and configuring the
  1301. * fields attached to an entity.
  1302. *
  1303. * This function removes the property adder field as that is really not meant
  1304. * for users to show or manage.
  1305. */
  1306. function tripal_chado_form_field_ui_field_overview_form_alter(&$form, &$form_state, $form_id) {
  1307. // Remove the kvproperty_addr field as it isn't ever displayed. It's just used
  1308. // on the add/edit form of an entity for adding new property fields.
  1309. $fields_names = element_children($form['fields']);
  1310. foreach ($fields_names as $field_name) {
  1311. $field_info = field_info_field($field_name);
  1312. if ($field_info['type'] == 'kvproperty_adder') {
  1313. unset($form['fields'][$field_name]);
  1314. }
  1315. if ($field_info['type'] == 'cvterm_class_adder') {
  1316. unset($form['fields'][$field_name]);
  1317. }
  1318. }
  1319. }