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