array( 'label' => t('Organism'), 'description' => t('A field for specifying an organism.'), 'default_widget' => 'tripal_fields_organism_select_widget', 'default_formatter' => 'tripal_fields_organism_formatter', 'settings' => array(), 'storage' => array( 'type' => 'field_chado_storage', 'module' => 'tripal_fields', 'active' => TRUE ), ), 'dbxref_id' => array( 'label' => t('Cross-reference'), 'description' => t('This record can be cross-referenced with a record in another online database. This field is intended for the most prominent reference. At a minimum, the database and accession must be provided.'), 'default_widget' => 'tripal_fields_primary_dbxref_widget', 'default_formatter' => 'tripal_fields_primary_dbxref_formatter', 'settings' => array(), 'storage' => array( 'type' => 'field_chado_storage', 'module' => 'tripal_fields', 'active' => TRUE ), ), 'residues' => array( 'label' => t('Residues'), 'description' => t('A field for managing nucleotide and protein residues.'), 'default_widget' => 'tripal_fields_residue_textarea_widget', 'default_formatter' => 'tripal_fields_residues_formatter', 'settings' => array(), 'storage' => array( 'type' => 'field_chado_storage', 'module' => 'tripal_fields', 'active' => TRUE ), ), 'md5checksum' => array( 'label' => t('MD5 checksum'), 'description' => t('A field for generating MD5 checksum for a sequence.'), 'default_widget' => 'tripal_fields_md5checksum_checkbox_widget', 'default_formatter' => 'tripal_fields_md5checksum_formatter', 'settings' => array(), 'storage' => array( 'type' => 'field_chado_storage', 'module' => 'tripal_fields', 'active' => TRUE ), ), 'seqlen' => array( 'label' => t('Sequence length'), 'description' => t('A field for calculating the length of a sequence.'), 'default_widget' => 'tripal_fields_seqlen_hidden_widget', 'default_formatter' => 'tripal_fields_seqlen_formatter', 'settings' => array(), 'storage' => array( 'type' => 'field_chado_storage', 'module' => 'tripal_fields', 'active' => TRUE ), ), // The field provides a widget for adding new properties // to an entity that is connected to a base table that has a prop table // in Chado. 'kvproperty_adder' => array( 'label' => t('Add a Property Type'), 'description' => t('This record may have any number of properties. Use this field to first add the type.'), 'default_widget' => 'tripal_fields_kvproperty_adder_widget', 'default_formatter' => 'tripal_fields_kvproperty_adder_formatter', 'settings' => array(), 'storage' => array( 'type' => 'field_chado_storage', 'module' => 'tripal_fields', 'active' => TRUE ), ), // The field provides form elements for adding a property to an entity // that in turn gets stored in a prop table of Chado (e.g. featureprop, // stockprop, etc). 'kvproperty' => array( 'label' => t('Add a Property'), 'description' => t('Add details about this property.'), 'default_widget' => 'tripal_fields_kvproperty_widget', 'default_formatter' => 'tripal_fields_kvproperty_formatter', 'settings' => array(), 'storage' => array( 'type' => 'field_chado_storage', 'module' => 'tripal_fields', 'active' => TRUE ), ), ); return $fields; } /** * Implements hook_field_widget_info(). */ function tripal_fields_field_widget_info() { return array( 'tripal_fields_organism_select_widget' => array( 'label' => t('Organism Select'), 'field types' => array('organism_id') ), 'tripal_fields_primary_dbxref_widget' => array( 'label' => t('Cross-reference'), 'field types' => array('dbxref_id'), 'description' => t('This record can be cross-referenced with a record in another online database. This field is intended for the most prominent reference. At a minimum, the database and accession must be provided.'), ), 'tripal_fields_md5checksum_checkbox_widget' => array( 'label' => t('MD5 Checksum Checkbox'), 'field types' => array('md5checksum'), ), 'tripal_fields_residues_textarea_widget' => array( 'label' => t('Residues'), 'field types' => array('residues'), ), 'tripal_fields_seqlen_hidden_widget' => array( 'label' => t('Sequence Length'), 'field types' => array('seqlen'), ), 'tripal_fields_kvproperty_adder_widget' => array( 'label' => t('Add a Property'), 'field types' => array('kvproperty_adder'), ), 'tripal_fields_kvproperty_widget' => array( 'label' => t('Property'), 'field types' => array('kvproperty'), ), ); } /** * Implements hook_field_formatter_info(). */ function tripal_fields_field_formatter_info() { return array( 'tripal_fields_organism_formatter' => array( 'label' => t('Organism'), 'field types' => array('organism_id') ), 'tripal_fields_primary_dbxref_formatter' => array( 'label' => t('Cross-reference'), 'field types' => array('dbxref_id') ), 'tripal_fields_md5checksum_formatter' => array( 'label' => t('MD5 checksum'), 'field types' => array('md5checksum') ), 'tripal_fields_residues_formatter' => array( 'label' => t('Residues'), 'field types' => array('residues') ), 'tripal_fields_seqlen_formatter' => array( 'label' => t('Sequence length'), 'field types' => array('seqlen') ), 'tripal_fields_kvproperty_adder_formatter' => array( 'label' => t('Add a Property'), 'field types' => array('kvproperty_adder') ), 'tripal_fields_kvproperty_formatter' => array( 'label' => t('Property'), 'field types' => array('kvproperty') ), ); } /** * Implements hook_field_formatter_view(). * * Two formatters are implemented. * - field_example_simple_text just outputs markup indicating the color that * was entered and uses an inline style to set the text color to that value. * - field_example_color_background does the same but also changes the * background color of div.region-content. * * @see field_example_field_formatter_info() */ function tripal_fields_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $element = array(); switch ($display['type']) { case 'tripal_fields_organism_formatter': module_load_include('inc', 'tripal_fields', 'includes/fields/organism_id'); tripal_fields_organism_select_formatter($element, $entity_type, $entity, $field, $instance, $langcode, $items, $display); break; case 'tripal_fields_primary_dbxref_formatter': module_load_include('inc', 'tripal_fields', 'includes/fields/primary_dbxref'); tripal_fields_primary_dbxref_formatter($element, $entity_type, $entity, $field, $instance, $langcode, $items, $display); break; case 'tripal_fields_md5checksum_formatter': module_load_include('inc', 'tripal_fields', 'includes/fields/md5checksum'); tripal_fields_md5checksum_checkbox_formatter($element, $entity_type, $entity, $field, $instance, $langcode, $items, $display); break; case 'tripal_fields_residues_formatter': module_load_include('inc', 'tripal_fields', 'includes/fields/residues'); tripal_fields_residues_textarea_formatter($element, $entity_type, $entity, $field, $instance, $langcode, $items, $display); break; case 'tripal_fields_seqlen_formatter': module_load_include('inc', 'tripal_fields', 'includes/fields/seqlen'); tripal_fields_seqlen_hidden_formatter($element, $entity_type, $entity, $field, $instance, $langcode, $items, $display); break; case 'tripal_fields_kvproperty_adder_formatter': module_load_include('inc', 'tripal_fields', 'includes/fields/kvproperty_adder'); tripal_fields_kvproperty_adder_formatter($element, $entity_type, $entity, $field, $instance, $langcode, $items, $display); break; case 'tripal_fields_kvproperty_formatter': module_load_include('inc', 'tripal_fields', 'includes/fields/kvproperty'); tripal_fields_kvproperty_formatter($element, $entity_type, $entity, $field, $instance, $langcode, $items, $display); break; } return $element; } /** * Implements hook_field_widget_form(). */ function tripal_fields_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) { $widget = $element; switch ($instance['widget']['type']) { case 'tripal_fields_organism_select_widget': // Make sure the include files get parsed now and for the form submits. form_load_include($form_state, 'inc', 'tripal_fields', 'includes/fields/organism_id'); module_load_include('inc', 'tripal_fields', 'includes/fields/organism_id'); // Update the widget with the new field. tripal_fields_organism_select_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element); break; case 'tripal_fields_primary_dbxref_widget': form_load_include($form_state, 'inc', 'tripal_fields', 'includes/fields/primary_dbxref'); module_load_include('inc', 'tripal_fields', 'includes/fields/primary_dbxref'); tripal_fields_primary_dbxref_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element); break; case 'tripal_fields_md5checksum_checkbox_widget': form_load_include($form_state, 'inc', 'tripal_fields', 'includes/fields/md5checksum'); module_load_include('inc', 'tripal_fields', 'includes/fields/md5checksum'); tripal_fields_md5checksum_checkbox_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element); break; case 'tripal_fields_residues_textarea_widget': form_load_include($form_state, 'inc', 'tripal_fields', 'includes/fields/residues'); module_load_include('inc', 'tripal_fields', 'includes/fields/residues'); tripal_fields_residues_textarea_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element); break; case 'tripal_fields_seqlen_hidden_widget': form_load_include($form_state, 'inc', 'tripal_fields', 'includes/fields/seqlen'); module_load_include('inc', 'tripal_fields', 'includes/fields/seqlen'); tripal_fields_seqlen_hidden_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element); break; case 'tripal_fields_kvproperty_adder_widget': form_load_include($form_state, 'inc', 'tripal_fields', 'includes/fields/kvproperty_adder'); module_load_include('inc', 'tripal_fields', 'includes/fields/kvproperty_adder'); tripal_fields_kvproperty_adder_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element); break; case 'tripal_fields_kvproperty_widget': form_load_include($form_state, 'inc', 'tripal_fields', 'includes/fields/kvproperty'); module_load_include('inc', 'tripal_fields', 'includes/fields/kvproperty'); tripal_fields_kvproperty_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element); break; } return $widget; } /** * Implements hook_field_is_empty(). */ function tripal_fields_field_is_empty($item, $field) { // If there is no value field then the field is empty. if (!array_key_exists('value', $item)) { return TRUE; } // Iterate through all of the fields and if at least one has a value // the field is not empty. foreach ($item as $form_field_name => $value) { if (isset($value) and $value != NULL and $value != '') { return FALSE; } } // Otherwise, the field is empty. return TRUE; } /** * Returns the values of the field from the $form_state. */ function tripal_fields_get_field_form_values($field_name, $form_state, $delta = 0, $child = NULL) { $value = NULL; // The form_state must have the 'values' key. If not then just return. if (!array_key_exists('values', $form_state)) { return $value; } // If the field name is not in the form_state['values'] then return. if (!array_key_exists($field_name, $form_state['values'])) { return $value; } // Iterate through the values looking for the field_name provided. foreach ($form_state['values'][$field_name] as $langcode => $items) { $item = $items[$delta]; if ($child){ if(array_key_exists($child, $item) and $item[$child] != '') { $value = $item[$child]; } } else { $value = $item['value']; } } return $value; } /** * Sets the values of the field from the $form_state. */ function tripal_fields_set_field_form_values($field_name, &$form_state, $newvalue, $delta = 0, $child = NULL) { // The form_state must have the 'values' key. If not then just return. if (!array_key_exists('values', $form_state)) { return FALSE; } // If the field name is not in the form_state['values'] then reutrn. if (!array_key_exists($field_name, $form_state['values'])) { return FALSE; } foreach ($form_state['values'][$field_name] as $langcode => $items) { if ($child) { $form_state['values'][$field_name][$langcode][$delta][$child] = $newvalue; } else { $form_state['values'][$field_name][$langcode][$delta]['value'] = $newvalue; } } return TRUE; } /** * Implements hook_theme(). */ function tripal_fields_theme($existing, $type, $theme, $path) { return array( 'tripal_fields_primary_dbxref_widget' => array( 'render element' => 'element', 'file' => 'includes/fields/primary_dbxref.inc', ), ); }