tripal.fields.inc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. <?php
  2. /**
  3. * Implements hook_field_info().
  4. *
  5. * We want the Tripal module to handle all TripalFields. This will allow
  6. * other modules to be more easily disabled/enabled because Drupal won't
  7. * let a module be disabled if it supports fields that are actively attached
  8. * to bundles. Therefore any module that provides a new TripalField will be
  9. * discovered and listed for Drupal by this function.
  10. */
  11. function tripal_field_info() {
  12. $info = array();
  13. $field_types = tripal_get_field_types();
  14. foreach ($field_types as $field_type) {
  15. $info[$field_type] = $field_type::info();
  16. }
  17. return $info;
  18. }
  19. /**
  20. * Implements hook_info_alter().
  21. */
  22. function tripal_field_info_alter(&$info) {
  23. // Make sure all fields have a 'tripal_term' setting so we can map
  24. // all fields to a vocabulary term for the semantic web.
  25. foreach ($info as $field_name => $details) {
  26. if(array_key_exists('settings', $details)) {
  27. if (!array_key_exists('tripal_term', $details['settings'])) {
  28. $info[$field_name]['settings']['tripal_term'] = '';
  29. }
  30. }
  31. else {
  32. $info[$field_name]['settings']['tripal_term'] = '';
  33. }
  34. }
  35. }
  36. /**
  37. * Implements hook_field_widget_info();
  38. */
  39. function tripal_field_widget_info() {
  40. $info = array();
  41. $widgets = tripal_get_field_widgets();
  42. foreach ($widgets as $widget) {
  43. $info[$widget] = $widget::info();
  44. }
  45. return $info;
  46. }
  47. /**
  48. * Implements hook_field_widget_info_alter();
  49. */
  50. function tripal_field_widget_info_alter(&$info) {
  51. }
  52. /**
  53. * Implements hook_field_formatter_info().
  54. */
  55. function tripal_field_formatter_info() {
  56. $info = array();
  57. $formatters = tripal_get_field_formatters();
  58. foreach ($formatters as $formatter) {
  59. $info[$formatter] = $formatter::info();
  60. }
  61. return $info;
  62. }
  63. /**
  64. * Implements hook_field_formatter_info_alter();
  65. */
  66. function tripal_field_formatter_info_alter(&$info) {
  67. }
  68. /**
  69. * Implements hook_bundle_create().
  70. *
  71. * This is a Triapl defined hook and is called in the TripalBundle::create()
  72. * function to allow modules to perform tasks when a bundle is created.
  73. */
  74. function tripal_bundle_create($bundle) {
  75. $field_type = 'rdfs__type';
  76. $field_name = 'rdfs__type';
  77. // Add the field, unless it already exists.
  78. if (!field_info_field($field_name)) {
  79. $field = field_create_field(array(
  80. 'field_name' => $field_name,
  81. 'type' => $field_type,
  82. 'cardinality' => 1,
  83. 'locked' => FALSE,
  84. 'storage' => array(
  85. 'type' => 'tripal_no_storage'
  86. ),
  87. ));
  88. }
  89. // Add an instance of the field to the bundle.
  90. if (!field_info_instance($bundle->type, $field_name, $bundle->name)) {
  91. $instance = field_create_instance(array(
  92. 'field_name' => $field_name,
  93. 'entity_type' => 'TripalEntity',
  94. 'bundle' => $bundle->name,
  95. 'label' => 'Resource Type',
  96. 'description' => 'The resource type',
  97. 'required' => FALSE,
  98. 'settings' => array(
  99. 'auto_attach' => TRUE,
  100. 'term_vocabulary' => 'rdfs',
  101. 'term_accession' => 'type',
  102. 'term_name' => 'type',
  103. ),
  104. 'widget' => array(
  105. 'type' => 'rdfs__type_widget',
  106. 'settings' => array(
  107. 'display_label' => 1,
  108. ),
  109. ),
  110. 'display' => array(
  111. 'default' => array(
  112. 'label' => 'inline',
  113. 'type' => 'rdfs__type_formatter',
  114. 'settings' => array(),
  115. ),
  116. ),
  117. ));
  118. }
  119. }
  120. /**
  121. * Implements hook_field_formatter_view().
  122. */
  123. function tripal_field_formatter_view($entity_type, $entity, $field,
  124. $instance, $langcode, $items, $display) {
  125. $element = array();
  126. $formatter_class = $display['type'];
  127. $is_loaded = tripal_load_include_field_class($formatter_class);
  128. if ($is_loaded) {
  129. $formatter = new $formatter_class($field, $instance);
  130. $formatter->view($element, $entity_type, $entity, $langcode, $items, $display);
  131. }
  132. return $element;
  133. }
  134. /**
  135. * Simple provides a message indicating that the field cannot be deleted.
  136. *
  137. * This function is used in the tripal_menu_alter() function. We alter the
  138. * menu created for managing fields to use this call back which
  139. * prints a message that the field cannot be deleted.
  140. */
  141. function tripal_field_no_delete() {
  142. drupal_set_message('This field cannot be removed.', 'warning');
  143. return '';
  144. }
  145. /**
  146. *
  147. * Implements hook_form_FORM_ID_alter().
  148. *
  149. * The field_ui_field_overview_form_ is used for adding and reordering the
  150. * fields attached to a bundle. It also includes edit and delete links and
  151. * links for editing field types and widgets.
  152. *
  153. * This alter function is used to add a new 'Supported By' column to
  154. * the table to let the user know where fields are storing their data.
  155. */
  156. function tripal_form_field_ui_field_overview_form_alter(&$form, &$form_state, $form_id) {
  157. // Add the 'Storage Location' to the table header.
  158. $form['fields']['#header'][] = 'Term';
  159. $form['fields']['#header'][] = 'Supported By * ';
  160. // Add the storage location as the final column for each field.
  161. $storage_info = module_invoke_all('field_storage_info');
  162. foreach (element_children($form['fields']) as $field_name) {
  163. $field = field_info_field($field_name);
  164. $instance = field_info_instance('TripalEntity', $field_name, $form['#bundle']);
  165. // For rows in the tables that aren't fields, just add an empty value
  166. // for the storage column.
  167. if (!$field) {
  168. $form['fields'][$field_name][] = array(
  169. '#markup' => '',
  170. );
  171. $form['fields'][$field_name][] = array(
  172. '#markup' => '',
  173. );
  174. continue;
  175. }
  176. $term_info = '';
  177. if (array_key_exists('term_accession', $instance['settings']) and $instance['settings']['term_accession']) {
  178. $term = tripal_get_term_details($instance['settings']['term_vocabulary'], $instance['settings']['term_accession']);
  179. $term_info = $term['name'] . ' (' . $instance['settings']['term_vocabulary'] . ':' . $instance['settings']['term_accession'] . ')';
  180. }
  181. $form['fields'][$field_name][] = array(
  182. '#markup' => $term_info,
  183. );
  184. $storage_type = $field['storage']['type'];
  185. $storage_label = array_key_exists('label', $storage_info[$storage_type]) ? $storage_info[$storage_type]['label'] : '';
  186. if ($storage_type == 'field_sql_storage') {
  187. $storage_label = 'Drupal';
  188. }
  189. if (array_key_exists('logo_url', $storage_info[$storage_type])) {
  190. $logo_url = $storage_info[$storage_type]['logo_url'];
  191. $form['fields'][$field_name][] = array(
  192. '#markup' => '<img class="form-field-ui-field-overview-storage-logo" src="' . $logo_url . '">',
  193. );
  194. }
  195. else {
  196. $form['fields'][$field_name][] = array(
  197. '#markup' => $storage_label,
  198. );
  199. }
  200. }
  201. $form['note'] = array(
  202. '#markup' => '* Fields attached to this content type can use various
  203. storage backends. Please be sure when you add new fields that the
  204. storage backend is appropriate. For example, if you use Chado, and you
  205. want all biological content to be stored in Chado, be sure that the
  206. respective fields are "supported by" Chado.',
  207. );
  208. }
  209. /**
  210. * Implements hook_module_implements_alter()
  211. *
  212. * We want our edits to the field_ui_field_overview_form form to occur after
  213. * all modules have implemented their changes.
  214. */
  215. function tripal_module_implements_alter(&$implementations, $hook) {
  216. if ($hook == 'form_alter') {
  217. $group = $implementations['tripal'];
  218. unset($implementations['tripal']);
  219. $implementations['tripal'] = $group;
  220. }
  221. }
  222. /**
  223. * Implements hook_field_settings_form()
  224. */
  225. function tripal_field_settings_form($field, $instance, $has_data) {
  226. // $form = array();
  227. // $field_type = $field['type'];
  228. // //$is_loaded = tripal_load_include_field_class($field_type);
  229. // tripal_load_include_field_class($field_type);
  230. // if (class_exists($field_type)) {
  231. // $tfield = new $field_type($field, $instance);
  232. // $form = $tfield->globalSettingsForm($field, $instance, $has_data);
  233. // }
  234. // return $form;
  235. }
  236. /**
  237. * Allows for altering of a field's instance setting form.
  238. *
  239. * This appears to be a Drupal hook but is actually a custom function created
  240. * by this module. It is called by the tripal_form_alter() function of this
  241. * module.
  242. *
  243. * Here we put additional form elements for any field, regardless if it is
  244. * a tripalField or not.
  245. *
  246. * @param $form
  247. * The form array. Alterations to the form can be made within this array.
  248. * @param $form_state
  249. * The form state array.
  250. */
  251. function tripal_field_instance_settings_form_alter(&$form, $form_state) {
  252. global $language;
  253. // It's not possible to add AJAX to a form element in the hook_form_alter
  254. // function. To make it work we have to add a process function. Inisde
  255. // of that process function is where the form additions get added that use
  256. // Ajax.
  257. $form['field_term'][$language->language][0]['#process'] = array('tripal_field_instance_settings_form_process');
  258. $form['#submit'][] = 'tripal_field_instance_settings_form_submit';
  259. }
  260. /**
  261. * Implements a process function for the instnace settings form.
  262. *
  263. * See the comment in the tripal_field_instance_settings_form_alter() for
  264. * more details.
  265. */
  266. function tripal_field_instance_settings_form_process($element, &$form_state, $form) {
  267. $field = $form['#field'];
  268. $instance = $form['#instance'];
  269. // Get the term for this instance.
  270. $vocabulary = '';
  271. $accession = '';
  272. $term_name = '';
  273. $term = NULL;
  274. if (array_key_exists('settings', $instance) and array_key_exists('term_vocabulary', $instance['settings'])) {
  275. $vocabulary = $instance['settings']['term_vocabulary'];
  276. $accession = $instance['settings']['term_accession'];
  277. $term_name = $instance['settings']['term_name'];
  278. $term = tripal_get_term_details($vocabulary, $accession);
  279. }
  280. // Construct a table for the vocabulary information.
  281. $headers = array();
  282. $rows = array();
  283. $rows[] = array(
  284. array(
  285. 'data' => 'Vocabulary',
  286. 'header' => TRUE,
  287. 'width' => '20%',
  288. ),
  289. $term['vocabulary']['name'] . ' (' . $term['vocabulary']['short_name'] . ') ' . $term['vocabulary']['description']
  290. );
  291. $rows[] = array(
  292. array(
  293. 'data' => 'Term',
  294. 'header' => TRUE,
  295. 'width' => '20%',
  296. ),
  297. $term['name'] . ':' . $term['accession']
  298. );
  299. $rows[] = array(
  300. array(
  301. 'data' => 'Definition',
  302. 'header' => TRUE,
  303. 'width' => '20%',
  304. ),
  305. $term['definition']
  306. );
  307. $table = array(
  308. 'header' => $headers,
  309. 'rows' => $rows,
  310. 'attributes' => array(
  311. ),
  312. 'sticky' => FALSE,
  313. 'caption' => '',
  314. 'colgroups' => array(),
  315. 'empty' => '',
  316. );
  317. $element['field_term'] = array(
  318. '#type' => 'fieldset',
  319. '#title' => 'Controlled Vocabulary Term',
  320. '#description' => t('All fields attached to a Tripal-based content type must
  321. be associated with a controlled vocabulary term. Please use caution
  322. when changing the term for this field as other sites may expect this term
  323. when querying web services.'),
  324. '#prefix' => '<div id = "tripal-field-term-fieldset">',
  325. '#suffix' => '</div>',
  326. );
  327. $element['field_term']['term_vocabulary'] = array(
  328. '#type' => 'value',
  329. '#value' => $vocabulary,
  330. );
  331. $element['field_term']['term_name'] = array(
  332. '#type' => 'value',
  333. '#value' => $term_name,
  334. );
  335. $element['field_term']['term_accession'] = array(
  336. '#type' => 'value',
  337. '#value' => $accession,
  338. );
  339. $element['field_term']['details'] = array(
  340. '#type' => 'item',
  341. '#title' => 'Current Term',
  342. '#markup' => theme_table($table),
  343. );
  344. $element['field_term']['new_name'] = array(
  345. '#type' => 'textfield',
  346. '#title' => 'Change the term',
  347. // TODO: This autocomplete path should not use Chado.
  348. '#autocomplete_path' => "admin/tripal/storage/chado/auto_name/cvterm/",
  349. );
  350. $element['field_term']['select_button'] = array(
  351. '#type' => 'button',
  352. '#value' => t('Lookup Term'),
  353. '#name' => 'select_cvterm',
  354. '#ajax' => array(
  355. 'callback' => "tripal_fields_select_term_form_ajax_callback",
  356. 'wrapper' => "tripal-field-term-fieldset",
  357. 'effect' => 'fade',
  358. 'method' => 'replace'
  359. ),
  360. );
  361. // If a new term name has been specified by the user then give some extra
  362. // fields to clarify the term.
  363. $term_name = '';
  364. if (array_key_exists('values', $form_state) and array_key_exists('new_name', $form_state['values'])) {
  365. $term_name = array_key_exists('values', $form_state) ? $form_state['values']['new_name'] : '';
  366. }
  367. if ($term_name) {
  368. $element['field_term']['instructions'] = array(
  369. '#type' => 'item',
  370. '#title' => 'Matching terms',
  371. '#markup' => t('Please select the term the best matches the
  372. content type you want to associate with this field. If the same term exists in
  373. multiple vocabularies you will see more than one option below.')
  374. );
  375. $match = array(
  376. 'name' => $term_name,
  377. );
  378. $terms = chado_generate_var('cvterm', $match, array('return_array' => TRUE));
  379. $terms = chado_expand_var($terms, 'field', 'cvterm.definition');
  380. $num_terms = 0;
  381. foreach ($terms as $term) {
  382. // Save the user a click by setting the default value as 1 if there's
  383. // only one matching term.
  384. $default = FALSE;
  385. $attrs = array();
  386. if ($num_terms == 0 and count($terms) == 1) {
  387. $default = TRUE;
  388. $attrs = array('checked' => 'checked');
  389. }
  390. $element['field_term']['term-' . $term->cvterm_id] = array(
  391. '#type' => 'checkbox',
  392. '#title' => $term->name,
  393. '#default_value' => $default,
  394. '#attributes' => $attrs,
  395. '#description' => '<b>Vocabulary:</b> ' . $term->cv_id->name . ' (' . $term->dbxref_id->db_id->name . ') ' . $term->cv_id->definition .
  396. '<br><b>Term: </b> ' . $term->dbxref_id->db_id->name . ':' . $term->dbxref_id->accession . '. ' .
  397. '<br><b>Definition:</b> ' . $term->definition,
  398. );
  399. $num_terms++;
  400. }
  401. if ($num_terms == 0) {
  402. $element['field_term']['none'] = array(
  403. '#type' => 'item',
  404. '#markup' => '<i>' . t('There is no term that matches the entered text.') . '</i>'
  405. );
  406. }
  407. }
  408. $element['#element_validate'][] = 'tripal_field_instance_settings_form_validate';
  409. return $element;
  410. }
  411. /**
  412. * Implements an AJAX callback for the tripal_field_vocab_select_term_form.
  413. */
  414. function tripal_fields_select_term_form_ajax_callback($form, $form_state) {
  415. return $form['field_term'];
  416. }
  417. /**
  418. * Implements hook_instance_settings_form()
  419. */
  420. function tripal_field_instance_settings_form($field, $instance) {
  421. // $form = array();
  422. // $field_type = $field['type'];
  423. // tripal_load_include_field_class($field_type);
  424. // if (class_exists($field_type)) {
  425. // $tfield = new $field_type($field, $instance);
  426. // $form = $tfield->instanceSettingsForm();
  427. // }
  428. // return $form;
  429. }
  430. /**
  431. * Validate our custom instance settings form fields.
  432. */
  433. function tripal_field_instance_settings_form_validate($form, &$form_state) {
  434. // If the user clicked the submit button then we want set the
  435. // instance settings values accordingly.
  436. foreach ($form_state['input'] as $key => $value) {
  437. $matches = array();
  438. if (preg_match("/^term-(\d+)$/", $key, $matches) and
  439. $form_state['input']['term-' . $matches[1]]) {
  440. $cvterm_id = $matches[1];
  441. // TODO: this should not call a Chado function.
  442. $term = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));
  443. $form_state['values']['instance']['settings']['term_vocabulary'] = $term->dbxref_id->db_id->name;
  444. $form_state['values']['instance']['settings']['term_accession'] = $term->dbxref_id->accession;
  445. $form_state['values']['instance']['settings']['term_name'] = $term->name;
  446. }
  447. }
  448. }
  449. /**
  450. * Custom submit function for instance settings form.
  451. */
  452. function tripal_field_instance_settings_form_submit($form, &$form_state) {
  453. }
  454. /**
  455. *
  456. */
  457. function tripal_field_widget_form_validate($form, &$form_state) {
  458. // $entity = $form['#entity'];
  459. // $entity_type = $form['#entity_type'];
  460. // $langcode = $form['#language'];
  461. // $delta = $form['#delta'];
  462. // $field = $form['#field'];
  463. // $field_type = $field['type'];
  464. // tripal_load_include_field_class($field_type);
  465. // if (class_exists($field_type)) {
  466. // $instance = $form['#instance'];
  467. // $tfield = new $field_type($field, $instance);
  468. // $form = $tfield->widgetFormValidate($form, $form_state, $entity_type, $entity, $langcode, $delta);
  469. // }
  470. }
  471. /**
  472. * Implements hook_field_settings_form_validate().
  473. *
  474. * This is not an actual Drpual hook, but rather a Tripal created hook
  475. * to alow the TripalField objects to have a globalSettingsFormValidate()
  476. * member function.
  477. */
  478. function tripal_field_settings_form_validate($form, &$form_state) {
  479. // $field = $form['#field'];
  480. // $instance = $form['#instance'];
  481. // $field_type = $field['type'];
  482. // tripal_load_include_field_class($field_type);
  483. // if (class_exists($field_type)) {
  484. // $tfield = new $field_type($field, $instance);
  485. // $form = $tfield->globalSettingsFormValidate($field, $instance, $form, $form_state);
  486. // }
  487. }
  488. /**
  489. * Implements hook_field_formatter_settings_summary().
  490. */
  491. function tripal_field_formatter_settings_summary($field, $instance, $view_mode) {
  492. // $summary = '';
  493. // $field_type = $field['type'];
  494. // tripal_load_include_field_class($field_type);
  495. // if (class_exists($field_type)) {
  496. // $tfield = new $field_type($field, $instance);
  497. // $form = $tfield->formatterSettingsSummary($view_mode);
  498. // }
  499. // return $summary;
  500. }
  501. /**
  502. * Implements hook_field_formatter_settings_form().
  503. */
  504. function tripal_formatter_settings_form($field, $instance,
  505. $view_mode, $form, &$form_state) {
  506. // $form = array();
  507. // $field_type = $field['type'];
  508. // tripal_load_include_field_class($field_type);
  509. // if (class_exists($field_type)) {
  510. // $tfield = new $field_type($field, $instance);
  511. // $form = $tfield->formatterSettingsForm($view_mode, $form, $form_state);
  512. // }
  513. // return $form;
  514. }
  515. /**
  516. * Implements hook_field_widget_form().
  517. */
  518. function tripal_field_widget_form(&$form, &$form_state, $field,
  519. $instance, $langcode, $items, $delta, $element) {
  520. $widget_class = $instance['widget']['type'];
  521. tripal_load_include_field_class($widget_class);
  522. if (class_exists($widget_class)) {
  523. $widget = new $widget_class($field, $instance);
  524. $widget->form($element, $form, $form_state, $langcode, $items, $delta, $element);
  525. }
  526. return $element;
  527. }
  528. /**
  529. * Implements hook_field_widget_form_alter().
  530. */
  531. function tripal_field_widget_form_alter(&$element, &$form_state, $context) {
  532. if (array_key_exists('#field_name', $element)) {
  533. $field_name = $element['#field_name'];
  534. $matches = array();
  535. if (preg_match('/(.+?)__(.+?)$/', $field_name, $matches)) {
  536. $tablename = $matches[1];
  537. $colname = $matches[2];
  538. $schema = chado_get_schema($tablename);
  539. if (!$schema) {
  540. return;
  541. }
  542. // The timelastmodified field exists in many Chado tables. We want
  543. // the form element to update to the most recent time rather than the time
  544. // in the database.
  545. if ($colname == 'timelastmodified' and $schema['fields'][$colname]['type'] == 'datetime') {
  546. // We want the default value for the field to be the current time.
  547. $element['#default_value']['value'] = format_date(time(), 'custom', "Y-m-d H:i:s", 'UTC');
  548. $element['#date_items']['value'] = $element['#default_value']['value'];
  549. }
  550. // We want the date combo fieldset to be collaspible so we will
  551. // add our own theme_wrapper to replace the one added by the date
  552. // module.
  553. if (array_key_exists($colname, $schema['fields']) and $schema['fields'][$colname]['type'] == 'datetime') {
  554. $element['#theme_wrappers'] = array('tripal_chado_date_combo');
  555. }
  556. }
  557. }
  558. }
  559. /**
  560. * Implements hook_field_validate()
  561. */
  562. function tripal_field_validate($entity_type, $entity, $field, $instance,
  563. $langcode, $items, &$errors) {
  564. // $field_type = $field['type'];
  565. // $is_loaded = tripal_load_include_field_class($field_type);
  566. // if ($is_loaded) {
  567. // $tfield = new $field_type($field, $instance);
  568. // $tfield->validate($entity_type, $entity, $langcode,
  569. // $items, $errors);
  570. // }
  571. }
  572. /**
  573. * Implements hook_form_FORM_ID_alter().
  574. *
  575. * The field_ui_display_overview_form is used for formatting the display
  576. * or layout of fields attached to an entity and shown on the entity view page.
  577. *
  578. * This function removes the cvterm class and property adder field as those are
  579. * really not meant for users to show or manage.
  580. */
  581. function tripal_form_field_ui_display_overview_form_alter(&$form, &$form_state, $form_id) {
  582. // Remove the kvproperty_addr field as it isn't ever displayed. It's just used
  583. // on the add/edit form of an entity for adding new property fields.
  584. $fields_names = element_children($form['fields']);
  585. foreach ($fields_names as $field_name) {
  586. $field_info = field_info_field($field_name);
  587. if ($field_info['type'] == 'kvproperty_adder') {
  588. unset($form['fields'][$field_name]);
  589. }
  590. if ($field_info['type'] == 'cvterm_class_adder') {
  591. unset($form['fields'][$field_name]);
  592. }
  593. }
  594. }
  595. /**
  596. * Implements hook_field_is_empty().
  597. */
  598. function tripal_field_is_empty($item, $field) {
  599. // If there is no value field then the field is empty.
  600. if (!array_key_exists('value', $item)) {
  601. return TRUE;
  602. }
  603. // Iterate through all of the fields and if at least one has a value
  604. // the field is not empty.
  605. foreach ($item as $form_field_name => $value) {
  606. if (isset($value) and $value != NULL and $value != '') {
  607. return FALSE;
  608. }
  609. }
  610. // Otherwise, the field is empty.
  611. return TRUE;
  612. }