tripal_chado.fields.inc 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  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 'chado_base__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_name = $instance['field_name'];
  362. $field_type = $field['type'];
  363. form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/' . $field_type);
  364. module_load_include('inc', 'tripal_chado', 'includes/fields/' . $field_name);
  365. $function = $field_type . '_widget';
  366. if (function_exists($function)) {
  367. $function($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
  368. }
  369. return $widget;
  370. }
  371. /**
  372. * Returns the values of the field from the $form_state.
  373. */
  374. function tripal_chado_get_field_form_values($field_name, $form_state, $delta = 0, $child = NULL) {
  375. $value = NULL;
  376. // The form_state must have the 'values' key. If not then just return.
  377. if (!array_key_exists('values', $form_state)) {
  378. return $value;
  379. }
  380. // If the field name is not in the form_state['values'] then return.
  381. if (!array_key_exists($field_name, $form_state['values'])) {
  382. return $value;
  383. }
  384. // Iterate through the values looking for the field_name provided.
  385. foreach ($form_state['values'][$field_name] as $langcode => $items) {
  386. if (!array_key_exists($delta, $items)) {
  387. continue;
  388. }
  389. $item = $items[$delta];
  390. if ($child){
  391. if(array_key_exists($child, $item) and $item[$child] != '') {
  392. $value = $item[$child];
  393. }
  394. }
  395. else {
  396. $value = $item['value'];
  397. }
  398. }
  399. return $value;
  400. }
  401. /**
  402. * Sets the values of the field from the $form_state.
  403. */
  404. function tripal_chado_set_field_form_values($field_name, &$form_state, $newvalue, $delta = 0, $child = NULL) {
  405. // The form_state must have the 'values' key. If not then just return.
  406. if (!array_key_exists('values', $form_state)) {
  407. return FALSE;
  408. }
  409. // If the field name is not in the form_state['values'] then reutrn.
  410. if (!array_key_exists($field_name, $form_state['values'])) {
  411. return FALSE;
  412. }
  413. foreach ($form_state['values'][$field_name] as $langcode => $items) {
  414. if ($child) {
  415. $form_state['values'][$field_name][$langcode][$delta][$child] = $newvalue;
  416. }
  417. else {
  418. $form_state['values'][$field_name][$langcode][$delta]['value'] = $newvalue;
  419. }
  420. }
  421. return TRUE;
  422. }
  423. /**
  424. * Implements hook_field_widget_form_alter().
  425. */
  426. function tripal_chado_field_widget_form_alter(&$element, &$form_state, $context) {
  427. if (array_key_exists('#field_name', $element)) {
  428. $field_name = $element['#field_name'];
  429. $matches = array();
  430. if (preg_match('/(.+?)__(.+?)$/', $field_name, $matches)) {
  431. $tablename = $matches[1];
  432. $colname = $matches[2];
  433. $schema = chado_get_schema($tablename);
  434. // The timelastmodified field exists in many Chado tables. We want
  435. // the form element to update to the most recent time rather than the time
  436. // in the database.
  437. if ($colname == 'timelastmodified' and $schema['fields'][$colname]['type'] == 'datetime') {
  438. // We want the default value for the field to be the current time.
  439. $element['#default_value']['value'] = format_date(time(), 'custom', "Y-m-d H:i:s", 'UTC');
  440. $element['#date_items']['value'] = $element['#default_value']['value'];
  441. }
  442. // We want the date combo fieldset to be collaspible so we will
  443. // add our own theme_wrapper to replace the one added by the date
  444. // module.
  445. if (array_key_exists($colname, $schema['fields']) and $schema['fields'][$colname]['type'] == 'datetime') {
  446. $element['#theme_wrappers'] = array('tripal_chado_date_combo');
  447. }
  448. }
  449. }
  450. }
  451. /**
  452. * Returns a $field_info array for a field based on a database column.
  453. *
  454. */
  455. function tripal_chado_add_bundle_fields_base__fields_defaults($table_name, $schema, $column_name) {
  456. $details = $schema['fields'][$column_name];
  457. // Create an array with information about this field.
  458. $field = array(
  459. 'field_type' => '',
  460. 'widget_type' => '',
  461. 'description' => '',
  462. 'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
  463. 'is_required' => 0,
  464. 'storage' => 'field_chado_storage',
  465. 'widget_settings' => array(
  466. 'display_label' => 1
  467. ),
  468. 'field_settings' => array(
  469. // The table in Chado where this field maps to.
  470. 'chado_table' => $table_name,
  471. // The column in the Chado table that this field maps to.
  472. 'chado_column' => $column_name,
  473. 'semantic_web' => array(
  474. // The type is the term from a vocabulary that desribes this field..
  475. 'type' => '',
  476. // The namepsace for the vocabulary (e.g. 'foaf').
  477. 'ns' => '',
  478. // The URL for the namespace. It must be that the type can be
  479. // appended to the URL.
  480. 'nsurl' => '',
  481. ),
  482. ),
  483. );
  484. // Alter the field info array depending on the column details.
  485. switch($details['type']) {
  486. case 'char':
  487. $field['field_type'] = 'text';
  488. $field['widget_type'] = 'text_textfield';
  489. $field['field_settings']['max_length'] = $details['length'];
  490. break;
  491. case 'varchar':
  492. $field['field_type'] = 'text';
  493. $field['widget_type'] = 'text_textfield';
  494. $field['field_settings']['max_length'] = $details['length'];
  495. break;
  496. case 'text':
  497. $field['field_type'] = 'text';
  498. $field['widget_type'] = 'text_textarea';
  499. $field['field_settings']['max_length'] = 17179869184;
  500. $field['field_settings']['text_processing'] = 1;
  501. $field['format'] = filter_default_format();
  502. break;
  503. case 'blob':
  504. // not sure how to support a blob field.
  505. continue;
  506. break;
  507. case 'int':
  508. $field['field_type'] = 'number_integer';
  509. $field['widget_type'] = 'number';
  510. break;
  511. case 'float':
  512. $field['field_type'] = 'number_float';
  513. $field['widget_type'] = 'number';
  514. $field['field_settings']['precision'] = 10;
  515. $field['field_settings']['scale'] = 2;
  516. $field['field_settings']['decimal_separator'] = '.';
  517. break;
  518. case 'numeric':
  519. $field['field_type'] = 'number_decimal';
  520. $field['widget_type'] = 'number';
  521. break;
  522. case 'serial':
  523. // Serial fields are most likely not needed as a field.
  524. break;
  525. case 'boolean':
  526. $field['field_type'] = 'list_boolean';
  527. $field['widget_type'] = 'options_onoff';
  528. $field['field_settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
  529. break;
  530. case 'datetime':
  531. // Use the Drupal Date and Date API to create the field/widget
  532. $field['field_type'] = 'datetime';
  533. $field['widget_type'] = 'date_select';
  534. $field['widget_settings']['increment'] = 1;
  535. $field['widget_settings']['tz_handling'] = 'none';
  536. $field['widget_settings']['collapsible'] = TRUE;
  537. // TODO: Add settings so that the minutes increment by 1.
  538. // And turn off the timezone, as the Chado field doesn't support it.
  539. break;
  540. }
  541. // Set some default semantic web information
  542. if ($column_name == 'name') {
  543. $field['field_settings']['semantic_web']['type'] = 'name';
  544. $field['field_settings']['semantic_web']['ns'] = 'foaf';
  545. $field['field_settings']['semantic_web']['nsurl'] = 'http://xmlns.com/foaf/0.1/';
  546. }
  547. if ($column_name == 'description' or $column_name == 'definition' or
  548. $column_name == 'comment') {
  549. $field['field_settings']['semantic_web']['type'] = 'description';
  550. $field['field_settings']['semantic_web']['ns'] = 'hydra';
  551. $field['field_settings']['semantic_web']['nsurl'] = 'http://www.w3.org/ns/hydra/core#';
  552. }
  553. //
  554. // GENERIC COLUMNS
  555. //
  556. if ($field['field_settings']['chado_column'] == 'organism_id') {
  557. $field['field_type'] = 'chado_base__organism_id';
  558. $field['widget_type'] = 'chado_base__organism_id_widget';
  559. $field['label'] = 'Organism';
  560. $field['description'] = 'Select an organism.';
  561. $field['field_settings']['semantic_web']['type'] = 'organism';
  562. $field['field_settings']['semantic_web']['ns'] = 'local';
  563. $field['field_settings']['semantic_web']['nsurl'] = '';
  564. }
  565. elseif ($field['field_settings']['chado_column'] =='dbxref_id') {
  566. $field['field_type'] = 'chado_base__dbxref_id';
  567. $field['widget_type'] = 'chado_base_dbxref_id_widget';
  568. $field['label'] = 'Cross Reference';
  569. $field['description'] = 'This record can be cross referenced with a ' .
  570. 'record in another online database. The primary reference is for the ' .
  571. 'most prominent reference. At a minimum, the database and accession ' .
  572. 'must be provided. To remove a set reference, change the database ' .
  573. 'field to "Select a Database".';
  574. }
  575. elseif ($field['label'] == 'Timeaccessioned') {
  576. $field['label'] = 'Time Accessioned';
  577. $field['description'] = 'Please enter the time that this record was first added to the database.';
  578. }
  579. elseif ($field['label'] == 'Timelastmodified') {
  580. $field['label'] = 'Time Last Modified';
  581. $field['description'] = 'Please enter the time that this record was last modified. The default is the current time.';
  582. }
  583. //
  584. // ORGANISM TABLE
  585. //
  586. elseif ($field['field_settings']['chado_table'] == 'organism' and $field['field_settings']['chado_column'] == 'comment') {
  587. $field['label'] = 'Description';
  588. }
  589. //
  590. // FEATURE TABLE
  591. //
  592. elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'uniquename') {
  593. $field['field_type'] = 'text';
  594. $field['widget_type'] = 'text_textfield';
  595. $field['field_settings']['text_processing'] = 0;
  596. $field['field_settings']['semantic_web']['type'] = 'name';
  597. $field['field_settings']['semantic_web']['ns'] = 'foaf';
  598. $field['field_settings']['semantic_web']['nsurl'] = 'http://xmlns.com/foaf/0.1/';
  599. }
  600. elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'md5checksum') {
  601. $field['field_type'] = 'chado_feature__md5checksum';
  602. $field['widget_type'] = 'chado_feature__md5checksum_widget';
  603. $field['label'] = 'MD5 Checksum';
  604. $field['description'] = 'Generate an MD5 checksum for the sequence.';
  605. }
  606. elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'seqlen') {
  607. $field['field_type'] = 'chado_feature__seqlen';
  608. $field['widget_type'] = 'chado_feature__seqlen_widget';
  609. $field['label'] = 'Seqlen';
  610. $field['description'] = 'The length of the residues.';
  611. }
  612. elseif ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'residues') {
  613. $field['field_type'] = 'chado_feature__residues';
  614. $field['widget_type'] = 'chado_feature__residues_widget';
  615. $field['label'] = 'Residues';
  616. $field['description'] = 'Please provide an IUPAC compatible residues for this feature. Spaces and new lines are allowed.';
  617. }
  618. //
  619. // ANALYSIS TABLE
  620. //
  621. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'program') {
  622. $field['field_settings']['semantic_web']['type'] = 'SoftwareApplication';
  623. $field['field_settings']['semantic_web']['ns'] = 'schema';
  624. $field['field_settings']['semantic_web']['nsurl'] = 'https://schema.org/';
  625. $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.';
  626. $field['label'] = 'Program, Pipeline, Workflow or Method Name.';
  627. }
  628. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'sourceuri') {
  629. $field['field_type'] = 'text';
  630. $field['widget_type'] = 'text_textfield';
  631. $field['field_settings']['text_processing'] = 0;
  632. $field['label'] = 'Source URL';
  633. $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.';
  634. }
  635. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'sourcename') {
  636. $field['label'] = 'Source Name';
  637. $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.';
  638. }
  639. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'sourceversion') {
  640. $field['label'] = 'Source Version';
  641. $field['description'] = 'If hte source data set has a version include it here.';
  642. }
  643. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'algorithm') {
  644. $field['label'] = 'Source Version';
  645. $field['description'] = 'The name of the algorithm used to produce the dataset if different from the program.';
  646. }
  647. elseif ($field['field_settings']['chado_table'] == 'analysis' and $field['field_settings']['chado_column'] == 'programversion') {
  648. $field['label'] = 'Program Version';
  649. $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.';
  650. }
  651. //
  652. // PROJECT TABLE
  653. //
  654. elseif ($field['field_settings']['chado_table'] == 'project' and $field['field_settings']['chado_column'] == 'description') {
  655. $field['label'] = 'Short Description';
  656. }
  657. return $field;
  658. }
  659. /**
  660. * Implements hook_form_FORM_ID_alter().
  661. *
  662. * The field_ui_display_overview_form is used for formatting the display
  663. * or layout of fields attached to an entity and shown on the entity view page.
  664. *
  665. * This function removes the cvterm class and property adder field as those are
  666. * really not meant for users to show or manage.
  667. */
  668. function tripal_chado_form_field_ui_display_overview_form_alter(&$form, &$form_state, $form_id) {
  669. // Remove the kvproperty_addr field as it isn't ever displayed. It's just used
  670. // on the add/edit form of an entity for adding new property fields.
  671. $fields_names = element_children($form['fields']);
  672. foreach ($fields_names as $field_name) {
  673. $field_info = field_info_field($field_name);
  674. if ($field_info['type'] == 'kvproperty_adder') {
  675. unset($form['fields'][$field_name]);
  676. }
  677. if ($field_info['type'] == 'cvterm_class_adder') {
  678. unset($form['fields'][$field_name]);
  679. }
  680. }
  681. }
  682. /**
  683. * Implements hook_form_FORM_ID_alter().
  684. *
  685. * The field_ui_field_overview_form is used for ordering and configuring the
  686. * fields attached to an entity.
  687. *
  688. * This function removes the property adder field as that is really not meant
  689. * for users to show or manage.
  690. */
  691. function tripal_chado_form_field_ui_field_overview_form_alter(&$form, &$form_state, $form_id) {
  692. // Remove the kvproperty_addr field as it isn't ever displayed. It's just used
  693. // on the add/edit form of an entity for adding new property fields.
  694. $fields_names = element_children($form['fields']);
  695. foreach ($fields_names as $field_name) {
  696. $field_info = field_info_field($field_name);
  697. if ($field_info['type'] == 'kvproperty_adder') {
  698. unset($form['fields'][$field_name]);
  699. }
  700. if ($field_info['type'] == 'cvterm_class_adder') {
  701. unset($form['fields'][$field_name]);
  702. }
  703. }
  704. }
  705. /**
  706. * Implements hook_field_is_empty().
  707. */
  708. function tripal_chado_field_is_empty($item, $field) {
  709. // If there is no value field then the field is empty.
  710. if (!array_key_exists('value', $item)) {
  711. return TRUE;
  712. }
  713. // Iterate through all of the fields and if at least one has a value
  714. // the field is not empty.
  715. foreach ($item as $form_field_name => $value) {
  716. if (isset($value) and $value != NULL and $value != '') {
  717. return FALSE;
  718. }
  719. }
  720. // Otherwise, the field is empty.
  721. return TRUE;
  722. }
  723. /**
  724. * Implements hook_add_bundle_fields().
  725. */
  726. function tripal_chado_add_bundle_fields($entity_type, $bundle, $term) {
  727. $bundle_name = $bundle->name;
  728. // This array will hold details that map the bundle to tables in Chado.
  729. $bundle_data = array();
  730. // Get the cvterm that corresponds to this TripalTerm object.
  731. $vocab = entity_load('TripalVocab', array($term->vocab_id));
  732. $vocab = reset($vocab);
  733. $match = array(
  734. 'dbxref_id' => array(
  735. 'db_id' => array(
  736. 'name' => $vocab->namespace,
  737. ),
  738. 'accession' => $term->accession
  739. ),
  740. );
  741. $cvterm = chado_generate_var('cvterm', $match);
  742. // The organism table does not have a type_id so we won't ever find
  743. // a record for it in the tripal_cv_defaults table.
  744. if ($cvterm->name == 'organism') {
  745. $bundle_data = array(
  746. 'cv_id' => $cvterm->cv_id->cv_id,
  747. 'cvterm_id' => $cvterm->cvterm_id,
  748. 'data_table' => 'organism',
  749. 'type_table' => 'organism',
  750. 'field' => '',
  751. );
  752. }
  753. // The analysis table does not have a type_id so we won't ever find
  754. // a record for it in the tripalcv_defaults table.
  755. else if ($cvterm->name == 'analysis') {
  756. $bundle_data = array(
  757. 'cv_id' => $cvterm->cv_id->cv_id,
  758. 'cvterm_id' => $cvterm->cvterm_id,
  759. 'data_table' => 'analysis',
  760. 'type_table' => 'analysis',
  761. 'field' => '',
  762. );
  763. }
  764. else if ($cvterm->name == 'project') {
  765. $bundle_data = array(
  766. 'cv_id' => $cvterm->cv_id->cv_id,
  767. 'cvterm_id' => $cvterm->cvterm_id,
  768. 'data_table' => 'project',
  769. 'type_table' => 'project',
  770. 'field' => '',
  771. );
  772. }
  773. else {
  774. // TODO: WHAT TO DO IF A VOCABULARY IS USED AS A DEFAULT FOR MULTIPLE
  775. // TABLES.
  776. // Look to see if this vocabulary is used as a default for any table.
  777. $default = db_select('tripal_cv_defaults', 't')
  778. ->fields('t')
  779. ->condition('cv_id', $cvterm->cv_id->cv_id)
  780. ->execute()
  781. ->fetchObject();
  782. if ($default) {
  783. $bundle_data = array(
  784. 'cv_id' => $cvterm->cv_id->cv_id,
  785. 'cvterm_id' => $cvterm->cvterm_id,
  786. 'data_table' => $default->table_name,
  787. 'type_table' => $default->table_name,
  788. 'field' => $default->field_name,
  789. );
  790. }
  791. }
  792. // Save the mapping information so that we can reuse it when we need to
  793. // look things up for later for an entity
  794. tripal_set_bundle_variable('chado_cvterm_id', $bundle->id, $bundle_data['cvterm_id']);
  795. tripal_set_bundle_variable('chado_table', $bundle->id, $bundle_data['data_table']);
  796. tripal_set_bundle_variable('chado_column', $bundle->id, $bundle_data['field']);
  797. //////////////////////////////////////////////////////////////////////////////
  798. // ADD FIELDS TO BUNDLE
  799. ////////////////////////////////////////////////////////////////////////////
  800. ////
  801. //
  802. // Base table fields.
  803. //
  804. // Adds the fields for the base table to the entity. Adds fields
  805. // for all columns including FK fields. Excludes primary key and the
  806. // type_id field (that's inherent in the bundle).
  807. tripal_chado_add_bundle_fields_base__fields($entity_type, $bundle_name, $bundle_data);
  808. ////
  809. //
  810. // Property table fields.
  811. //
  812. // Check to see if there are any property tables with FKs to this
  813. // base table. If so, add the fields for that type of table.
  814. $prop_table = $bundle_data['data_table'] . 'prop';
  815. if (chado_table_exists($prop_table)) {
  816. tripal_chado_add_bundle_fields_linker__prop_adder_field($entity_type, $bundle_name, $prop_table, $bundle_data['data_table']);
  817. }
  818. ////
  819. //
  820. // Dbxref table fields.
  821. //
  822. // Check to see if there are any dbxref tables with FKs to this
  823. // base table. If so, add the fields for that type of table.
  824. $dbxref_table = $bundle_data['data_table'] . '_dbxref';
  825. if (chado_table_exists($dbxref_table)) {
  826. tripal_chado_add_bundle_fields_linker__dbxref_field($entity_type, $bundle_name, $dbxref_table, $bundle_data['data_table']);
  827. }
  828. ////
  829. //
  830. // Cvterm table fields.
  831. //
  832. // Check to see if there are any cvterm tables with FKs to this
  833. // base table. If so, add the fields for that type of table.
  834. $cvterm_table = $bundle_data['data_table'] . '_cvterm';
  835. if (chado_table_exists($cvterm_table)) {
  836. tripal_chado_add_bundle_fields_linker__cvterm_adder_field($entity_type, $bundle_name, $cvterm_table, $bundle_data['data_table']);
  837. }
  838. ////
  839. //
  840. // Synonym table fields.
  841. //
  842. // Check to see if there are any synonym tables with FKs to this
  843. // base table. If so, add the fields for that type of table.
  844. $syn_table = $bundle_data['data_table'] . '_synonym';
  845. if (chado_table_exists($syn_table)) {
  846. tripal_chado_add_bundle_fields_linker__synonym_field($entity_type, $bundle_name, $syn_table, $bundle_data['data_table']);
  847. }
  848. ////
  849. //
  850. // Pub table fields.
  851. //
  852. // Check to see if there are any pub tables with FKs to this
  853. // base table. If so, add the fields for that type of table.
  854. $pub_table = $bundle_data['data_table'] . '_pub';
  855. if (chado_table_exists($pub_table)) {
  856. tripal_chado_add_bundle_fields_linker__pub_field($entity_type, $bundle_name, $pub_table, $bundle_data['data_table']);
  857. }
  858. }
  859. /**
  860. * Adds the fields for managing xrefs that are stored in a [base]_dbxref table.
  861. *
  862. * @param $entity_type
  863. * @param $bundle_name
  864. * @param $base_table
  865. * @param $dbxref_table
  866. */
  867. function tripal_chado_add_bundle_fields_linker__dbxref_field($entity_type_name, $bundle_name, $dbxref_table, $base_table) {
  868. // We already have a dbxref_id field.
  869. $field_name = $dbxref_table;
  870. $schema = chado_get_schema($dbxref_table);
  871. $pkey = $schema['primary key'][0];
  872. // Initialize the field array.
  873. $field_info = array(
  874. 'field_type' => 'chado_linker__dbxref',
  875. 'widget_type' => 'chado_linker__dbxref_widget',
  876. 'widget_settings' => array('display_label' => 1),
  877. 'description' => '',
  878. 'label' => 'Cross References',
  879. 'is_required' => 0,
  880. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  881. 'storage' => 'field_chado_storage',
  882. 'field_settings' => array(
  883. // The Chado table that this field maps to.
  884. 'chado_table' => $dbxref_table,
  885. // The column in the chado table that this field maps to.
  886. 'chado_column' => $pkey,
  887. // The base table that this field is connected to.
  888. 'base_table' => $base_table,
  889. 'semantic_web' => array(
  890. // The type is the term from a vocabulary that desribes this field..
  891. 'type' => '',
  892. // The namepsace for the vocabulary (e.g. 'foaf').
  893. 'ns' => '',
  894. // The URL for the namespace. It must be that the type can be
  895. // appended to the URL.
  896. 'nsurl' => '',
  897. ),
  898. ),
  899. );
  900. // If the base table has a 'dbxref_id' then change the label to
  901. // indicate these are secondary cross references.
  902. $schema = chado_get_schema($base_table);
  903. if (array_key_exists('dbxref_id', $schema['fields'])) {
  904. $field_info['label'] = 'Secondary Cross References';
  905. }
  906. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  907. }
  908. /**
  909. * Adds the fields for managing xrefs that are stored in a [base]_dbxref table.
  910. *
  911. * @param $entity_type
  912. * @param $bundle_name
  913. * @param $base_table
  914. * @param $dbxref_table
  915. */
  916. function tripal_chado_add_bundle_fields_linker__synonym_field($entity_type_name, $bundle_name, $syn_table, $base_table) {
  917. // We already have a dbxref_id field.
  918. $field_name = $syn_table;
  919. $schema = chado_get_schema($syn_table);
  920. $pkey = $schema['primary key'][0];
  921. // Initialize the field array.
  922. $field_info = array(
  923. 'field_type' => 'chado_linker__synonym',
  924. 'widget_type' => 'chado_linker__synonym_widget',
  925. 'widget_settings' => array('display_label' => 1),
  926. 'description' => '',
  927. 'label' => 'Synonyms',
  928. 'is_required' => 0,
  929. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  930. 'storage' => 'field_chado_storage',
  931. 'field_settings' => array(
  932. // The Chado table that this field maps to.
  933. 'chado_table' => $syn_table,
  934. // The column in the chado table that this field maps to.
  935. 'chado_column' => $pkey,
  936. // The base table that this field is connected to.
  937. 'base_table' => $base_table,
  938. 'semantic_web' => array(
  939. // The type is the term from a vocabulary that desribes this field..
  940. 'type' => '',
  941. // The namepsace for the vocabulary (e.g. 'foaf').
  942. 'ns' => '',
  943. // The URL for the namespace. It must be that the type can be
  944. // appended to the URL.
  945. 'nsurl' => '',
  946. ),
  947. ),
  948. );
  949. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  950. }
  951. /**
  952. * Adds the fields for managing xrefs that are stored in a [base]_dbxref table.
  953. *
  954. * @param $entity_type
  955. * @param $bundle_name
  956. * @param $base_table
  957. * @param $dbxref_table
  958. */
  959. function tripal_chado_add_bundle_fields_linker__pub_field($entity_type_name, $bundle_name, $pub_table, $base_table) {
  960. // We already have a dbxref_id field.
  961. $field_name = $pub_table;
  962. $schema = chado_get_schema($pub_table);
  963. $pkey = $schema['primary key'][0];
  964. // Initialize the field array.
  965. $field_info = array(
  966. 'field_type' => 'chado_linker__pub',
  967. 'widget_type' => 'chado_linker__pub_widget',
  968. 'widget_settings' => array('display_label' => 1),
  969. 'description' => '',
  970. 'label' => 'Publications',
  971. 'is_required' => 0,
  972. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  973. 'storage' => 'field_chado_storage',
  974. 'field_settings' => array(
  975. // The Chado table that this field maps to.
  976. 'chado_table' => $pub_table,
  977. // The column in the chado table that this field maps to.
  978. 'chado_column' => $pkey,
  979. // The base table that this field is connected to.
  980. 'base_table' => $base_table,
  981. 'semantic_web' => array(
  982. // The type is the term from a vocabulary that desribes this field..
  983. 'type' => '',
  984. // The namepsace for the vocabulary (e.g. 'foaf').
  985. 'ns' => '',
  986. // The URL for the namespace. It must be that the type can be
  987. // appended to the URL.
  988. 'nsurl' => '',
  989. ),
  990. ),
  991. );
  992. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  993. }
  994. /**
  995. * Adds the fields for managing properties that are stored in a prop table.
  996. *
  997. * @param $entity_type_name
  998. * @param $bundle_name
  999. * @param $kv_table
  1000. */
  1001. function tripal_chado_add_bundle_fields_linker__prop_adder_field($entity_type_name, $bundle_name, $kv_table, $base_table) {
  1002. $field_name = $kv_table;
  1003. // Initialize the field array.
  1004. $field_info = array(
  1005. 'field_type' => 'chado_linker__prop_adder',
  1006. 'widget_type' => 'chado_linker__prop_adder_widget',
  1007. 'field_settings' => array(
  1008. 'base_table' => $base_table,
  1009. ),
  1010. 'storage' => 'field_chado_storage',
  1011. 'widget_settings' => array('display_label' => 1),
  1012. 'description' => '',
  1013. 'label' => 'Additional Properties',
  1014. 'is_required' => 0,
  1015. );
  1016. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  1017. }
  1018. /**
  1019. * Adds the fields for managing properties that are stored in a prop table.
  1020. *
  1021. * @param $entity_type_name
  1022. * @param $bundle_name
  1023. * @param $kv_table
  1024. */
  1025. function tripal_chado_add_bundle_fields_linker__cvterm_adder_field($entity_type_name, $bundle_name, $cvterm_table, $base_table) {
  1026. // First add a generic property field so that users can add new property types.
  1027. $field_name = $cvterm_table;
  1028. // Initialize the field array.
  1029. $field_info = array(
  1030. 'field_type' => 'chado_linker__cvterm_adder',
  1031. 'widget_type' => 'chado_linker__cvterm_adder_widget',
  1032. 'field_settings' => array(
  1033. 'base_table' => $base_table,
  1034. ),
  1035. 'storage' => 'field_chado_storage',
  1036. 'widget_settings' => array('display_label' => 1),
  1037. 'description' => '',
  1038. 'label' => 'Additional Annotation Types',
  1039. 'is_required' => 0,
  1040. );
  1041. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  1042. }
  1043. /**
  1044. * Adds the fields for the base table to the entity.
  1045. */
  1046. function tripal_chado_add_bundle_fields_base__fields($entity_type_name, $bundle_name, $bundle_data) {
  1047. $table_name = $bundle_data['data_table'];
  1048. $type_table = $bundle_data['type_table'];
  1049. $type_field = $bundle_data['field'];
  1050. // Iterate through the columns of the table and see if fields have been
  1051. // created for each one. If not, then create them.
  1052. $schema = chado_get_schema($table_name);
  1053. $columns = $schema['fields'];
  1054. foreach ($columns as $column_name => $details) {
  1055. $field_name = $table_name . '__' . $column_name;
  1056. // Skip the primary key field.
  1057. if ($column_name == $schema['primary key'][0]) {
  1058. continue;
  1059. }
  1060. // Skip the type field.
  1061. if ($table_name == $type_table and $column_name == $type_field) {
  1062. continue;
  1063. }
  1064. // Get the field defaults for this column.
  1065. $field_info = tripal_chado_add_bundle_fields_base__fields_defaults($table_name, $schema, $column_name);
  1066. // TODO: add in a call to drupal_alter to allow other modules to change
  1067. // the field settings.
  1068. // Determine if the field is required.
  1069. if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
  1070. $field_info['is_required'] = array_key_exists('default', $details) ? 0 : 1;
  1071. }
  1072. // If we don't have a field type then we don't need to create a field.
  1073. if (!$field_info['field_type']) {
  1074. // If we don't have a field type but it is required and doesn't have
  1075. // a default value then we are in trouble.
  1076. if ($field_info['is_required'] and !array_key_exists('default', $details)) {
  1077. throw new Exception(t('The %table.%field type, %type, is not yet supported for Entity fields, but it is required,',
  1078. array('%table' => $table_name, '%field' => $column_name, '%type' => $details['type'])));
  1079. }
  1080. continue;
  1081. }
  1082. // If this field is a foreign key field then we will have a custom field.
  1083. $is_fk = FALSE;
  1084. if (array_key_exists('foreign keys', $schema)) {
  1085. foreach ($schema['foreign keys'] as $remote_table => $fk_details) {
  1086. if (array_key_exists($column_name, $fk_details['columns'])) {
  1087. $is_fk = TRUE;
  1088. }
  1089. }
  1090. }
  1091. // Add the field to the bundle.
  1092. tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
  1093. }
  1094. }
  1095. /**
  1096. * Implements hook_field_validate().
  1097. *
  1098. * This function is used to validate any field. Fields with custom
  1099. * widgets will most likely have their own validate function but for all
  1100. * others we need a way to validate them.
  1101. *
  1102. */
  1103. function tripal_chado_field_validate($entity_type, $entity, $field, $instance,
  1104. $langcode, $items, &$errors) {
  1105. }
  1106. /**
  1107. * Implements hook_field_attach_validate().
  1108. *
  1109. * This function is used to validate entity-wide validation any of the fields
  1110. * attached to an entity.
  1111. */
  1112. function tripal_chado_field_attach_validate($entity_type, $entity, &$errors) {
  1113. $bundle_name = $entity->bundle;
  1114. $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
  1115. $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
  1116. // Provide some higher-level validation for the organism type.
  1117. if ($term->name == 'organism') {
  1118. }
  1119. }