tripal_chado.fields.inc 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  1. <?php
  2. /**
  3. * Implements hook_field_info().
  4. */
  5. function tripal_chado_field_info() {
  6. $fields = array(
  7. /*
  8. * Generic fields that support multiple base tables.
  9. */
  10. 'chado_base__organism_id' => array(
  11. 'label' => t('Organism'),
  12. 'description' => t('A field for specifying an organism.'),
  13. 'default_widget' => 'chado_base__organism_id_widget',
  14. 'default_formatter' => 'chado_base__organism_id_formatter',
  15. 'settings' => array(),
  16. 'storage' => array(
  17. 'type' => 'field_chado_storage',
  18. 'module' => 'tripal_chado',
  19. 'active' => TRUE
  20. ),
  21. ),
  22. 'chado_base__dbxref_id' => array(
  23. 'label' => t('Cross reference'),
  24. 'description' => t('This record can be cross referenced with a record in
  25. another online database. This field is intended for the most prominent
  26. reference. At a minimum, the database and accession must be provided.'),
  27. 'default_widget' => 'chado_base__dbxref_id_widget',
  28. 'default_formatter' => 'chado_base__dbxref_id_formatter',
  29. 'settings' => array(),
  30. 'storage' => array(
  31. 'type' => 'field_chado_storage',
  32. 'module' => 'tripal_chado',
  33. 'active' => TRUE
  34. ),
  35. ),
  36. /*
  37. * Fields that support linker tables.
  38. */
  39. 'chado_linker__cvterm' => array(
  40. 'label' => t('Annotations'),
  41. 'description' => t('This record can be annotated with terms
  42. from other vocabularies.'),
  43. 'default_widget' => 'chado_linker__cvterm_widget',
  44. 'default_formatter' => 'chado_linker__cvterm_formatter',
  45. 'settings' => array(),
  46. 'storage' => array(
  47. 'type' => 'field_chado_storage',
  48. 'module' => 'tripal_chado',
  49. 'active' => TRUE
  50. ),
  51. ),
  52. 'chado_linker__synonym' => array(
  53. 'label' => t('Synonyms'),
  54. 'description' => t('Adds an alternative name (synonym or alias) to this record.'),
  55. 'default_widget' => 'chado_linker__synonym_widget',
  56. 'default_formatter' => 'chado_linker__synonym_formatter',
  57. 'settings' => array(),
  58. 'storage' => array(
  59. 'type' => 'field_chado_storage',
  60. 'module' => 'tripal_chado',
  61. 'active' => TRUE
  62. ),
  63. ),
  64. 'chado_linker__prop' => array(
  65. 'label' => t('Add a Property'),
  66. 'description' => t('Add details about this property.'),
  67. 'default_widget' => 'chado_linker__prop_widget',
  68. 'default_formatter' => 'chado_linker__prop_formatter',
  69. 'settings' => array(),
  70. 'storage' => array(
  71. 'type' => 'field_chado_storage',
  72. 'module' => 'tripal_chado',
  73. 'active' => TRUE
  74. ),
  75. ),
  76. 'chado_linker__dbxref' => array(
  77. 'label' => t('Cross references'),
  78. 'description' => t('This record can be cross referenced with a record in
  79. another online database. This field is intended for one or more
  80. references. At a minimum, the database and accession must be provided.'),
  81. 'default_widget' => 'chado_linker__dbxref_widget',
  82. 'default_formatter' => 'chado_linker__dbxref_formatter',
  83. 'settings' => array(),
  84. 'storage' => array(
  85. 'type' => 'field_chado_storage',
  86. 'module' => 'tripal_chado',
  87. 'active' => TRUE
  88. ),
  89. ),
  90. 'chado_linker__pub' => array(
  91. 'label' => t('Publications'),
  92. 'description' => t('Associates a publication (e.g. journal article,
  93. conference proceedings, book chapter, etc.) with this record.'),
  94. 'default_widget' => 'chado_linker__pub_widget',
  95. 'default_formatter' => 'chado_linker__pub_formatter',
  96. 'settings' => array(),
  97. 'storage' => array(
  98. 'type' => 'field_chado_storage',
  99. 'module' => 'tripal_chado',
  100. 'active' => TRUE
  101. ),
  102. ),
  103. /*
  104. * Fields that add new fields. These fields are not shown on
  105. * pages. They are avaiable to site curators when adding/updating
  106. * a record and allow the user to add new linker table fields.
  107. */
  108. 'chado_linker__prop_adder' => array(
  109. 'label' => t('Add a Property Type'),
  110. 'description' => t('This record may have any number of properties. Use
  111. this field to first add the type.'),
  112. 'default_widget' => 'chado_linker__prop_adder_widget',
  113. 'default_formatter' => 'hidden',
  114. 'settings' => array(),
  115. 'storage' => array(
  116. 'type' => 'field_chado_storage',
  117. 'module' => 'tripal_chado',
  118. 'active' => TRUE
  119. ),
  120. ),
  121. // The field provides a widget for adding new vocabularies for cvterm
  122. // linker tables. This will allow cvterms to be grouped by vocabulary
  123. // ('category').
  124. 'chado_linker__cvterm_adder' => array(
  125. 'label' => t('Add an Annotation Type'),
  126. 'description' => t('This record may have any number of types of
  127. annotations. Use this field to first add the type.'),
  128. 'default_widget' => 'chado_linker__cvterm_adder_widget',
  129. 'default_formatter' => 'hidden',
  130. 'settings' => array(),
  131. 'storage' => array(
  132. 'type' => 'field_chado_storage',
  133. 'module' => 'tripal_chado',
  134. 'active' => TRUE
  135. ),
  136. ),
  137. /*
  138. * Field specific to the feature table of Chado.
  139. */
  140. 'chado_feature__residues' => array(
  141. 'label' => t('Residues'),
  142. 'description' => t('A field for managing nucleotide and protein residues.'),
  143. 'default_widget' => 'chado_feature__residues_widget',
  144. 'default_formatter' => 'chado_feature__residues_formatter',
  145. 'settings' => array(),
  146. 'storage' => array(
  147. 'type' => 'field_chado_storage',
  148. 'module' => 'tripal_chado',
  149. 'active' => TRUE
  150. ),
  151. ),
  152. 'chado_feature__md5checksum' => array(
  153. 'label' => t('MD5 checksum'),
  154. 'description' => t('A field for generating MD5 checksum for a sequence.'),
  155. 'default_widget' => 'chado_feature__md5checksum_widget',
  156. 'default_formatter' => 'chado_feature__md5checksum_formatter',
  157. 'settings' => array(),
  158. 'storage' => array(
  159. 'type' => 'field_chado_storage',
  160. 'module' => 'tripal_chado',
  161. 'active' => TRUE
  162. ),
  163. ),
  164. 'chado_feature__seqlen' => array(
  165. 'label' => t('Sequence length'),
  166. 'description' => t('A field for calculating the length of a sequence.'),
  167. 'default_widget' => 'chado_feature__seqlen_widget',
  168. 'default_formatter' => 'chado_feature__seqlen_formatter',
  169. 'settings' => array(),
  170. 'storage' => array(
  171. 'type' => 'field_chado_storage',
  172. 'module' => 'tripal_chado',
  173. 'active' => TRUE
  174. ),
  175. ),
  176. );
  177. return $fields;
  178. }
  179. /**
  180. * Implements hook_field_widget_info().
  181. */
  182. function tripal_chado_field_widget_info() {
  183. return array(
  184. /*
  185. * Generic fields that support multiple base tables.
  186. */
  187. 'chado_base__organism_id_widget' => array(
  188. 'label' => t('Organism Select'),
  189. 'field types' => array('chado_base__organism_id')
  190. ),
  191. 'chado_base__dbxref_id_widget' => array(
  192. 'label' => t('Cross reference'),
  193. 'field types' => array('chado_base__dbxref_id'),
  194. 'description' => t('This record can be cross referenced with a record in
  195. another online database. This field is intended for the most
  196. prominent reference. At a minimum, the database and accession
  197. must be provided.'),
  198. ),
  199. /*
  200. * Fields that support linker tables.
  201. */
  202. 'chado_linker__pub_widget' => array(
  203. 'label' => t('Publications'),
  204. 'field types' => array('chado_linker__pub'),
  205. ),
  206. 'chado_linker__dbxref_widget' => array(
  207. 'label' => t('Cross references'),
  208. 'field types' => array('chado_linker__dbxref'),
  209. 'description' => t('This record can be cross referenced with a record
  210. in another online database. This field is intended for the most
  211. prominent reference. At a minimum, the database and accession
  212. must be provided.'),
  213. ),
  214. 'chado_linker__cvterm_widget' => array(
  215. 'label' => t('Annotations'),
  216. 'field types' => array('chado_linker__cvterm'),
  217. 'description' => t('This record can be annotated with terms
  218. from other vocabularies.'),
  219. ),
  220. 'chado_linker__prop_widget' => array(
  221. 'label' => t('Property'),
  222. 'field types' => array('chado_linker__prop'),
  223. ),
  224. 'chado_linker__synonym_widget' => array(
  225. 'label' => t('Synonyms'),
  226. 'field types' => array('chado_linker__synonym'),
  227. ),
  228. /*
  229. * Fields that add new fields. These fields are not shown on
  230. * pages. They are avaiable to site curators when adding/updating
  231. * a record and allow the user to add new linker table fields.
  232. */
  233. 'chado_linker__prop_adder_widget' => array(
  234. 'label' => t('Add a Property'),
  235. 'field types' => array('chado_linker__prop_adder'),
  236. ),
  237. 'chado_linker__cvterm_adder_widget' => array(
  238. 'label' => t('Add an Annotation'),
  239. 'field types' => array('chado_linker__cvterm_adder'),
  240. ),
  241. /*
  242. * Field specific to the feature table of Chado.
  243. */
  244. 'chado_feature__md5checksum_widget' => array(
  245. 'label' => t('MD5 Checksum Checkbox'),
  246. 'field types' => array('chado_feature__md5checksum'),
  247. ),
  248. 'chado_feature__residues_widget' => array(
  249. 'label' => t('Residues'),
  250. 'field types' => array('chado_feature__residues'),
  251. ),
  252. 'chado_feature__seqlen_widget' => array(
  253. 'label' => t('Sequence Length'),
  254. 'field types' => array('chado_feature__seqlen'),
  255. ),
  256. );
  257. }
  258. /**
  259. * Implements hook_field_formatter_info().
  260. */
  261. function tripal_chado_field_formatter_info() {
  262. return array(
  263. 'chado_base__organism_id_formatter' => array(
  264. 'label' => t('Organism'),
  265. 'field types' => array('chado_base__organism_id')
  266. ),
  267. 'chado_base__dbxref_id_formatter' => array(
  268. 'label' => t('Cross reference'),
  269. 'field types' => array('chado_base__dbxref_id')
  270. ),
  271. 'chado_linker__pub_formatter' => array(
  272. 'label' => t('Publications'),
  273. 'field types' => array('chado_linker__pub')
  274. ),
  275. 'chado_linker__dbxref_formatter' => array(
  276. 'label' => t('Cross references'),
  277. 'field types' => array('chado_linker__dbxref')
  278. ),
  279. 'chado_linker__cvterm_formatter' => array(
  280. 'label' => t('Annotations'),
  281. 'field types' => array('chado_linker__cvterm')
  282. ),
  283. 'chado_linker__prop_formatter' => array(
  284. 'label' => t('Property'),
  285. 'field types' => array('chado_linker__prop')
  286. ),
  287. 'chado_linker__synonym_formatter' => array(
  288. 'label' => t('Synonyms'),
  289. 'field types' => array('chado_linker__synonym')
  290. ),
  291. 'chado_linker__cvterm_adder_formatter' => array(
  292. 'label' => t('Add an Annotation'),
  293. 'field types' => array('chado_linker__cvterm_adder')
  294. ),
  295. 'chado_linker__prop_adder_formatter' => array(
  296. 'label' => t('Add a Property'),
  297. 'field types' => array('chado_linker__prop_adder')
  298. ),
  299. 'chado_feature__md5checksum_formatter' => array(
  300. 'label' => t('MD5 checksum'),
  301. 'field types' => array('chado_feature__md5checksum')
  302. ),
  303. 'chado_feature__residues_formatter' => array(
  304. 'label' => t('Residues'),
  305. 'field types' => array('chado_feature__residues')
  306. ),
  307. 'chado_feature__seqlen_formatter' => array(
  308. 'label' => t('Sequence length'),
  309. 'field types' => array('chado_feature__seqlen')
  310. ),
  311. );
  312. }
  313. /**
  314. * Implements hook_field_formatter_settings_summary.
  315. */
  316. function tripal_chado_field_formatter_settings_summary($field, $instance, $view_mode) {
  317. $summary = '';
  318. switch ($field['type']) {
  319. case 'organism_id':
  320. $summary = 'Organisms can be displayed in vaious ways.';
  321. break;
  322. default:
  323. $summary = '';
  324. }
  325. return $summary;
  326. }
  327. /**
  328. * Implements hook_field_formatter_settings_form.
  329. */
  330. function tripal_chado_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  331. $element = array();
  332. $field_type = $field['type'];
  333. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/' . $field_type);
  334. module_load_include('inc', 'tripal_chado', 'includes/fields/' . $field_type);
  335. $function = $field_type . '_formatter_form';
  336. if (function_exists($function)) {
  337. $element = $function($field, $instance, $view_mode, $form, $form_state);
  338. }
  339. return $element;
  340. }
  341. /**
  342. * Implements hook_field_formatter_view().
  343. */
  344. function tripal_chado_field_formatter_view($entity_type, $entity, $field,
  345. $instance, $langcode, $items, $display) {
  346. $element = array();
  347. $field_type = $display['type'];
  348. module_load_include('inc', 'tripal_chado', 'includes/fields/' . $field_type);
  349. $function = $field_type;
  350. if (function_exists($function)) {
  351. $function($element, $entity_type, $entity, $field, $instance, $langcode, $items, $display);
  352. }
  353. return $element;
  354. }
  355. /**
  356. * Implements hook_field_widget_form().
  357. */
  358. function tripal_chado_field_widget_form(&$form, &$form_state, $field,
  359. $instance, $langcode, $items, $delta, $element) {
  360. $widget = $element;
  361. $field_type = $instance['widget']['type'];
  362. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/' . $field_type);
  363. module_load_include('inc', 'tripal_chado', 'includes/fields/' . $field_type);
  364. $function = $field_type;
  365. if (function_exists($function)) {
  366. $function($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  367. }
  368. return $widget;
  369. }
  370. /**
  371. * Returns the values of the field from the $form_state.
  372. */
  373. function tripal_chado_get_field_form_values($field_name, $form_state, $delta = 0, $child = NULL) {
  374. $value = NULL;
  375. // The form_state must have the 'values' key. If not then just return.
  376. if (!array_key_exists('values', $form_state)) {
  377. return $value;
  378. }
  379. // If the field name is not in the form_state['values'] then return.
  380. if (!array_key_exists($field_name, $form_state['values'])) {
  381. return $value;
  382. }
  383. // Iterate through the values looking for the field_name provided.
  384. foreach ($form_state['values'][$field_name] as $langcode => $items) {
  385. if (!array_key_exists($delta, $items)) {
  386. continue;
  387. }
  388. $item = $items[$delta];
  389. if ($child){
  390. if(array_key_exists($child, $item) and $item[$child] != '') {
  391. $value = $item[$child];
  392. }
  393. }
  394. else {
  395. $value = $item['value'];
  396. }
  397. }
  398. return $value;
  399. }
  400. /**
  401. * Sets the values of the field from the $form_state.
  402. */
  403. function tripal_chado_set_field_form_values($field_name, &$form_state, $newvalue, $delta = 0, $child = NULL) {
  404. // The form_state must have the 'values' key. If not then just return.
  405. if (!array_key_exists('values', $form_state)) {
  406. return FALSE;
  407. }
  408. // If the field name is not in the form_state['values'] then reutrn.
  409. if (!array_key_exists($field_name, $form_state['values'])) {
  410. return FALSE;
  411. }
  412. foreach ($form_state['values'][$field_name] as $langcode => $items) {
  413. if ($child) {
  414. $form_state['values'][$field_name][$langcode][$delta][$child] = $newvalue;
  415. }
  416. else {
  417. $form_state['values'][$field_name][$langcode][$delta]['value'] = $newvalue;
  418. }
  419. }
  420. return TRUE;
  421. }
  422. /**
  423. * Implements hook_field_widget_form_alter().
  424. */
  425. function tripal_chado_field_widget_form_alter(&$element, &$form_state, $context) {
  426. if (array_key_exists('#field_name', $element)) {
  427. $field_name = $element['#field_name'];
  428. $matches = array();
  429. if (preg_match('/(.+?)__(.+?)$/', $field_name, $matches)) {
  430. $tablename = $matches[1];
  431. $colname = $matches[2];
  432. $schema = chado_get_schema($tablename);
  433. // The timelastmodified field exists in many Chado tables. We want
  434. // the form element to update to the most recent time rather than the time
  435. // in the database.
  436. if ($colname == 'timelastmodified' and $schema['fields'][$colname]['type'] == 'datetime') {
  437. // We want the default value for the field to be the current time.
  438. $element['#default_value']['value'] = format_date(time(), 'custom', "Y-m-d H:i:s", 'UTC');
  439. $element['#date_items']['value'] = $element['#default_value']['value'];
  440. }
  441. // We want the date combo fieldset to be collaspible so we will
  442. // add our own theme_wrapper to replace the one added by the date
  443. // module.
  444. if (array_key_exists($colname, $schema['fields']) and $schema['fields'][$colname]['type'] == 'datetime') {
  445. $element['#theme_wrappers'] = array('tripal_chado_date_combo');
  446. }
  447. }
  448. }
  449. }
  450. /**
  451. * Returns a $field_info array for a field based on a database column.
  452. *
  453. */
  454. function tripal_chado_add_bundle_fields_base__fields_defaults($table_name, $schema, $column_name) {
  455. $details = $schema['fields'][$column_name];
  456. // Create an array with information about this field.
  457. $field = array(
  458. 'field_type' => '',
  459. 'widget_type' => '',
  460. 'description' => '',
  461. 'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
  462. 'is_required' => 0,
  463. 'storage' => 'field_chado_storage',
  464. 'widget_settings' => array(
  465. 'display_label' => 1
  466. ),
  467. 'field_settings' => array(
  468. // The table in Chado where this field maps to.
  469. 'chado_table' => $table_name,
  470. // The column in the Chado table that this field maps to.
  471. 'chado_column' => $column_name,
  472. 'semantic_web' => array(
  473. // The type is the term from a vocabulary that desribes this field..
  474. 'type' => '',
  475. // The namepsace for the vocabulary (e.g. 'foaf').
  476. 'ns' => '',
  477. // The URL for the namespace. It must be that the type can be
  478. // appended to the URL.
  479. 'nsurl' => '',
  480. ),
  481. ),
  482. );
  483. // Alter the field info array depending on the column details.
  484. switch($details['type']) {
  485. case 'char':
  486. $field['field_type'] = 'text';
  487. $field['widget_type'] = 'text_textfield';
  488. $field['field_settings']['max_length'] = $details['length'];
  489. break;
  490. case 'varchar':
  491. $field['field_type'] = 'text';
  492. $field['widget_type'] = 'text_textfield';
  493. $field['field_settings']['max_length'] = $details['length'];
  494. break;
  495. case 'text':
  496. $field['field_type'] = 'text';
  497. $field['widget_type'] = 'text_textarea';
  498. $field['field_settings']['max_length'] = 17179869184;
  499. $field['field_settings']['text_processing'] = 1;
  500. $field['format'] = filter_default_format();
  501. break;
  502. case 'blob':
  503. // not sure how to support a blob field.
  504. continue;
  505. break;
  506. case 'int':
  507. $field['field_type'] = 'number_integer';
  508. $field['widget_type'] = 'number';
  509. break;
  510. case 'float':
  511. $field['field_type'] = 'number_float';
  512. $field['widget_type'] = 'number';
  513. $field['field_settings']['precision'] = 10;
  514. $field['field_settings']['scale'] = 2;
  515. $field['field_settings']['decimal_separator'] = '.';
  516. break;
  517. case 'numeric':
  518. $field['field_type'] = 'number_decimal';
  519. $field['widget_type'] = 'number';
  520. break;
  521. case 'serial':
  522. // Serial fields are most likely not needed as a field.
  523. break;
  524. case 'boolean':
  525. $field['field_type'] = 'list_boolean';
  526. $field['widget_type'] = 'options_onoff';
  527. $field['field_settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
  528. break;
  529. case 'datetime':
  530. // Use the Drupal Date and Date API to create the field/widget
  531. $field['field_type'] = 'datetime';
  532. $field['widget_type'] = 'date_select';
  533. $field['widget_settings']['increment'] = 1;
  534. $field['widget_settings']['tz_handling'] = 'none';
  535. $field['widget_settings']['collapsible'] = TRUE;
  536. // TODO: Add settings so that the minutes increment by 1.
  537. // And turn off the timezone, as the Chado field doesn't support it.
  538. break;
  539. }
  540. // Set some default semantic web information
  541. if ($column_name == 'name') {
  542. $field['field_settings']['semantic_web']['type'] = 'name';
  543. $field['field_settings']['semantic_web']['ns'] = 'foaf';
  544. $field['field_settings']['semantic_web']['nsurl'] = 'http://xmlns.com/foaf/0.1/';
  545. }
  546. if ($column_name == 'description' or $column_name == 'definition' or
  547. $column_name == 'comment') {
  548. $field['field_settings']['semantic_web']['type'] = 'description';
  549. $field['field_settings']['semantic_web']['ns'] = 'hydra';
  550. $field['field_settings']['semantic_web']['nsurl'] = 'http://www.w3.org/ns/hydra/core#';
  551. }
  552. //
  553. // GENERIC COLUMNS
  554. //
  555. if ($field['field_settings']['chado_column'] == 'organism_id') {
  556. $field['field_type'] = 'chado_base__organism_id';
  557. $field['widget_type'] = 'chado_base__organism_id_widget';
  558. $field['label'] = 'Organism';
  559. $field['description'] = 'Select an organism.';
  560. $field['field_settings']['semantic_web']['type'] = 'organism';
  561. $field['field_settings']['semantic_web']['ns'] = 'local';
  562. $field['field_settings']['semantic_web']['nsurl'] = '';
  563. }
  564. elseif ($field['field_settings']['chado_column'] =='dbxref_id') {
  565. $field['field_type'] = 'chado_base__dbxref_id';
  566. $field['widget_type'] = 'chado_base_dbxref_id_widget';
  567. $field['label'] = 'Cross Reference';
  568. $field['description'] = 'This record can be cross referenced with a ' .
  569. 'record in another online database. The primary reference is for the ' .
  570. 'most prominent reference. At a minimum, the database and accession ' .
  571. 'must be provided. To remove a set reference, change the database ' .
  572. 'field to "Select a Database".';
  573. }
  574. elseif ($field['label'] == 'Timeaccessioned') {
  575. $field['label'] = 'Time Accessioned';
  576. $field['description'] = 'Please enter the time that this record was first added to the database.';
  577. }
  578. elseif ($field['label'] == 'Timelastmodified') {
  579. $field['label'] = 'Time Last Modified';
  580. $field['description'] = 'Please enter the time that this record was last modified. The default is the current time.';
  581. }
  582. //
  583. // ORGANISM TABLE
  584. //
  585. elseif ($field['field_settings']['chado_table'] == 'organism' and $field['field_settings']['chado_column'] == 'comment') {
  586. $field['label'] = 'Description';
  587. }
  588. //
  589. // FEATURE TABLE
  590. //
  591. elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'uniquename') {
  592. $field['field_type'] = 'text';
  593. $field['widget_type'] = 'text_textfield';
  594. $field['field_settings']['text_processing'] = 0;
  595. $field['field_settings']['semantic_web']['type'] = 'name';
  596. $field['field_settings']['semantic_web']['ns'] = 'foaf';
  597. $field['field_settings']['semantic_web']['nsurl'] = 'http://xmlns.com/foaf/0.1/';
  598. }
  599. elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'md5checksum') {
  600. $field['field_type'] = 'chado_feature__md5checksum';
  601. $field['widget_type'] = 'chado_feature__md5checksum_widget';
  602. $field['label'] = 'MD5 Checksum';
  603. $field['description'] = 'Generate an MD5 checksum for the sequence.';
  604. }
  605. elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'seqlen') {
  606. $field['field_type'] = 'chado_feature__seqlen';
  607. $field['widget_type'] = 'chado_feature__seqlen_widget';
  608. $field['label'] = 'Seqlen';
  609. $field['description'] = 'The length of the residues.';
  610. }
  611. elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'residues') {
  612. $field['field_type'] = 'chado_feature__residues';
  613. $field['widget_type'] = 'chado_feature__residues_widget';
  614. $field['label'] = 'Residues';
  615. $field['description'] = 'Please provide an IUPAC compatible residues for this feature. Spaces and new lines are allowed.';
  616. }
  617. //
  618. // ANALYSIS TABLE
  619. //
  620. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'program') {
  621. $field['field_settings']['semantic_web']['type'] = 'SoftwareApplication';
  622. $field['field_settings']['semantic_web']['ns'] = 'schema';
  623. $field['field_settings']['semantic_web']['nsurl'] = 'https://schema.org/';
  624. $field['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.';
  625. $field['label'] = 'Program, Pipeline, Workflow or Method Name.';
  626. }
  627. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'sourceuri') {
  628. $field['field_type'] = 'text';
  629. $field['widget_type'] = 'text_textfield';
  630. $field['field_settings']['text_processing'] = 0;
  631. $field['label'] = 'Source URL';
  632. $field['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.';
  633. }
  634. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'sourcename') {
  635. $field['label'] = 'Source Name';
  636. $field['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.';
  637. }
  638. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'sourceversion') {
  639. $field['label'] = 'Source Version';
  640. $field['description'] = 'If hte source data set has a version include it here.';
  641. }
  642. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'algorithm') {
  643. $field['label'] = 'Source Version';
  644. $field['description'] = 'The name of the algorithm used to produce the dataset if different from the program.';
  645. }
  646. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'programversion') {
  647. $field['label'] = 'Program Version';
  648. $field['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.';
  649. }
  650. //
  651. // PROJECT TABLE
  652. //
  653. elseif ($field['field_settings']['chado_table'] == 'project' and $field['field_settings']['chado_column'] == 'description') {
  654. $field['label'] = 'Short Description';
  655. }
  656. return $field;
  657. }
  658. /**
  659. * Implements hook_form_FORM_ID_alter().
  660. *
  661. * The field_ui_display_overview_form is used for formatting the display
  662. * or layout of fields attached to an entity and shown on the entity view page.
  663. *
  664. * This function removes the cvterm class and property adder field as those are
  665. * really not meant for users to show or manage.
  666. */
  667. function tripal_chado_form_field_ui_display_overview_form_alter(&$form, &$form_state, $form_id) {
  668. // Remove the kvproperty_addr field as it isn't ever displayed. It's just used
  669. // on the add/edit form of an entity for adding new property fields.
  670. $fields_names = element_children($form['fields']);
  671. foreach ($fields_names as $field_name) {
  672. $field_info = field_info_field($field_name);
  673. if ($field_info['type'] == 'kvproperty_adder') {
  674. unset($form['fields'][$field_name]);
  675. }
  676. if ($field_info['type'] == 'cvterm_class_adder') {
  677. unset($form['fields'][$field_name]);
  678. }
  679. }
  680. }
  681. /**
  682. * Implements hook_form_FORM_ID_alter().
  683. *
  684. * The field_ui_field_overview_form is used for ordering and configuring the
  685. * fields attached to an entity.
  686. *
  687. * This function removes the property adder field as that is really not meant
  688. * for users to show or manage.
  689. */
  690. function tripal_chado_form_field_ui_field_overview_form_alter(&$form, &$form_state, $form_id) {
  691. // Remove the kvproperty_addr field as it isn't ever displayed. It's just used
  692. // on the add/edit form of an entity for adding new property fields.
  693. $fields_names = element_children($form['fields']);
  694. foreach ($fields_names as $field_name) {
  695. $field_info = field_info_field($field_name);
  696. if ($field_info['type'] == 'kvproperty_adder') {
  697. unset($form['fields'][$field_name]);
  698. }
  699. if ($field_info['type'] == 'cvterm_class_adder') {
  700. unset($form['fields'][$field_name]);
  701. }
  702. }
  703. }
  704. /**
  705. * Implements hook_field_is_empty().
  706. */
  707. function tripal_chado_field_is_empty($item, $field) {
  708. // If there is no value field then the field is empty.
  709. if (!array_key_exists('value', $item)) {
  710. return TRUE;
  711. }
  712. // Iterate through all of the fields and if at least one has a value
  713. // the field is not empty.
  714. foreach ($item as $form_field_name => $value) {
  715. if (isset($value) and $value != NULL and $value != '') {
  716. return FALSE;
  717. }
  718. }
  719. // Otherwise, the field is empty.
  720. return TRUE;
  721. }
  722. /**
  723. * Implements hook_add_bundle_fields().
  724. */
  725. function tripal_chado_add_bundle_fields($entity_type, $bundle, $term) {
  726. $bundle_name = $bundle->name;
  727. // This array will hold details that map the bundle to tables in Chado.
  728. $bundle_data = array();
  729. // Get the cvterm that corresponds to this TripalTerm object.
  730. $vocab = entity_load('TripalVocab', array($term->vocab_id));
  731. $vocab = reset($vocab);
  732. $match = array(
  733. 'dbxref_id' => array(
  734. 'db_id' => array(
  735. 'name' => $vocab->namespace,
  736. ),
  737. 'accession' => $term->accession
  738. ),
  739. );
  740. $cvterm = chado_generate_var('cvterm', $match);
  741. // The organism table does not have a type_id so we won't ever find
  742. // a record for it in the tripal_cv_defaults table.
  743. if ($cvterm->name == 'organism') {
  744. $bundle_data = array(
  745. 'cv_id' => $cvterm->cv_id->cv_id,
  746. 'cvterm_id' => $cvterm->cvterm_id,
  747. 'data_table' => 'organism',
  748. 'type_table' => 'organism',
  749. 'field' => '',
  750. );
  751. }
  752. // The analysis table does not have a type_id so we won't ever find
  753. // a record for it in the tripalcv_defaults table.
  754. else if ($cvterm->name == 'analysis') {
  755. $bundle_data = array(
  756. 'cv_id' => $cvterm->cv_id->cv_id,
  757. 'cvterm_id' => $cvterm->cvterm_id,
  758. 'data_table' => 'analysis',
  759. 'type_table' => 'analysis',
  760. 'field' => '',
  761. );
  762. }
  763. else if ($cvterm->name == 'project') {
  764. $bundle_data = array(
  765. 'cv_id' => $cvterm->cv_id->cv_id,
  766. 'cvterm_id' => $cvterm->cvterm_id,
  767. 'data_table' => 'project',
  768. 'type_table' => 'project',
  769. 'field' => '',
  770. );
  771. }
  772. else {
  773. // TODO: WHAT TO DO IF A VOCABULARY IS USED AS A DEFAULT FOR MULTIPLE
  774. // TABLES.
  775. // Look to see if this vocabulary is used as a default for any table.
  776. $default = db_select('tripal_cv_defaults', 't')
  777. ->fields('t')
  778. ->condition('cv_id', $cvterm->cv_id->cv_id)
  779. ->execute()
  780. ->fetchObject();
  781. if ($default) {
  782. $bundle_data = array(
  783. 'cv_id' => $cvterm->cv_id->cv_id,
  784. 'cvterm_id' => $cvterm->cvterm_id,
  785. 'data_table' => $default->table_name,
  786. 'type_table' => $default->table_name,
  787. 'field' => $default->field_name,
  788. );
  789. }
  790. }
  791. // Save the mapping information so that we can reuse it when we need to
  792. // look things up for later for an entity
  793. tripal_set_bundle_variable('chado_cvterm_id', $bundle->id, $bundle_data['cvterm_id']);
  794. tripal_set_bundle_variable('chado_table', $bundle->id, $bundle_data['data_table']);
  795. tripal_set_bundle_variable('chado_column', $bundle->id, $bundle_data['field']);
  796. //////////////////////////////////////////////////////////////////////////////
  797. // ADD FIELDS TO BUNDLE
  798. ////////////////////////////////////////////////////////////////////////////
  799. ////
  800. //
  801. // Base table fields.
  802. //
  803. // Adds the fields for the base table to the entity. Adds fields
  804. // for all columns including FK fields. Excludes primary key and the
  805. // type_id field (that's inherent in the bundle).
  806. tripal_chado_add_bundle_fields_base__fields($entity_type, $bundle_name, $bundle_data);
  807. ////
  808. //
  809. // Property table fields.
  810. //
  811. // Check to see if there are any property tables with FKs to this
  812. // base table. If so, add the fields for that type of table.
  813. $prop_table = $bundle_data['data_table'] . 'prop';
  814. if (chado_table_exists($prop_table)) {
  815. tripal_chado_add_bundle_fields_linker__prop_adder_field($entity_type, $bundle_name, $prop_table, $bundle_data['data_table']);
  816. }
  817. ////
  818. //
  819. // Dbxref table fields.
  820. //
  821. // Check to see if there are any dbxref tables with FKs to this
  822. // base table. If so, add the fields for that type of table.
  823. $dbxref_table = $bundle_data['data_table'] . '_dbxref';
  824. if (chado_table_exists($dbxref_table)) {
  825. tripal_chado_add_bundle_fields_linker__dbxref_field($entity_type, $bundle_name, $dbxref_table, $bundle_data['data_table']);
  826. }
  827. ////
  828. //
  829. // Cvterm table fields.
  830. //
  831. // Check to see if there are any cvterm tables with FKs to this
  832. // base table. If so, add the fields for that type of table.
  833. $cvterm_table = $bundle_data['data_table'] . '_cvterm';
  834. if (chado_table_exists($cvterm_table)) {
  835. tripal_chado_add_bundle_fields_linker__cvterm_adder_field($entity_type, $bundle_name, $cvterm_table, $bundle_data['data_table']);
  836. }
  837. ////
  838. //
  839. // Synonym table fields.
  840. //
  841. // Check to see if there are any synonym tables with FKs to this
  842. // base table. If so, add the fields for that type of table.
  843. $syn_table = $bundle_data['data_table'] . '_synonym';
  844. if (chado_table_exists($syn_table)) {
  845. tripal_chado_add_bundle_fields_linker__synonym_field($entity_type, $bundle_name, $syn_table, $bundle_data['data_table']);
  846. }
  847. ////
  848. //
  849. // Pub table fields.
  850. //
  851. // Check to see if there are any pub tables with FKs to this
  852. // base table. If so, add the fields for that type of table.
  853. $pub_table = $bundle_data['data_table'] . '_pub';
  854. if (chado_table_exists($pub_table)) {
  855. tripal_chado_add_bundle_fields_linker__pub_field($entity_type, $bundle_name, $pub_table, $bundle_data['data_table']);
  856. }
  857. }
  858. /**
  859. * Adds the fields for managing xrefs that are stored in a [base]_dbxref table.
  860. *
  861. * @param $entity_type
  862. * @param $bundle_name
  863. * @param $base_table
  864. * @param $dbxref_table
  865. */
  866. function tripal_chado_add_bundle_fields_linker__dbxref_field($entity_type_name, $bundle_name, $dbxref_table, $base_table) {
  867. // We already have a dbxref_id field.
  868. $field_name = $dbxref_table;
  869. $schema = chado_get_schema($dbxref_table);
  870. $pkey = $schema['primary key'][0];
  871. // Initialize the field array.
  872. $field_info = array(
  873. 'field_type' => 'chado_base__dbxref_id',
  874. 'widget_type' => 'chado_base__dbxref_id_widget',
  875. 'widget_settings' => array('display_label' => 1),
  876. 'description' => '',
  877. 'label' => 'Cross References',
  878. 'is_required' => 0,
  879. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  880. 'storage' => 'field_chado_storage',
  881. 'field_settings' => array(
  882. // The Chado table that this field maps to.
  883. 'chado_table' => $dbxref_table,
  884. // The column in the chado table that this field maps to.
  885. 'chado_column' => $pkey,
  886. // The base table that this field is connected to.
  887. 'base_table' => $base_table,
  888. 'semantic_web' => array(
  889. // The type is the term from a vocabulary that desribes this field..
  890. 'type' => '',
  891. // The namepsace for the vocabulary (e.g. 'foaf').
  892. 'ns' => '',
  893. // The URL for the namespace. It must be that the type can be
  894. // appended to the URL.
  895. 'nsurl' => '',
  896. ),
  897. ),
  898. );
  899. // If the base table has a 'dbxref_id' then change the label to
  900. // indicate these are secondary cross references.
  901. $schema = chado_get_schema($base_table);
  902. if (array_key_exists('dbxref_id', $schema['fields'])) {
  903. $field_info['label'] = 'Secondary Cross References';
  904. }
  905. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  906. }
  907. /**
  908. * Adds the fields for managing xrefs that are stored in a [base]_dbxref table.
  909. *
  910. * @param $entity_type
  911. * @param $bundle_name
  912. * @param $base_table
  913. * @param $dbxref_table
  914. */
  915. function tripal_chado_add_bundle_fields_linker__synonym_field($entity_type_name, $bundle_name, $syn_table, $base_table) {
  916. // We already have a dbxref_id field.
  917. $field_name = $syn_table;
  918. $schema = chado_get_schema($syn_table);
  919. $pkey = $schema['primary key'][0];
  920. // Initialize the field array.
  921. $field_info = array(
  922. 'field_type' => 'chado_linker__synonym',
  923. 'widget_type' => 'chado_linker__synonym_widget',
  924. 'widget_settings' => array('display_label' => 1),
  925. 'description' => '',
  926. 'label' => 'Synonyms',
  927. 'is_required' => 0,
  928. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  929. 'storage' => 'field_chado_storage',
  930. 'field_settings' => array(
  931. // The Chado table that this field maps to.
  932. 'chado_table' => $syn_table,
  933. // The column in the chado table that this field maps to.
  934. 'chado_column' => $pkey,
  935. // The base table that this field is connected to.
  936. 'base_table' => $base_table,
  937. 'semantic_web' => array(
  938. // The type is the term from a vocabulary that desribes this field..
  939. 'type' => '',
  940. // The namepsace for the vocabulary (e.g. 'foaf').
  941. 'ns' => '',
  942. // The URL for the namespace. It must be that the type can be
  943. // appended to the URL.
  944. 'nsurl' => '',
  945. ),
  946. ),
  947. );
  948. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  949. }
  950. /**
  951. * Adds the fields for managing xrefs that are stored in a [base]_dbxref table.
  952. *
  953. * @param $entity_type
  954. * @param $bundle_name
  955. * @param $base_table
  956. * @param $dbxref_table
  957. */
  958. function tripal_chado_add_bundle_fields_linker__pub_field($entity_type_name, $bundle_name, $pub_table, $base_table) {
  959. // We already have a dbxref_id field.
  960. $field_name = $pub_table;
  961. $schema = chado_get_schema($pub_table);
  962. $pkey = $schema['primary key'][0];
  963. // Initialize the field array.
  964. $field_info = array(
  965. 'field_type' => 'chado_linker__pub',
  966. 'widget_type' => 'chado_linker__pub_widget',
  967. 'widget_settings' => array('display_label' => 1),
  968. 'description' => '',
  969. 'label' => 'Publications',
  970. 'is_required' => 0,
  971. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  972. 'storage' => 'field_chado_storage',
  973. 'field_settings' => array(
  974. // The Chado table that this field maps to.
  975. 'chado_table' => $pub_table,
  976. // The column in the chado table that this field maps to.
  977. 'chado_column' => $pkey,
  978. // The base table that this field is connected to.
  979. 'base_table' => $base_table,
  980. 'semantic_web' => array(
  981. // The type is the term from a vocabulary that desribes this field..
  982. 'type' => '',
  983. // The namepsace for the vocabulary (e.g. 'foaf').
  984. 'ns' => '',
  985. // The URL for the namespace. It must be that the type can be
  986. // appended to the URL.
  987. 'nsurl' => '',
  988. ),
  989. ),
  990. );
  991. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  992. }
  993. /**
  994. * Adds the fields for managing properties that are stored in a prop table.
  995. *
  996. * @param $entity_type_name
  997. * @param $bundle_name
  998. * @param $kv_table
  999. */
  1000. function tripal_chado_add_bundle_fields_linker__prop_adder_field($entity_type_name, $bundle_name, $kv_table, $base_table) {
  1001. $field_name = $kv_table;
  1002. // Initialize the field array.
  1003. $field_info = array(
  1004. 'field_type' => 'chado_linker__prop_adder',
  1005. 'widget_type' => 'chado_linker__prop_adder_widget',
  1006. 'field_settings' => array(
  1007. 'base_table' => $base_table,
  1008. ),
  1009. 'storage' => 'field_chado_storage',
  1010. 'widget_settings' => array('display_label' => 1),
  1011. 'description' => '',
  1012. 'label' => 'Additional Properties',
  1013. 'is_required' => 0,
  1014. );
  1015. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  1016. }
  1017. /**
  1018. * Adds the fields for managing properties that are stored in a prop table.
  1019. *
  1020. * @param $entity_type_name
  1021. * @param $bundle_name
  1022. * @param $kv_table
  1023. */
  1024. function tripal_chado_add_bundle_fields_linker__cvterm_adder_field($entity_type_name, $bundle_name, $cvterm_table, $base_table) {
  1025. // First add a generic property field so that users can add new property types.
  1026. $field_name = $cvterm_table;
  1027. // Initialize the field array.
  1028. $field_info = array(
  1029. 'field_type' => 'chado_linker__cvterm_adder',
  1030. 'widget_type' => 'chado_linker__cvterm_adder_widget',
  1031. 'field_settings' => array(
  1032. 'base_table' => $base_table,
  1033. ),
  1034. 'storage' => 'field_chado_storage',
  1035. 'widget_settings' => array('display_label' => 1),
  1036. 'description' => '',
  1037. 'label' => 'Additional Annotation Types',
  1038. 'is_required' => 0,
  1039. );
  1040. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  1041. }
  1042. /**
  1043. * Adds the fields for the base table to the entity.
  1044. */
  1045. function tripal_chado_add_bundle_fields_base__fields($entity_type_name, $bundle_name, $bundle_data) {
  1046. $table_name = $bundle_data['data_table'];
  1047. $type_table = $bundle_data['type_table'];
  1048. $type_field = $bundle_data['field'];
  1049. // Iterate through the columns of the table and see if fields have been
  1050. // created for each one. If not, then create them.
  1051. $schema = chado_get_schema($table_name);
  1052. $columns = $schema['fields'];
  1053. foreach ($columns as $column_name => $details) {
  1054. $field_name = $table_name . '__' . $column_name;
  1055. // Skip the primary key field.
  1056. if ($column_name == $schema['primary key'][0]) {
  1057. continue;
  1058. }
  1059. // Skip the type field.
  1060. if ($table_name == $type_table and $column_name == $type_field) {
  1061. continue;
  1062. }
  1063. // Get the field defaults for this column.
  1064. $field_info = tripal_chado_add_bundle_fields_base__fields_defaults($table_name, $schema, $column_name);
  1065. // TODO: add in a call to drupal_alter to allow other modules to change
  1066. // the field settings.
  1067. // Determine if the field is required.
  1068. if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
  1069. $field_info['is_required'] = array_key_exists('default', $details) ? 0 : 1;
  1070. }
  1071. // If we don't have a field type then we don't need to create a field.
  1072. if (!$field_info['field_type']) {
  1073. // If we don't have a field type but it is required and doesn't have
  1074. // a default value then we are in trouble.
  1075. if ($field_info['is_required'] and !array_key_exists('default', $details)) {
  1076. throw new Exception(t('The %table.%field type, %type, is not yet supported for Entity fields, but it is required,',
  1077. array('%table' => $table_name, '%field' => $column_name, '%type' => $details['type'])));
  1078. }
  1079. continue;
  1080. }
  1081. // If this field is a foreign key field then we will have a custom field.
  1082. $is_fk = FALSE;
  1083. if (array_key_exists('foreign keys', $schema)) {
  1084. foreach ($schema['foreign keys'] as $remote_table => $fk_details) {
  1085. if (array_key_exists($column_name, $fk_details['columns'])) {
  1086. $is_fk = TRUE;
  1087. }
  1088. }
  1089. }
  1090. // Add the field to the bundle.
  1091. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  1092. }
  1093. }