tripal_chado.fields.inc 42 KB

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