|
@@ -395,9 +395,10 @@ function tripal_chado_field_info() {
|
|
|
'active' => TRUE
|
|
|
),
|
|
|
),
|
|
|
+
|
|
|
'dbxref_id' => array(
|
|
|
- 'label' => t('Cross-reference'),
|
|
|
- 'description' => t('This record can be cross-referenced with a record in
|
|
|
+ '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_chado_dbxref_id_widget',
|
|
@@ -477,6 +478,26 @@ function tripal_chado_field_info() {
|
|
|
'active' => TRUE
|
|
|
),
|
|
|
),
|
|
|
+
|
|
|
+ // The field provides form elements for adding multiple dbxrefs to an
|
|
|
+ // entity that in turn get stored in a [base]_dbxref table of Chado
|
|
|
+ // (e.g. organism_dbxref, feature_dbxref). This is different
|
|
|
+ // from the dbxref_id field as that is specific to a dbxref_id in
|
|
|
+ // a base table.
|
|
|
+ 'dbxref' => array(
|
|
|
+ 'label' => t('Cross references'),
|
|
|
+ 'description' => t('This record can be cross referenced with a record in
|
|
|
+ another online database. This field is intended for one or more
|
|
|
+ references. At a minimum, the database and accession must be provided.'),
|
|
|
+ 'default_widget' => 'tripal_chado_dbxref_widget',
|
|
|
+ 'default_formatter' => 'tripal_chado_dbxref_formatter',
|
|
|
+ 'settings' => array(),
|
|
|
+ 'storage' => array(
|
|
|
+ 'type' => 'field_chado_storage',
|
|
|
+ 'module' => 'tripal_chado',
|
|
|
+ 'active' => TRUE
|
|
|
+ ),
|
|
|
+ ),
|
|
|
);
|
|
|
return $fields;
|
|
|
}
|
|
@@ -491,9 +512,20 @@ function tripal_chado_field_widget_info() {
|
|
|
'field types' => array('organism_id')
|
|
|
),
|
|
|
'tripal_chado_dbxref_id_widget' => array(
|
|
|
- 'label' => t('Cross-reference'),
|
|
|
+ '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.'),
|
|
|
+ '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_chado_dbxref_widget' => array(
|
|
|
+ 'label' => t('Cross references'),
|
|
|
+ 'field types' => array('dbxref'),
|
|
|
+ '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_chado_md5checksum_checkbox_widget' => array(
|
|
|
'label' => t('MD5 Checksum Checkbox'),
|
|
@@ -527,9 +559,13 @@ function tripal_chado_field_formatter_info() {
|
|
|
'field types' => array('organism_id')
|
|
|
),
|
|
|
'tripal_chado_dbxref_id_formatter' => array(
|
|
|
- 'label' => t('Cross-reference'),
|
|
|
+ 'label' => t('Cross reference'),
|
|
|
'field types' => array('dbxref_id')
|
|
|
),
|
|
|
+ 'tripal_chado_dbxref_formatter' => array(
|
|
|
+ 'label' => t('Cross references'),
|
|
|
+ 'field types' => array('dbxref')
|
|
|
+ ),
|
|
|
'tripal_chado_md5checksum_formatter' => array(
|
|
|
'label' => t('MD5 checksum'),
|
|
|
'field types' => array('md5checksum')
|
|
@@ -634,6 +670,11 @@ function tripal_chado_field_formatter_view($entity_type, $entity, $field,
|
|
|
tripal_chado_dbxref_id_formatter($element, $entity_type, $entity, $field,
|
|
|
$instance, $langcode, $items, $display);
|
|
|
break;
|
|
|
+ case 'tripal_chado_dbxref_formatter':
|
|
|
+ module_load_include('inc', 'tripal_chado', 'includes/fields/dbxref');
|
|
|
+ tripal_chado_dbxref_formatter($element, $entity_type, $entity, $field,
|
|
|
+ $instance, $langcode, $items, $display);
|
|
|
+ break;
|
|
|
case 'tripal_chado_md5checksum_formatter':
|
|
|
module_load_include('inc', 'tripal_chado', 'includes/fields/md5checksum');
|
|
|
tripal_chado_md5checksum_checkbox_formatter($element, $entity_type, $entity, $field,
|
|
@@ -683,6 +724,11 @@ function tripal_chado_field_widget_form(&$form, &$form_state, $field,
|
|
|
module_load_include('inc', 'tripal_chado', 'includes/fields/dbxref_id');
|
|
|
tripal_chado_dbxref_id_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
|
|
|
break;
|
|
|
+ case 'tripal_chado_dbxref_widget':
|
|
|
+ form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/dbxref');
|
|
|
+ module_load_include('inc', 'tripal_chado', 'includes/fields/dbxref');
|
|
|
+ tripal_chado_dbxref_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
|
|
|
+ break;
|
|
|
case 'tripal_chado_md5checksum_checkbox_widget':
|
|
|
form_load_include($form_state, 'inc', 'tripal_chado', 'includes/fields/md5checksum');
|
|
|
module_load_include('inc', 'tripal_chado', 'includes/fields/md5checksum');
|
|
@@ -717,6 +763,9 @@ function tripal_chado_field_widget_form(&$form, &$form_state, $field,
|
|
|
*
|
|
|
* The field_ui_display_overview_form is used for formatting the display
|
|
|
* or layout of fields attached to an entity and shown on the entity view page.
|
|
|
+ *
|
|
|
+ * This function removes the property adder field as that is really not meant
|
|
|
+ * for users to show or manage.
|
|
|
*/
|
|
|
function tripal_chado_form_field_ui_display_overview_form_alter(&$form, &$form_state, $form_id) {
|
|
|
// Remove the kvproperty_addr field as it isn't ever displayed. It's just used
|
|
@@ -734,6 +783,9 @@ function tripal_chado_form_field_ui_display_overview_form_alter(&$form, &$form_s
|
|
|
*
|
|
|
* The field_ui_field_overview_form is used for ordering and configuring the
|
|
|
* fields attached to an entity.
|
|
|
+ *
|
|
|
+ * This function removes the property adder field as that is really not meant
|
|
|
+ * for users to show or manage.
|
|
|
*/
|
|
|
function tripal_chado_form_field_ui_field_overview_form_alter(&$form, &$form_state, $form_id) {
|
|
|
// Remove the kvproperty_addr field as it isn't ever displayed. It's just used
|
|
@@ -917,32 +969,101 @@ function tripal_chado_add_bundle_fields($entity_type, $bundle, $term) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Adds the fields for the base table to the entity.
|
|
|
- tripal_chado_add_bundle_base_fields($entity_type, $bundle_name, $bundle_data);
|
|
|
-
|
|
|
// Save the mapping information so that we can reuse it when we need to
|
|
|
// look things up for later for an entity
|
|
|
tripal_set_bundle_variable('chado_cvterm_id', $bundle->id, $bundle_data['cvterm_id']);
|
|
|
tripal_set_bundle_variable('chado_table', $bundle->id, $bundle_data['data_table']);
|
|
|
tripal_set_bundle_variable('chado_column', $bundle->id, $bundle_data['field']);
|
|
|
|
|
|
- // Check to see if there are any kv-property tables associated to this
|
|
|
+ //////////////////////////////////////////////////////////////////////////////
|
|
|
+ // ADD FIELDS TO BUNDLE
|
|
|
+ ////////////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+ ////
|
|
|
+ //
|
|
|
+ // Base table fields.
|
|
|
+ //
|
|
|
+ // Adds the fields for the base table to the entity. Adds fields
|
|
|
+ // for all columns including FK fields. Excludes primary key and the
|
|
|
+ // type_id field (that's inherent in the bundle).
|
|
|
+ tripal_chado_add_bundle_base_fields($entity_type, $bundle_name, $bundle_data);
|
|
|
+
|
|
|
+ ////
|
|
|
+ //
|
|
|
+ // Property table fields.
|
|
|
+ //
|
|
|
+ // Check to see if there are any property tables with FKs to this
|
|
|
// base table. If so, add the fields for that type of table.
|
|
|
- $proptable = $bundle_data['data_table'] . 'prop';
|
|
|
- if (chado_table_exists($proptable)) {
|
|
|
- tripal_chado_add_bundle_kvproperty_adder_field($entity_type, $bundle_name, $proptable);
|
|
|
+ $prop_table = $bundle_data['data_table'] . 'prop';
|
|
|
+ if (chado_table_exists($prop_table)) {
|
|
|
+ tripal_chado_add_bundle_kvproperty_adder_field($entity_type, $bundle_name, $prop_table);
|
|
|
+ }
|
|
|
+
|
|
|
+ ////
|
|
|
+ //
|
|
|
+ // Dbxref table fields.
|
|
|
+ //
|
|
|
+ // Check to see if there are any dbxref tables with FKs to this
|
|
|
+ // base table. If so, add the fields for that type of table.
|
|
|
+ $dbxref_table = $bundle_data['data_table'] . '_dbxref';
|
|
|
+ if (chado_table_exists($dbxref_table)) {
|
|
|
+ tripal_chado_add_bundle_dbxref_field($entity_type, $bundle_name, $bundle_data['data_table'], $dbxref_table);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Adds the fields for a kv-property table fields
|
|
|
+ * Adds the fields for managing xrefs that are stored in a [base]_dbxref table.
|
|
|
+ *
|
|
|
+ * @param $entity_type
|
|
|
+ * @param $bundle_name
|
|
|
+ * @param $base_table
|
|
|
+ * @param $dbxref_table
|
|
|
+ */
|
|
|
+function tripal_chado_add_bundle_dbxref_field($entity_type_name, $bundle_name, $base_table, $dbxref_table) {
|
|
|
+ // We already have a dbxref_id field.
|
|
|
+ $field_name = $dbxref_table;
|
|
|
+
|
|
|
+ // Initialize the field array.
|
|
|
+ $field_info = array(
|
|
|
+ 'field_type' => 'dbxref',
|
|
|
+ 'widget_type' => 'tripal_fields_kvproperty_adder_widget',
|
|
|
+ 'widget_settings' => array('display_label' => 1),
|
|
|
+ 'description' => '',
|
|
|
+ 'label' => 'Cross References',
|
|
|
+ 'is_required' => 0,
|
|
|
+ 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
|
|
|
+ 'field_settings' => array(
|
|
|
+ 'chado_table' => $dbxref_table,
|
|
|
+ 'chado_column' => '',
|
|
|
+ 'semantic_web' => array(
|
|
|
+ // The type is the term from a vocabulary that desribes this field..
|
|
|
+ 'type' => '',
|
|
|
+ // The namepsace for the vocabulary (e.g. 'foaf').
|
|
|
+ 'ns' => '',
|
|
|
+ // The URL for the namespace. It must be that the type can be
|
|
|
+ // appended to the URL.
|
|
|
+ 'nsurl' => '',
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+
|
|
|
+ // If the base table has a 'dbxref_id' then change the label to
|
|
|
+ // indicate these are secondary cross references.
|
|
|
+ $schema = chado_get_schema($base_table);
|
|
|
+ if (array_key_exists('dbxref_id', $schema['fields'])) {
|
|
|
+ $field_info['label'] = 'Secondary Cross References';
|
|
|
+ }
|
|
|
+ tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
|
|
|
+}
|
|
|
+/**
|
|
|
+ * Adds the fields for managing properties that are stored in a prop table.
|
|
|
*
|
|
|
* @param $entity_type_name
|
|
|
* @param $bundle_name
|
|
|
* @param $kv_table
|
|
|
*/
|
|
|
function tripal_chado_add_bundle_kvproperty_adder_field($entity_type_name, $bundle_name, $kv_table) {
|
|
|
- // First add a generic property field so that users can add new proeprty types.
|
|
|
+ // First add a generic property field so that users can add new property types.
|
|
|
$field_name = $kv_table;
|
|
|
|
|
|
// Initialize the field array.
|
|
@@ -988,6 +1109,9 @@ function tripal_chado_add_bundle_base_fields($entity_type_name, $bundle_name, $b
|
|
|
$field_info = tripal_chado_get_table_column_field_default($table_name, $schema, $column_name);
|
|
|
|
|
|
|
|
|
+ // TODO: add in a call to drupal_alter to allow other modules to change
|
|
|
+ // the field settings.
|
|
|
+
|
|
|
// Determine if the field is required.
|
|
|
if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
|
|
|
$field_info['is_required'] = array_key_exists('default', $details) ? 0 : 1;
|
|
@@ -1004,8 +1128,7 @@ function tripal_chado_add_bundle_base_fields($entity_type_name, $bundle_name, $b
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- // If this field is a foreign key field then we will have a special custom
|
|
|
- // field provided by Tripal.
|
|
|
+ // If this field is a foreign key field then we will have a custom field.
|
|
|
$is_fk = FALSE;
|
|
|
if (array_key_exists('foreign keys', $schema)) {
|
|
|
foreach ($schema['foreign keys'] as $remote_table => $fk_details) {
|
|
@@ -1031,6 +1154,12 @@ function tripal_chado_get_table_column_field_default($table_name, $schema, $colu
|
|
|
$field = array(
|
|
|
'field_type' => '',
|
|
|
'widget_type' => '',
|
|
|
+ 'description' => '',
|
|
|
+ 'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
|
|
|
+ 'is_required' => 0,
|
|
|
+ 'widget_settings' => array(
|
|
|
+ 'display_label' => 1
|
|
|
+ ),
|
|
|
'field_settings' => array(
|
|
|
'chado_table' => $table_name,
|
|
|
'chado_column' => $column_name,
|
|
@@ -1044,12 +1173,6 @@ function tripal_chado_get_table_column_field_default($table_name, $schema, $colu
|
|
|
'nsurl' => '',
|
|
|
),
|
|
|
),
|
|
|
- 'widget_settings' => array(
|
|
|
- 'display_label' => 1
|
|
|
- ),
|
|
|
- 'description' => '',
|
|
|
- 'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
|
|
|
- 'is_required' => 0,
|
|
|
);
|
|
|
|
|
|
// Alter the field info array depending on the column details.
|
|
@@ -1136,8 +1259,8 @@ function tripal_chado_get_table_column_field_default($table_name, $schema, $colu
|
|
|
elseif ($field['field_settings']['chado_column'] =='dbxref_id') {
|
|
|
$field['field_type'] = 'dbxref_id';
|
|
|
$field['widget_type'] = 'tripal_chado_primary_dbxref_widget';
|
|
|
- $field['label'] = 'Primary Cross Reference';;
|
|
|
- $field['description'] = 'This record can be cross-referenced with a ' .
|
|
|
+ $field['label'] = '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 ' .
|
|
@@ -1332,22 +1455,22 @@ function tripal_chado_entity_property_info_alter(&$info) {
|
|
|
* The rendered value of the field specified by $field_name.
|
|
|
*/
|
|
|
function tripal_chado_entity_property_get_value($entity, $options, $field_name, $entity_type) {
|
|
|
-
|
|
|
- $display = array(
|
|
|
- 'type' => '',
|
|
|
- 'label' => 'hidden',
|
|
|
- );
|
|
|
-
|
|
|
- $langcode = LANGUAGE_NONE;
|
|
|
- $items = field_get_items($entity_type, $entity, $field_name);
|
|
|
- if (count($items) == 1) {
|
|
|
- $render_array = field_view_value($entity_type, $entity, $field_name, $items[0], $display, $langcode);
|
|
|
- }
|
|
|
- // @todo: handle fields with multiple values.
|
|
|
- else {
|
|
|
- $render_array = field_view_value($entity_type, $entity, $field_name, $items[0], $display, $langcode);
|
|
|
- drupal_set_message('Tripal Chado currently only supports views integration for single value fields. The first value has been shown.', 'warning');
|
|
|
- }
|
|
|
+
|
|
|
+ $display = array(
|
|
|
+ 'type' => '',
|
|
|
+ 'label' => 'hidden',
|
|
|
+ );
|
|
|
+
|
|
|
+ $langcode = LANGUAGE_NONE;
|
|
|
+ $items = field_get_items($entity_type, $entity, $field_name);
|
|
|
+ if (count($items) == 1) {
|
|
|
+ $render_array = field_view_value($entity_type, $entity, $field_name, $items[0], $display, $langcode);
|
|
|
+ }
|
|
|
+ // @todo: handle fields with multiple values.
|
|
|
+ else {
|
|
|
+ $render_array = field_view_value($entity_type, $entity, $field_name, $items[0], $display, $langcode);
|
|
|
+ drupal_set_message('Tripal Chado currently only supports views integration for single value fields. The first value has been shown.', 'warning');
|
|
|
+ }
|
|
|
|
|
|
return drupal_render($render_array);
|
|
|
}
|