|
@@ -1,57 +1,34 @@
|
|
|
<?php
|
|
|
|
|
|
-function tripal_chado_field_widget_info() {
|
|
|
- return array(
|
|
|
- 'chado_base_dbxref_id' => array(
|
|
|
- 'label' => 'Site specific Accession',
|
|
|
- 'field types' => array('tripal_key_value'),
|
|
|
- ),
|
|
|
- 'chado_base_organism_id' => array(
|
|
|
- 'label' => 'Organism',
|
|
|
- 'field types' => array('tripal_key_value')
|
|
|
- ),
|
|
|
- 'chado_feature_md5checsum' => array(
|
|
|
- 'label' => 'Sequence Checksum',
|
|
|
- 'field types' => array('tripal_key_value')
|
|
|
- ),
|
|
|
- 'chado_feature_residues' => array(
|
|
|
- 'label' => 'Sequence',
|
|
|
- 'field types' => array('tripal_key_value')
|
|
|
- ),
|
|
|
- 'chado_feature_seqlen' => array(
|
|
|
- 'label' => 'Sequence Length',
|
|
|
- 'field types' => array('tripal_key_value')
|
|
|
- ),
|
|
|
- 'chado_gene_transcripts' => array(
|
|
|
- 'label' => 'Transcripts',
|
|
|
- 'field types' => array('tripal_key_value')
|
|
|
- ),
|
|
|
- 'chado_linker_contact' => array(
|
|
|
- 'label' => 'Contacts',
|
|
|
- 'field types' => array('tripal_key_value')
|
|
|
- ),
|
|
|
- 'chado_linker_dbxref' => array(
|
|
|
- 'label' => 'Cross References',
|
|
|
- 'field types' => array('tripal_key_value')
|
|
|
- ),
|
|
|
- 'chado_linker_expression' => array(
|
|
|
- 'label' => 'Expression',
|
|
|
- 'field types' => array('tripal_key_value')
|
|
|
- ),
|
|
|
- 'chado_linker_featureloc' => array(
|
|
|
- 'label' => 'Positions',
|
|
|
- 'field types' => array('tripal_key_value')
|
|
|
- ),
|
|
|
- );
|
|
|
+/**
|
|
|
+ * Implements hook_chado_bundle_create().
|
|
|
+ *
|
|
|
+ * This is a Tripal hook. It allows any module to perform tasks after
|
|
|
+ * a bundle has been created.
|
|
|
+ *
|
|
|
+ * @param $bundle
|
|
|
+ * The TripalBundle object.
|
|
|
+ */
|
|
|
+
|
|
|
+function tripal_chado_bundle_create($bundle) {
|
|
|
+ $entity_type = $bundle->type;
|
|
|
+
|
|
|
+ // Create/Add the new fields for this bundle.
|
|
|
+ tripal_chado_bundle_create_fields($entity_type, $bundle);
|
|
|
+
|
|
|
+ // Create/Add the new field instances for this bundle.
|
|
|
+ tripal_chado_bundle_create_instances($entity_type, $bundle);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* Implements hook_field_create_info().
|
|
|
*
|
|
|
* This is a Tripal defined hook that supports integration with the
|
|
|
* TripalEntity field.
|
|
|
*/
|
|
|
-function tripal_chado_create_tripalfields2($entity_type, $bundle) {
|
|
|
+function tripal_chado_bundle_create_fields($entity_type, $bundle) {
|
|
|
|
|
|
// Get the table this bundle is mapped to.
|
|
|
$term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
|
|
@@ -74,21 +51,36 @@ function tripal_chado_create_tripalfields2($entity_type, $bundle) {
|
|
|
$info = array();
|
|
|
|
|
|
// Create the fields for each column in the table.
|
|
|
- tripal_chado_create_tripalfields_base($info, $details, $entity_type, $bundle);
|
|
|
+ tripal_chado_bundle_create_fields_base($info, $details, $entity_type, $bundle);
|
|
|
|
|
|
// Create custom fields.
|
|
|
- tripal_chado_create_tripalfields_custom($info, $details, $entity_type, $bundle);
|
|
|
-
|
|
|
+ tripal_chado_bundle_create_fields_custom($info, $details, $entity_type, $bundle);
|
|
|
+dpm($info);
|
|
|
// Create fields for linking tables.
|
|
|
- tripal_chado_create_tripalfields_linker($info, $details, $entity_type, $bundle);
|
|
|
+ //tripal_chado_bundle_create_fields_linker($info, $details, $entity_type, $bundle);
|
|
|
|
|
|
- return $info;
|
|
|
+ foreach ($info as $field_name => $details) {
|
|
|
+ $field_type = $details['type'];
|
|
|
+
|
|
|
+ // If the field already exists then skip it.
|
|
|
+ $field = field_info_field($details['field_name']);
|
|
|
+ if ($field) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Create the field.
|
|
|
+ $field = field_create_field($details);
|
|
|
+ if (!$field) {
|
|
|
+ tripal_set_message(t("Could not create new field: %field.",
|
|
|
+ array('%field' => $details['field_name'])), TRIPAL_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
/**
|
|
|
*
|
|
|
* @param unknown $details
|
|
|
*/
|
|
|
-function tripal_chado_create_tripalfields_base(&$info, $details, $entity_type, $bundle) {
|
|
|
+function tripal_chado_bundle_create_fields_base(&$info, $details, $entity_type, $bundle) {
|
|
|
|
|
|
$table_name = $details['chado_table'];
|
|
|
$type_table = $details['chado_type_table'];
|
|
@@ -218,7 +210,7 @@ function tripal_chado_create_tripalfields_base(&$info, $details, $entity_type, $
|
|
|
*
|
|
|
* @param unknown $details
|
|
|
*/
|
|
|
-function tripal_chado_create_tripalfields_custom(&$info, $details, $entity_type, $bundle) {
|
|
|
+function tripal_chado_bundle_create_fields_custom(&$info, $details, $entity_type, $bundle) {
|
|
|
$table_name = $details['chado_table'];
|
|
|
$type_table = $details['chado_type_table'];
|
|
|
$type_field = $details['chado_type_column'];
|
|
@@ -226,10 +218,11 @@ function tripal_chado_create_tripalfields_custom(&$info, $details, $entity_type,
|
|
|
$cvterm_id = $details['chado_cvterm_id'];
|
|
|
$schema = chado_get_schema($table_name);
|
|
|
|
|
|
- // BASE DBXREF
|
|
|
- if (array_key_exists('dbxref_id', $schema['fields'])) {
|
|
|
- $field_name = $table_name . '__dbxref_id';
|
|
|
- $field_type = 'chado_base__dbxref_id';
|
|
|
+
|
|
|
+ // BASE ORGANISM_ID
|
|
|
+ if ($table_name != 'organism' and array_key_exists('organism_id', $schema['fields'])) {
|
|
|
+ $field_name = $bundle->name . '_obi__organism';
|
|
|
+ $field_type = 'obi__organism';
|
|
|
$info[$field_name] = array(
|
|
|
'field_name' => $field_name,
|
|
|
'type' => $field_type,
|
|
@@ -240,16 +233,16 @@ function tripal_chado_create_tripalfields_custom(&$info, $details, $entity_type,
|
|
|
),
|
|
|
'settings' => array(
|
|
|
'chado_table' => $table_name,
|
|
|
- 'chado_column' => 'dbxref_id',
|
|
|
- 'semantic_web' => tripal_get_chado_semweb_term($table_name, 'dbxref_id'),
|
|
|
+ 'chado_column' => 'organism_id',
|
|
|
),
|
|
|
);
|
|
|
}
|
|
|
+ return;
|
|
|
|
|
|
- // BASE ORGANISM_ID
|
|
|
- if ($table_name != 'organism' and array_key_exists('organism_id', $schema['fields'])) {
|
|
|
- $field_name = $table_name . '__organism_id';
|
|
|
- $field_type = 'chado_base__organism_id';
|
|
|
+ // BASE DBXREF
|
|
|
+ if (array_key_exists('dbxref_id', $schema['fields'])) {
|
|
|
+ $field_name = $table_name . '__dbxref_id';
|
|
|
+ $field_type = 'chado_base__dbxref_id';
|
|
|
$info[$field_name] = array(
|
|
|
'field_name' => $field_name,
|
|
|
'type' => $field_type,
|
|
@@ -260,12 +253,14 @@ function tripal_chado_create_tripalfields_custom(&$info, $details, $entity_type,
|
|
|
),
|
|
|
'settings' => array(
|
|
|
'chado_table' => $table_name,
|
|
|
- 'chado_column' => 'organism_id',
|
|
|
- 'semantic_web' => tripal_get_chado_semweb_term($table_name, 'organism_id'),
|
|
|
+ 'chado_column' => 'dbxref_id',
|
|
|
+ 'semantic_web' => tripal_get_chado_semweb_term($table_name, 'dbxref_id'),
|
|
|
),
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
// FEATURE MD5CHECKSUM
|
|
|
if ($table_name == 'feature') {
|
|
|
$field_name = $table_name . '__md5checksum';
|
|
@@ -373,7 +368,7 @@ function tripal_chado_create_tripalfields_custom(&$info, $details, $entity_type,
|
|
|
*
|
|
|
* @param unknown $details
|
|
|
*/
|
|
|
-function tripal_chado_create_tripalfields_linker(&$info, $details, $entity_type, $bundle) {
|
|
|
+function tripal_chado_bundle_create_fields_linker(&$info, $details, $entity_type, $bundle) {
|
|
|
|
|
|
$table_name = $details['chado_table'];
|
|
|
$type_table = $details['chado_type_table'];
|
|
@@ -663,7 +658,7 @@ function tripal_chado_create_tripalfields_linker(&$info, $details, $entity_type,
|
|
|
* This is a Tripal defined hook that supports integration with the
|
|
|
* TripalEntity field.
|
|
|
*/
|
|
|
-function tripal_chado_create_tripalfield_instance2($entity_type, $bundle) {
|
|
|
+function tripal_chado_bundle_create_instances($entity_type, $bundle) {
|
|
|
|
|
|
$term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
|
|
|
$vocab = $term->vocab;
|
|
@@ -682,11 +677,22 @@ function tripal_chado_create_tripalfield_instance2($entity_type, $bundle) {
|
|
|
'chado_type_column' => $mapped_table->chado_field,
|
|
|
);
|
|
|
|
|
|
- tripal_chado_create_tripalfield_instance_base($info, $entity_type, $bundle, $details);
|
|
|
- tripal_chado_create_tripalfield_instance_custom($info, $entity_type, $bundle, $details);
|
|
|
- tripal_chado_create_tripalfield_instance_linker($info, $entity_type, $bundle, $details);
|
|
|
+ tripal_chado_bundle_create_instances_base($info, $entity_type, $bundle, $details);
|
|
|
+ tripal_chado_bundle_create_instances_custom($info, $entity_type, $bundle, $details);
|
|
|
+ //tripal_chado_bundle_create_instances_linker($info, $entity_type, $bundle, $details);
|
|
|
+
|
|
|
+ foreach ($info as $field_name => $details) {
|
|
|
+ // If the field is already attached to this bundle then skip it.
|
|
|
+ $field = field_info_field($details['field_name']);
|
|
|
+ if ($field and array_key_exists('bundles', $field) and
|
|
|
+ array_key_exists('TripalEntity', $field['bundles']) and
|
|
|
+ in_array($bundle_name, $field['bundles']['TripalEntity'])) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // Create the field instance.
|
|
|
+ $instance = field_create_instance($details);
|
|
|
+ }
|
|
|
|
|
|
- return $info;
|
|
|
}
|
|
|
/**
|
|
|
* Helper function for the hook_create_tripalfield_instance().
|
|
@@ -697,7 +703,7 @@ function tripal_chado_create_tripalfield_instance2($entity_type, $bundle) {
|
|
|
* @param $bundle
|
|
|
* @param $details
|
|
|
*/
|
|
|
-function tripal_chado_create_tripalfield_instance_base(&$info, $entity_type, $bundle, $details) {
|
|
|
+function tripal_chado_bundle_create_instances_base(&$info, $entity_type, $bundle, $details) {
|
|
|
$fields = array();
|
|
|
|
|
|
// Get Chado information
|
|
@@ -873,7 +879,7 @@ function tripal_chado_create_tripalfield_instance_base(&$info, $entity_type, $bu
|
|
|
* @param $bundle
|
|
|
* @param $details
|
|
|
*/
|
|
|
-function tripal_chado_create_tripalfield_instance_custom(&$info, $entity_type, $bundle, $details) {
|
|
|
+function tripal_chado_bundle_create_instances_custom(&$info, $entity_type, $bundle, $details) {
|
|
|
$table_name = $details['chado_table'];
|
|
|
$type_table = $details['chado_type_table'];
|
|
|
$type_field = $details['chado_type_column'];
|
|
@@ -881,22 +887,26 @@ function tripal_chado_create_tripalfield_instance_custom(&$info, $entity_type, $
|
|
|
$cvterm_id = $details['chado_cvterm_id'];
|
|
|
$schema = chado_get_schema($table_name);
|
|
|
|
|
|
- // BASE DBXREF
|
|
|
- if (array_key_exists('dbxref_id', $schema['fields'])) {
|
|
|
- $field_name = $table_name . '__dbxref_id';
|
|
|
- $info[$field_name] = array(
|
|
|
+ // BASE ORGANISM_ID
|
|
|
+ if ($table_name != 'organism' and array_key_exists('organism_id', $schema['fields'])) {
|
|
|
+ $field_name = $bundle->name . '_obi__organism';
|
|
|
+ $is_required = FALSE;
|
|
|
+ if (array_key_exists('not null', $schema['fields']['organism_id']) and
|
|
|
+ $schema['fields']['organism_id']['not null']) {
|
|
|
+ $is_required = TRUE;
|
|
|
+ }
|
|
|
+ $info[$field_name] = array(
|
|
|
'field_name' => $field_name,
|
|
|
'entity_type' => $entity_type,
|
|
|
'bundle' => $bundle->name,
|
|
|
- 'label' => 'Accession',
|
|
|
- 'description' => 'This field specifies the unique stable accession (ID) for
|
|
|
- this record. It requires that this site have a database entry.',
|
|
|
- 'required' => FALSE,
|
|
|
+ 'label' => 'Organism',
|
|
|
+ 'description' => 'Select an organism.',
|
|
|
+ 'required' => $is_required,
|
|
|
'settings' => array(
|
|
|
'auto_attach' => TRUE,
|
|
|
),
|
|
|
'widget' => array(
|
|
|
- 'type' => 'chado_base__dbxref_id_widget',
|
|
|
+ 'type' => 'obi__organism_widget',
|
|
|
'settings' => array(
|
|
|
'display_label' => 1,
|
|
|
),
|
|
@@ -904,33 +914,30 @@ function tripal_chado_create_tripalfield_instance_custom(&$info, $entity_type, $
|
|
|
'display' => array(
|
|
|
'default' => array(
|
|
|
'label' => 'inline',
|
|
|
- 'type' => 'chado_base__dbxref_id_formatter',
|
|
|
+ 'type' => 'obi__organism_formatter',
|
|
|
'settings' => array(),
|
|
|
),
|
|
|
),
|
|
|
);
|
|
|
}
|
|
|
+ return;
|
|
|
|
|
|
- // BASE ORGANISM_ID
|
|
|
- if ($table_name != 'organism' and array_key_exists('organism_id', $schema['fields'])) {
|
|
|
- $field_name = $table_name . '__organism_id';
|
|
|
- $is_required = FALSE;
|
|
|
- if (array_key_exists('not null', $schema['fields']['organism_id']) and
|
|
|
- $schema['fields']['organism_id']['not null']) {
|
|
|
- $is_required = TRUE;
|
|
|
- }
|
|
|
- $info[$field_name] = array(
|
|
|
+ // BASE DBXREF
|
|
|
+ if (array_key_exists('dbxref_id', $schema['fields'])) {
|
|
|
+ $field_name = $table_name . '__dbxref_id';
|
|
|
+ $info[$field_name] = array(
|
|
|
'field_name' => $field_name,
|
|
|
'entity_type' => $entity_type,
|
|
|
'bundle' => $bundle->name,
|
|
|
- 'label' => 'Organism',
|
|
|
- 'description' => 'Select an organism.',
|
|
|
- 'required' => $is_required,
|
|
|
+ 'label' => 'Accession',
|
|
|
+ 'description' => 'This field specifies the unique stable accession (ID) for
|
|
|
+ this record. It requires that this site have a database entry.',
|
|
|
+ 'required' => FALSE,
|
|
|
'settings' => array(
|
|
|
'auto_attach' => TRUE,
|
|
|
),
|
|
|
'widget' => array(
|
|
|
- 'type' => 'chado_base__organism_id_widget',
|
|
|
+ 'type' => 'chado_base__dbxref_id_widget',
|
|
|
'settings' => array(
|
|
|
'display_label' => 1,
|
|
|
),
|
|
@@ -938,7 +945,7 @@ function tripal_chado_create_tripalfield_instance_custom(&$info, $entity_type, $
|
|
|
'display' => array(
|
|
|
'default' => array(
|
|
|
'label' => 'inline',
|
|
|
- 'type' => 'chado_base__organism_id_formatter',
|
|
|
+ 'type' => 'chado_base__dbxref_id_formatter',
|
|
|
'settings' => array(),
|
|
|
),
|
|
|
),
|
|
@@ -1106,7 +1113,7 @@ function tripal_chado_create_tripalfield_instance_custom(&$info, $entity_type, $
|
|
|
* @param unknown $bundle
|
|
|
* @param unknown $details
|
|
|
*/
|
|
|
-function tripal_chado_create_tripalfield_instance_linker(&$info, $entity_type, $bundle, $details) {
|
|
|
+function tripal_chado_bundle_create_instances_linker(&$info, $entity_type, $bundle, $details) {
|
|
|
|
|
|
$table_name = $details['chado_table'];
|
|
|
$type_table = $details['chado_type_table'];
|