|
@@ -178,15 +178,122 @@ function tripal_fields_field_formatter_info() {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Implements hook_field_formatter_view().
|
|
|
+ * Implements hook_chado_field_alter().
|
|
|
+ *
|
|
|
+ * This function is used to change the default field formatter and widget
|
|
|
+ * that are assigned to fields of an Entity. This hook is only used for
|
|
|
+ * those fields that correspond to a column in a Chado table. An implementation
|
|
|
+ * of this hook can be used to change the default formatters and widgets to
|
|
|
+ * custom formatters and widgets that are created by the module creating
|
|
|
+ * this hook.
|
|
|
*
|
|
|
- * 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.
|
|
|
+ * By default, Tripal will provide custom formatters and widgets for many
|
|
|
+ * columns in Chado tables, therefore, this hook will most likely be of use
|
|
|
+ * to extension modules that create custom table inside of Chado.
|
|
|
*
|
|
|
- * @see field_example_field_formatter_info()
|
|
|
+ * @param $field
|
|
|
+ */
|
|
|
+function hook_chado_field_alter(&$field) {
|
|
|
+ // TODO: add example code for how to use this hook.
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Implements hook_chado_field_alter().
|
|
|
+ *
|
|
|
+ * This function adds the custom formatters and widgets to many of the Chado
|
|
|
+ * tables. This way Tripal users get a nice set of already usable fields.
|
|
|
+ */
|
|
|
+function tripal_fields_chado_field_alter(&$field) {
|
|
|
+
|
|
|
+ if (!array_key_exists('field_settings', $field)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // If the field doesn't list the Chado table or column then just return.
|
|
|
+ if (!array_key_exists('chado_table', $field['field_settings']) or
|
|
|
+ !array_key_exists('chado_column', $field['field_settings'])) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // Here we provide new field types and widgets for FK fields
|
|
|
+ // and fields that need special attention.
|
|
|
+ if ($field['field_settings']['chado_column'] =='organism_id') {
|
|
|
+ $field['field_type'] = 'organism_id';
|
|
|
+ $field['widget_type'] = 'tripal_fields_organism_select_widget';
|
|
|
+ $field['label'] = 'Organism';
|
|
|
+ $field['description'] = 'Select an organism.';
|
|
|
+ }
|
|
|
+ else if ($field['field_settings']['chado_column'] =='dbxref_id') {
|
|
|
+ $field['field_type'] = 'dbxref_id';
|
|
|
+ $field['widget_type'] = 'tripal_fields_primary_dbxref_widget';
|
|
|
+ $field['label'] = 'Primary Cross Reference';;
|
|
|
+ $field['description'] = 'This record can be cross-referenced with a
|
|
|
+ record in another online database. The primary reference is for the
|
|
|
+ most prominent reference. At a minimum, the database and accession
|
|
|
+ must be provided. To remove a set reference, change the database
|
|
|
+ field to "Select a Database".';
|
|
|
+ }
|
|
|
+ else if ($field['field_settings']['chado_table'] == 'feature' and
|
|
|
+ $field['field_settings']['chado_column'] == 'md5checksum') {
|
|
|
+ $field['field_type'] = 'md5checksum';
|
|
|
+ $field['widget_type'] = 'tripal_fields_md5checksum_checkbox_widget';
|
|
|
+ $field['label'] = 'MD5 Checksum';
|
|
|
+ $field['description'] = 'Generating MD5 checksum for the sequence.';
|
|
|
+ }
|
|
|
+ else if ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'seqlen') {
|
|
|
+ $field['field_type'] = 'seqlen';
|
|
|
+ $field['widget_type'] = 'tripal_fields_seqlen_hidden_widget';
|
|
|
+ $field['label'] = 'Seqlen';
|
|
|
+ $field['description'] = 'The length of the residues.';
|
|
|
+ }
|
|
|
+ else if ($field['field_settings']['chado_table'] == 'feature' and $field['field_settings']['chado_column'] == 'residues') {
|
|
|
+ $field['field_type'] = 'residues';
|
|
|
+ $field['widget_type'] = 'tripal_fields_residues_textarea_widget';
|
|
|
+ $field['label'] = 'Residues';
|
|
|
+ $field['description'] = 'Please provide an IUPAC compatible residues for this feature. Spaces and new lines are allowed.';
|
|
|
+ }
|
|
|
+ else if ($field['label'] == 'Timeaccessioned') {
|
|
|
+ $field['label'] = 'Time Accessioned';
|
|
|
+ $field['description'] = 'Please enter the time that this record was first added to the database.';
|
|
|
+ }
|
|
|
+ else if ($field['label'] == 'Timelastmodified') {
|
|
|
+ $field['label'] = 'Time Last Modified';
|
|
|
+ $field['description'] = 'Please enter the time that this record was last modified. The default is the current time.';
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Implements hook_field_widget_form_alter().
|
|
|
+ */
|
|
|
+function tripal_fields_field_widget_form_alter(&$element, &$form_state, $context) {
|
|
|
+
|
|
|
+ if (array_key_exists('#field_name', $element)) {
|
|
|
+ $field_name = $element['#field_name'];
|
|
|
+ $matches = array();
|
|
|
+
|
|
|
+ if (preg_match('/(.+?)__(.+?)$/', $field_name, $matches)) {
|
|
|
+ $tablename = $matches[1];
|
|
|
+ $colname = $matches[2];
|
|
|
+ $schema = chado_get_schema($tablename);
|
|
|
+
|
|
|
+ // The timelastmodified field exists in many Chado tables. We want
|
|
|
+ // the form element to update to the most recent time rather than the time
|
|
|
+ // in the database.
|
|
|
+ if ($colname == 'timelastmodified' and $schema['fields'][$colname]['type'] == 'datetime') {
|
|
|
+ // We want the default value for the field to be the current time.
|
|
|
+ $element['#default_value']['value'] = format_date(time(), 'custom', "Y-m-d H:i:s", 'UTC');
|
|
|
+ $element['#date_items']['value'] = $element['#default_value']['value'];
|
|
|
+ }
|
|
|
+ // We want the date combo fieldset to be collaspible so we will
|
|
|
+ // add our own theme_wrapper to replace the one added by the date
|
|
|
+ // module.
|
|
|
+ if (array_key_exists($colname, $schema['fields']) and $schema['fields'][$colname]['type'] == 'datetime') {
|
|
|
+ $element['#theme_wrappers'] = array('tripal_entities_date_combo');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Implements hook_field_formatter_view().
|
|
|
*/
|
|
|
function tripal_fields_field_formatter_view($entity_type, $entity, $field,
|
|
|
$instance, $langcode, $items, $display) {
|