123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 |
- <?php
- require_once "api/tripal_fields.api.inc";
- require_once "includes/tripal_fields.field_storage.inc";
- /**
- * Implements hook_field_info().
- */
- function tripal_fields_field_info() {
- $fields = array(
- 'organism_id' => 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_dbxref_id_widget',
- 'default_formatter' => 'tripal_fields_dbxref_id_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_dbxref_id_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_dbxref_id_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_dbxref_id_formatter':
- module_load_include('inc', 'tripal_fields', 'includes/fields/dbxref_id');
- tripal_fields_dbxref_id_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_dbxref_id_widget':
- form_load_include($form_state, 'inc', 'tripal_fields', 'includes/fields/dbxref_id');
- module_load_include('inc', 'tripal_fields', 'includes/fields/dbxref_id');
- tripal_fields_dbxref_id_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_dbxref_id_widget' => array(
- 'render element' => 'element',
- 'file' => 'includes/fields/dbxref_id.inc',
- ),
- 'tripal_fields_kvproperty_addr_widget' => array(
- 'render element' => 'element',
- 'file' => 'includes/fields/dbxref_id.inc',
- ),
- );
- }
|