1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675 |
- <?php
- /**
- * Implements hook_field_create_info().
- *
- * This is a Tripal defined hook that supports integration with the
- * TripalEntity field.
- */
- function tripal_chado_bundle_create_fields($entity_type, $bundle, $chado_bundle) {
- // Get the details about the mapping of this bundle to the Chado table:
- $details = array(
- 'chado_cvterm_id' => $chado_bundle['type_id'],
- 'chado_table' => $chado_bundle['data_table'],
- 'chado_type_table' => $chado_bundle['type_linker_table'],
- 'chado_type_column' => $chado_bundle['type_column'],
- );
- $info = array();
- // Create the fields for each column in the table.
- tripal_chado_bundle_create_fields_base($info, $details, $entity_type, $bundle);
- // Create custom fields.
- tripal_chado_bundle_create_fields_custom($info, $details, $entity_type, $bundle);
- // Create fields for linking tables.
- tripal_chado_bundle_create_fields_linker($info, $details, $entity_type, $bundle);
- 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_bundle_create_fields_base(&$info, $details, $entity_type, $bundle) {
- $table_name = $details['chado_table'];
- $type_table = $details['chado_type_table'];
- $type_field = $details['chado_type_column'];
- $cvterm_id = $details['chado_cvterm_id'];
- // Iterate through the columns of the table and see if fields have been
- // created for each one. If not, then create them.
- $schema = chado_get_schema($table_name);
- if (!$schema) {
- return;
- }
- $pkey = $schema['primary key'][0];
- // Get the list of columns for this table and create a new field for each one.
- $columns = $schema['fields'];
- foreach ($columns as $column_name => $details) {
- // Don't create base fields for the primary key and the type_id field.
- if ($column_name == $pkey or $column_name == $type_field) {
- continue;
- }
- $cvterm = tripal_get_chado_semweb_term($table_name, $column_name, array('return_object' => TRUE));
- if (!$cvterm) {
- tripal_report_error('tripal', TRIPAL_ERROR,
- 'Cannot create field for "%table_name.%column_name". Missing an appropriate vocabulary term',
- array('%table_name' => $table_name, '%column_name' => $column_name));
- drupal_set_message(t('Cannot create field for "%table_name.%column_name". Missing an appropriate vocabulary term',
- array('%table_name' => $table_name, '%column_name' => $column_name)), 'error');
- continue;
- }
- $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/ /', '_', $cvterm->name));
- // Skip the primary key field.
- if ($column_name == $schema['primary key'][0]) {
- continue;
- }
- // Skip the type field.
- if ($table_name == $type_table and $column_name == $type_field) {
- continue;
- }
- // Set some defaults for the field.
- $base_info = array(
- 'field_name' => $field_name,
- 'type' => '',
- 'cardinality' => 1,
- 'locked' => TRUE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- // Alter the field info array depending on the column details.
- switch($details['type']) {
- case 'char':
- $base_info['type'] = 'text';
- $base_info['settings']['max_length'] = $details['length'];
- break;
- case 'varchar':
- $base_info['type'] = 'text';
- $base_info['settings']['max_length'] = $details['length'];
- break;
- case 'text':
- $base_info['type'] = 'text';
- $base_info['settings']['max_length'] = 17179869184;
- $base_info['settings']['text_processing'] = 1;
- break;
- case 'blob':
- // not sure how to support a blob field.
- continue;
- break;
- case 'int':
- $base_info['type'] = 'number_integer';
- break;
- case 'float':
- $base_info['type'] = 'number_float';
- $base_info['settings']['precision'] = 10;
- $base_info['settings']['scale'] = 2;
- $base_info['settings']['decimal_separator'] = '.';
- break;
- case 'numeric':
- $base_info['type'] = 'number_decimal';
- break;
- case 'serial':
- // Serial fields are most likely not needed as a field.
- break;
- case 'boolean':
- $base_info['type'] = 'list_boolean';
- $base_info['settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
- break;
- case 'datetime':
- // Use the Drupal Date and Date API to create the field/widget
- $base_info['type'] = 'datetime';
- break;
- }
- // Set some default semantic web information
- if ($column_name == 'uniquename') {
- $base_info['settings']['text_processing'] = 0;
- }
- //
- // PUB TABLE
- //
- elseif ($table_name == 'pub' and $column_name == 'uniquename') {
- $base_info['type'] = 'text';
- $base_info['settings']['text_processing'] = 0;
- }
- //
- // ANALYSIS TABLE
- //
- elseif ($table_name == 'analysis' and $column_name == 'sourceuri') {
- $base_info['type'] = 'text';
- $base_info['settings']['text_processing'] = 0;
- }
- $info[$field_name] = $base_info;
- }
- }
- /**
- *
- * @param unknown $details
- */
- 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'];
- $cvterm_id = $details['chado_cvterm_id'];
- $schema = chado_get_schema($table_name);
- // BASE ORGANISM_ID
- if ($table_name != 'organism' and
- array_key_exists('organism_id', $schema['fields'])) {
- $field_name = 'obi__organism';
- $field_type = 'obi__organism';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => TRUE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // BASE DBXREF
- if (array_key_exists('dbxref_id', $schema['fields'])) {
- $field_name = 'data__accession';
- $field_type = 'data__accession';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => TRUE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // FEATURE MD5CHECKSUM
- if ($table_name == 'feature') {
- $field_name = 'data__sequence_checksum';
- $field_type = 'data__sequence_checksum';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => TRUE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // FEATURE RESIDUES
- if ($table_name == 'feature') {
- $field_name = 'data__sequence';
- $field_type = 'data__sequence';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => TRUE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // FEATURE SEQLEN
- if ($table_name == 'feature') {
- $field_name = 'data__sequence_length';
- $field_type = 'data__sequence_length';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => TRUE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // GENE TRANSCRIPTS
- $rel_table = $table_name . '_relationship';
- if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
- $field_name = 'so__transcript';
- $field_type = 'so__transcript';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => TRUE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // ORGANISM TYPE_ID
- // if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
- // $field_name = 'taxarank__infraspecific_taxon';
- // $field_type = 'taxarank__infraspecific_taxon';
- // $info[$field_name] = array(
- // 'field_name' => $field_name,
- // 'type' => $field_type,
- // 'cardinality' => 1,
- // 'locked' => TRUE,
- // 'storage' => array(
- // 'type' => 'field_chado_storage',
- // ),
- // 'settings' => array(
- // ),
- // );
- // }
- }
- /**
- *
- * @param unknown $details
- */
- function tripal_chado_bundle_create_fields_linker(&$info, $details, $entity_type, $bundle) {
- $table_name = $details['chado_table'];
- $type_table = $details['chado_type_table'];
- $type_field = $details['chado_type_column'];
- $cvterm_id = $details['chado_cvterm_id'];
- // CONTACTS
- $contact_table = $table_name . '_contact';
- if (chado_table_exists($contact_table)) {
- $schema = chado_get_schema($contact_table);
- $pkey = $schema['primary key'][0];
- $field_name = $table_name . '_contact';
- $field_type = 'chado_linker__contact';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => TRUE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // DBXREF
- $dbxref_table = $table_name . '_dbxref';
- if (chado_table_exists($dbxref_table)) {
- $field_name = 'sbo__database_cross_reference';
- $field_type = 'sbo__database_cross_reference';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => TRUE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // EXPRESSION
- $expression_table = $table_name . '_expression';
- if (chado_table_exists($expression_table)) {
- $field_name = 'go__gene_expression';
- $field_type = 'go__gene_expression';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => TRUE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // FEATURELOC
- if ($table_name == 'feature') {
- $field_name = 'data__sequence_coordinates';
- $field_type = 'data__sequence_coordinates';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => TRUE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // FEATUREPOS
- if ($table_name == 'feature') {
- $field_name = 'ogi__location_on_map';
- $field_type = 'ogi__location_on_map';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => TRUE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // GENOTYPE
- $genotype_table = $table_name . '_genotype';
- if (chado_table_exists($genotype_table)) {
- $field_name = 'so__genotype';
- $field_type = 'so__genotype';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => TRUE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // PHENOTYPE
- $phenotype_table = $table_name . '_phenotype';
- if (chado_table_exists($phenotype_table)) {
- $field_name = 'sbo__phenotype';
- $field_type = 'sbo__phenotype';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => TRUE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // PROPERTIES
- $prop_table = $table_name . 'prop';
- if (chado_table_exists($prop_table)) {
- // Get the list of existing property types for this table.
- $sql = 'SELECT DISTINCT type_id FROM {' . $prop_table . '}';
- $props = chado_query($sql);
- while ($prop = $props->fetchObject()) {
- $term = chado_generate_var('cvterm', array('cvterm_id' => $prop->type_id));
- $field_name = strtolower(preg_replace('/[^\w]/','_', $term->dbxref_id->db_id->name . '__' . $term->name));
- $field_type = 'chado_linker__prop';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => 1,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- }
- // PUBLICATIONS
- $pub_table = $table_name . '_pub';
- if (chado_table_exists($pub_table)) {
- $field_name = 'schema__publication';
- $field_type = 'schema__publication';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => TRUE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // RELATIONSHIPS
- // If the linker table does not exists then we don't want to add attach.
- $rel_table = $table_name . '_relationship';
- if (chado_table_exists($rel_table)) {
- $field_name = 'sbo__relationship';
- $field_type = 'sbo__relationship';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => TRUE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- );
- }
- // SYNONYMS
- $syn_table = $table_name . '_synonym';
- if (chado_table_exists($syn_table)) {
- $field_name = 'schema__alternate_name';
- $field_type = 'schema__alternate_name';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => TRUE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- ),
- );
- }
- }
- /**
- * Impelments hook_create_tripalfield_instance().
- *
- * This is a Tripal defined hook that supports integration with the
- * TripalEntity field.
- */
- function tripal_chado_bundle_create_instances($entity_type, $bundle, $chado_bundle) {
- $details = array(
- 'chado_cvterm_id' => $chado_bundle['type_id'],
- 'chado_table' => $chado_bundle['data_table'],
- 'chado_type_table' => $chado_bundle['type_linker_table'],
- 'chado_type_column' => $chado_bundle['type_column'],
- );
- 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);
- }
- }
- /**
- * Helper function for the hook_create_tripalfield_instance().
- *
- * Add the field instances that corresond to the columns of the base table.
- *
- * @param $entity_type
- * @param $bundle
- * @param $details
- */
- function tripal_chado_bundle_create_instances_base(&$info, $entity_type, $bundle, $details) {
- $fields = array();
- // Get Chado information
- $table_name = $details['chado_table'];
- $type_table = $details['chado_type_table'];
- $type_field = $details['chado_type_column'];
- $cvterm_id = $details['chado_cvterm_id'];
- // Iterate through the columns of the table and see if fields have been
- // created for each one. If not, then create them.
- $schema = chado_get_schema($table_name);
- if (!$schema) {
- return;
- }
- $pkey = $schema['primary key'][0];
- $columns = $schema['fields'];
- foreach ($columns as $column_name => $details) {
- // Don't create base fields for the primary key and the type_id field.
- if ($column_name == $pkey or $column_name == $type_field) {
- continue;
- }
- $cvterm = tripal_get_chado_semweb_term($table_name, $column_name, array('return_object' => TRUE));
- if (!$cvterm) {
- // We already provided an error when creating the base field. So
- // don't create another one here.
- continue;
- }
- $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/ /', '_', $cvterm->name));
- // Skip the primary key field.
- if ($column_name == $schema['primary key'][0]) {
- continue;
- }
- // Skip the type field.
- if ($table_name == $type_table and $column_name == $type_field) {
- continue;
- }
- $base_info = array(
- 'field_name' => $field_name,
- 'entity_type' => 'TripalEntity',
- 'bundle' => $bundle->name,
- 'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
- 'description' => '',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => TRUE,
- 'term_vocabulary' => $cvterm->dbxref_id->db_id->name,
- 'term_name' => $cvterm->name,
- 'term_accession' => $cvterm->dbxref_id->accession,
- 'chado_table' => $table_name,
- 'chado_column' => $column_name,
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'settings' => array(),
- ),
- ),
- );
- // Determine if the field is required.
- if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
- $base_info['required'] = TRUE;
- }
- // Alter the field info array depending on the column details.
- switch($details['type']) {
- case 'char':
- $base_info['widget']['type'] = 'text_textfield';
- break;
- case 'varchar':
- $base_info['widget']['type'] = 'text_textfield';
- break;
- case 'text':
- $base_info['widget']['type'] = 'text_textarea';
- $base_info['widget']['settings']['format'] = filter_default_format();
- break;
- case 'blob':
- // not sure how to support a blob field.
- continue;
- break;
- case 'int':
- $base_info['widget']['type'] = 'number';
- break;
- case 'float':
- $base_info['widget']['type'] = 'number';
- break;
- case 'numeric':
- $base_info['widget']['type'] = 'number';
- break;
- case 'serial':
- // Serial fields are most likely not needed as a field.
- break;
- case 'boolean':
- $base_info['widget']['type'] = 'options_onoff';
- $base_info['required'] = FALSE;
- break;
- case 'datetime':
- $base_info['widget']['type'] = 'date_select';
- $base_info['widget']['settings']['increment'] = 1;
- $base_info['widget']['settings']['tz_handling'] = 'none';
- $base_info['widget']['settings']['collapsible'] = TRUE;
- // TODO: Add settings so that the minutes increment by 1.
- // And turn off the timezone, as the Chado field doesn't support it.
- break;
- }
- // Set some default semantic web information
- if ($column_name == 'uniquename') {
- $base_info['label'] = 'Identifier';
- $base_info['widget_type'] = 'text_textfield';
- }
- elseif ($base_info['label'] == 'Timeaccessioned') {
- $base_info['label'] = 'Time Accessioned';
- $base_info['description'] = 'Please enter the time that this record was first added to the database.';
- }
- elseif ($base_info['label'] == 'Timelastmodified') {
- $base_info['label'] = 'Time Last Modified';
- $base_info['description'] = 'Please enter the time that this record was last modified. The default is the current time.';
- }
- //
- // ORGANISM TABLE
- //
- elseif ($table_name == 'organism' and $column_name == 'comment') {
- $base_info['label'] = 'Description';
- }
- //
- // PUB TABLE
- //
- elseif ($table_name == 'pub' and $column_name == 'uniquename') {
- $base_info['widget_type'] = 'text_textfield';
- }
- //
- // ANALYSIS TABLE
- //
- elseif ($table_name == 'analysis' and $column_name == 'program') {
- $base_info['description'] = 'The program name (e.g. blastx, blastp, sim4, genscan. If the analysis was not derived from a software package then provide a very brief description of the pipeline, workflow or method.';
- $base_info['label'] = 'Program, Pipeline, Workflow or Method Name.';
- }
- elseif ($table_name == 'analysis' and $column_name == 'sourceuri') {
- $base_info['widget_type'] = 'text_textfield';
- $base_info['label'] = 'Source URL';
- $base_info['description'] = 'The URL where the original source data was derived. Ideally, this should link to the page where more information about the source data can be found.';
- }
- elseif ($table_name == 'analysis' and $column_name == 'sourcename') {
- $base_info['label'] = 'Source Name';
- $base_info['description'] = 'The name of the source data. This could be a file name, data set or a small description for how the data was collected. For long descriptions use the larger description field.';
- }
- elseif ($table_name == 'analysis' and $column_name == 'sourceversion') {
- $base_info['label'] = 'Source Version';
- $base_info['description'] = 'If hte source data set has a version include it here.';
- }
- elseif ($table_name == 'analysis' and $column_name == 'algorithm') {
- $base_info['label'] = 'Source Version';
- $base_info['description'] = 'The name of the algorithm used to produce the dataset if different from the program.';
- }
- elseif ($table_name == 'analysis' and $column_name == 'programversion') {
- $base_info['label'] = 'Program Version';
- $base_info['description'] = 'The version of the program used to perform this analysis. (e.g. TBLASTX 2.0MP-WashU [09-Nov-2000]. Enter "n/a" if no version is available or applicable.';
- }
- //
- // PROJECT TABLE
- //
- elseif ($table_name == 'project' and $column_name == 'description') {
- $base_info['label'] = 'Short Description';
- }
- $info[$field_name] = $base_info;
- }
- }
- /**
- * Helper function for the hook_create_tripalfield_instance().
- *
- * Adds custom fields for base fields. These override the settings provided
- * in the tripal_chado_create_tripalfield_instance_base() function.
- *
- * @param $entity_type
- * @param $bundle
- * @param $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'];
- $cvterm_id = $details['chado_cvterm_id'];
- $schema = chado_get_schema($table_name);
- // BASE ORGANISM_ID
- if ($table_name != 'organism' and array_key_exists('organism_id', $schema['fields'])) {
- $field_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' => 'Organism',
- 'description' => 'Select an organism.',
- 'required' => $is_required,
- 'settings' => array(
- 'auto_attach' => TRUE,
- 'chado_table' => $table_name,
- 'chado_column' => 'organism_id',
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'obi__organism_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'obi__organism_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // BASE DBXREF
- if (array_key_exists('dbxref_id', $schema['fields'])) {
- $field_name = 'data__accession';
- $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,
- 'settings' => array(
- 'auto_attach' => TRUE,
- 'chado_table' => $table_name,
- 'chado_column' => 'dbxref_id',
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'data__accession_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'data__accession_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // FEATURE MD5CHECKSUM
- if ($table_name == 'feature') {
- $field_name = 'data__sequence_checksum';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Sequence Checksum',
- 'description' => 'The MD5 checksum for the sequence. The checksum here
- will always be unique for the raw unformatted sequence. To verify that the
- sequence has not been corrupted, download the raw sequence and use an MD5 tool
- to calculate the value. If the value calculated is identical the one shown
- here, then the downloaded sequence is uncorrupted.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => TRUE,
- 'chado_table' => $table_name,
- 'chado_column' => 'md5checksum',
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'data__sequence_checksum_widget',
- 'settings' => array(
- 'display_label' => 1,
- 'md5_fieldname' => 'feature__md5checksum',
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'data__sequence_checksum_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // FEATURE RESIDUES
- if ($table_name == 'feature') {
- $field_name = 'data__sequence';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Sequence',
- 'description' => 'All available sequences for this record.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => $table_name,
- 'chado_column' => 'residues',
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'data__sequence_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'data__sequence_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // FEATURE SEQLEN
- if ($table_name == 'feature') {
- $field_name = 'data__sequence_length';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Sequence Length',
- 'description' => 'The number of residues in the raw sequence. This length
- is only for the assigned raw sequence and does not represent the length of any
- sequences derived from alignments. If this value is zero but aligned sequences
- are present then this record has no official assigned sequence.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => TRUE,
- 'chado_table' => $table_name,
- 'chado_column' => 'seqlen',
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'data__sequence_length_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'data__sequence_length_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // GENE TRANSCRIPTS
- $rel_table = $table_name . '_relationship';
- if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
- $field_name = 'so__transcript';
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Transcripts',
- 'description' => 'Transcripts that are part of this gene.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => $rel_table,
- 'chado_column' => '',
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'so__transcript_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'so__transcript_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // ORGANISM TYPE_ID
- // if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
- // $field_name = 'taxarank__infraspecific_taxon';
- // $info[$field_name] = array(
- // 'field_name' => $field_name,
- // 'entity_type' => $entity_type,
- // 'bundle' => $bundle->name,
- // 'label' => 'Infraspecific Taxon',
- // 'description' => 'The Infraspecific Taxon.',
- // 'required' => FALSE,
- // 'settings' => array(
- // 'auto_attach' => TRUE,
- // 'chado_table' => 'organism',
- // 'chado_column' => 'type_id',
- // 'base_table' => 'organism',
- // ),
- // 'widget' => array(
- // 'type' => 'taxarank__infraspecific_taxon_widget',
- // 'settings' => array(
- // 'display_label' => 1,
- // ),
- // ),
- // 'display' => array(
- // 'default' => array(
- // 'label' => 'inline',
- // 'type' => 'taxarank__infraspecific_taxon_formatter',
- // 'settings' => array(),
- // ),
- // ),
- // );
- // }
- }
- /**
- *
- * @param unknown $entity_type
- * @param unknown $bundle
- * @param unknown $details
- */
- function tripal_chado_bundle_create_instances_linker(&$info, $entity_type, $bundle, $details) {
- $table_name = $details['chado_table'];
- $type_table = $details['chado_type_table'];
- $type_field = $details['chado_type_column'];
- $cvterm_id = $details['chado_cvterm_id'];
- // CONTACTS
- $contact_table = $table_name . '_contact';
- if (chado_table_exists($contact_table)) {
- $field_name = $table_name . '_contact';
- $info[$field_name] = $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Contact',
- 'description' => 'Associates an indviddual or organization with this record',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => $contact_table,
- 'base_table' => $table_name,
- 'chado_column' => 'contact_id',
- ),
- 'widget' => array(
- 'type' => 'local__contact_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'local__contact_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // DBXREF
- $dbxref_table = $table_name . '_dbxref';
- if (chado_table_exists($dbxref_table)) {
- $field_name = 'sbo__database_cross_reference';
- $schema = chado_get_schema($dbxref_table);
- $pkey = $schema['primary key'][0];
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Database Cross Reference',
- 'description' => 'The IDs where this record may be available in other external online databases.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => $dbxref_table,
- 'chado_column' => $pkey,
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'sbo__database_cross_reference_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'sbo__database_cross_reference_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // EXPRESSION
- $expression_table = $table_name . '_expression';
- if (chado_table_exists($expression_table)) {
- $field_name = 'go__gene_expression';
- $schema = chado_get_schema($expression_table);
- $pkey = $schema['primary key'][0];
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Gene expression',
- 'description' => 'Information about the expression of this record.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => $expression_table,
- 'chado_column' => $pkey,
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'go__gene_expression_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'go__gene_expression_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // FEATURELOC
- if ($table_name == 'feature') {
- $field_name = 'data__sequence_coordinates';
- $schema = chado_get_schema('featureloc');
- $pkey = $schema['primary key'][0];
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Sequence Coordinates',
- 'description' => 'The locations on other genomic sequences where this
- record has been aligned.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => 'featureloc',
- 'chado_column' => $pkey,
- 'base_table' => 'feature',
- ),
- 'widget' => array(
- 'type' => 'data__sequence_coordinates_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'data__sequence_coordinates_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // FEATUREPOS
- if ($table_name == 'feature') {
- $field_name = 'ogi__location_on_map';
- $schema = chado_get_schema('featurepos');
- $pkey = $schema['primary key'][0];
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Location on Map',
- 'description' => 'The positions on a genetic map.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => 'featurepos',
- 'chado_column' => $pkey,
- 'base_table' => 'feature',
- ),
- 'widget' => array(
- 'type' => 'ogi__location_on_map_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'ogi__location_on_map_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // GENOTYPE
- $genotype_table = $table_name . '_genotype';
- if (chado_table_exists($genotype_table)) {
- $field_name = 'so__genotype';
- $schema = chado_get_schema($genotype_table);
- $pkey = $schema['primary key'][0];
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Genotype',
- 'description' => 'The genotypes associated with this record.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => $genotype_table,
- 'chado_column' => $pkey,
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'so__genotype_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'so__genotype_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // PHENOTYPE
- $phenotype_table = $table_name . '_phenotype';
- if (chado_table_exists($phenotype_table)) {
- $field_name = 'sbo__phenotype';
- $schema = chado_get_schema($phenotype_table);
- $pkey = $schema['primary key'][0];
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Phenotype',
- 'description' => 'The phenotypes associated with this record.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => $phenotype_table,
- 'chado_column' => $pkey,
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'sbo__phenotype_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'sbo__phenotype_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // PROPERTIES
- $prop_table = $table_name . 'prop';
- if (chado_table_exists($prop_table)) {
- // Get the list of existing property types for this table.
- $sql = 'SELECT DISTINCT type_id FROM {' . $prop_table . '}';
- $props = chado_query($sql);
- $schema = chado_get_schema($prop_table);
- $pkey = $schema['primary key'][0];
- while ($prop = $props->fetchObject()) {
- $term = chado_generate_var('cvterm', array('cvterm_id' => $prop->type_id));
- $field_name = strtolower(preg_replace('/[^\w]/','_', $term->dbxref_id->db_id->name . '__' . $term->name));
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => ucwords(preg_replace('/_/', ' ', $term->name)),
- 'description' => $term->definition,
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => TRUE,
- 'term_vocabulary' => $term->dbxref_id->db_id->name,
- 'term_accession' => $term->dbxref_id->accession,
- 'term_name' => $term->name,
- 'base_table' => $table_name,
- 'chado_table' => $prop_table,
- 'chado_column' => $pkey,
- ),
- 'widget' => array(
- 'type' => 'chado_linker__prop_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'chado_linker__prop_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- }
- // PUBLICATIONS
- $pub_table = $table_name . '_pub';
- if (chado_table_exists($pub_table)) {
- $field_name = 'schema__publication';
- $schema = chado_get_schema($pub_table);
- $pkey = $schema['primary key'][0];
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Publication',
- 'description' => 'This record has been referenced or is sourced from these publications.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => $pub_table,
- 'chado_column' => $pkey,
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'schema__publication_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'schema__publication_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // RELATIONSHIPS
- // If the linker table does not exists then we don't want to add attach.
- $rel_table = $table_name . '_relationship';
- if (chado_table_exists($rel_table)) {
- $field_name = 'sbo__relationship';
- $schema = chado_get_schema($rel_table);
- $pkey = $schema['primary key'][0];
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Relationship',
- 'description' => 'Other records with relationships to this record.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => $rel_table,
- 'chado_column' => $pkey,
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'sbo__relationship_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'sbo__relationship_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- // SYNONYMS
- $syn_table = $table_name . '_synonym';
- if (chado_table_exists($syn_table)) {
- $field_name = 'schema__alternate_name';
- $schema = chado_get_schema($syn_table);
- $pkey = $schema['primary key'][0];
- $info[$field_name] = array(
- 'field_name' => $field_name,
- 'entity_type' => $entity_type,
- 'bundle' => $bundle->name,
- 'label' => 'Synonyms',
- 'description' => 'Alternate names, aliases or synonyms for this record.',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => FALSE,
- 'chado_table' => $syn_table,
- 'chado_column' => $pkey,
- 'base_table' => $table_name,
- ),
- 'widget' => array(
- 'type' => 'schema__alternate_name_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'schema__alternate_name_formatter',
- 'settings' => array(),
- ),
- ),
- );
- }
- }
- /**
- * Implements hook_form_FORM_ID_alter().
- *
- * 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
- // on the add/edit form of an entity for adding new property fields.
- $fields_names = element_children($form['fields']);
- foreach ($fields_names as $field_name) {
- $field_info = field_info_field($field_name);
- if ($field_info['type'] == 'kvproperty_adder') {
- unset($form['fields'][$field_name]);
- }
- if ($field_info['type'] == 'cvterm_class_adder') {
- unset($form['fields'][$field_name]);
- }
- }
- }
- /**
- * Implements hook_form_field_ui_field_overview_add_new().
- */
- function tripal_chado_form_field_ui_field_overview_add_new($new_field, $bundle) {
- // Get the table this bundle is mapped to.
- $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
- $vocab = $term->vocab;
- $params = array(
- 'vocabulary' => $vocab->vocabulary,
- 'accession' => $term->accession,
- );
- $mapped_table = chado_get_cvterm_mapping($params);
- $chado_table = $mapped_table->chado_table;
- $chado_type_table = $mapped_table->chado_table;
- $chado_type_column = $mapped_table->chado_field;
- // We allow site admins to add new chado_linker__prop fields to an entity.
- // This function will allow us to properly add them. But at this point we
- // don't know the controlled vocabulary term. We'll have to use the
- // defaults and let the user set it using the interface.
- if ($new_field['type'] == 'chado_linker__prop') {
- $table_name = $chado_table . 'prop';
- if (chado_table_exists($table_name)) {
- $schema = chado_get_schema($table_name);
- $pkey = $schema['primary key'][0];
- $field_name = $new_field['field_name'];
- $field_type = 'chado_linker__prop';
- // First add the field.
- field_create_field(array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'base_table' => $chado_table,
- 'chado_table' => $table_name,
- 'chado_column' => $pkey,
- ),
- ));
- // Now add the instance
- field_create_instance(array(
- 'field_name' => $field_name,
- 'entity_type' => 'TripalEntity',
- 'bundle' => $bundle->name,
- 'label' => $new_field['label'],
- 'description' => '',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => TRUE,
- ),
- 'widget' => array(
- 'type' => 'chado_linker__prop_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'chado_linker__prop_formatter',
- 'settings' => array(),
- ),
- ),
- ));
- }
- else {
- drupal_set_message('Cannot add a property field to this entity. Chado does not support properties for this data type.', 'error');
- }
- }
- // We allow site admins to add new chado_linker__cvterm fields to an entity.
- // This function will allow us to properly add them. But at this point we
- // don't know the controlled vocabulary term. We'll have to use the
- // defaults and let the user set it using the interface.
- if ($new_field['type'] == 'chado_linker__cvterm') {
- $table_name = $chado_table . '_cvterm';
- if (chado_table_exists($table_name)) {
- $schema = chado_get_schema($table_name);
- $pkey = $schema['primary key'][0];
- $field_name = $new_field['field_name'];
- $field_type = 'chado_linker__cvterm';
- // First add the field.
- field_create_field(array(
- 'field_name' => $field_name,
- 'type' => $field_type,
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'base_table' => $chado_table,
- 'chado_table' => $table_name,
- 'chado_column' => $pkey,
- ),
- ));
- // Now add the instance
- field_create_instance(array(
- 'field_name' => $field_name,
- 'entity_type' => 'TripalEntity',
- 'bundle' => $bundle->name,
- 'label' => $new_field['label'],
- 'description' => '',
- 'required' => FALSE,
- 'settings' => array(
- 'auto_attach' => TRUE,
- ),
- 'widget' => array(
- 'type' => 'chado_linker__cvterm_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'above',
- 'type' => 'chado_linker__cvterm_formatter',
- 'settings' => array(),
- ),
- ),
- ));
- }
- else {
- drupal_set_message('Cannot add a property field to this entity. Chado does not support annotations for this data type.', 'error');
- }
- }
- }
- /**
- * Allows for altering of a field's instance setting form.
- *
- * This appears to be a Drupal hook but is actually a custom function created
- * by this module. It is called by the tripal_form_alter() function of this
- * module.
- *
- * Here we put additional form elements for any field, regardless if it is
- * a tripalField or not.
- *
- * @param $form
- * The form array. Alterations to the form can be made within this array.
- * @param $form_state
- * The form state array.
- */
- function tripal_chado_field_instance_settings_form_alter(&$form, $form_state) {
- global $language;
- $field = $form['#field'];
- $instance = $form['#instance'];
- // Construct a table for the vocabulary information.
- $headers = array();
- $rows = array();
- $rows[] = array(
- array(
- 'data' => 'Base Table',
- 'header' => TRUE,
- 'width' => '20%',
- ),
- $instance['settings']['base_table']
- );
- $rows[] = array(
- array(
- 'data' => 'Record Table',
- 'header' => TRUE,
- 'width' => '20%',
- ),
- $instance['settings']['chado_table']
- );
- $rows[] = array(
- array(
- 'data' => 'ID Column',
- 'header' => TRUE,
- 'width' => '20%',
- ),
- $instance['settings']['chado_column']
- );
- $table = array(
- 'header' => $headers,
- 'rows' => $rows,
- 'attributes' => array(
- ),
- 'sticky' => FALSE,
- 'caption' => '',
- 'colgroups' => array(),
- 'empty' => '',
- );
- $form['chado_mapping'] = array(
- '#type' => 'fieldset',
- '#title' => 'Chado Mapping',
- '#description' => t('This field maps to data in Chado to the following table:'),
- );
- $form['chado_mapping']['details'] = array(
- '#type' => 'item',
- '#markup' => theme_table($table),
- );
- }
- /**
- * Implements hook_form_FROM_ID_alter()
- */
- function tripal_chado_form_tripalbundle_form_alter(&$form, $form_state) {
- global $language;
- $bundle = $form['#bundle'];
- $term = entity_load('TripalTerm', array('id' => $bundle->term_id));
- $term = reset($term);
- $vocab = $term->vocab;
- $params = array(
- 'vocabulary' => $vocab->vocabulary,
- 'accession' => $term->accession,
- );
- $mapped_table = chado_get_cvterm_mapping($params);
- $chado_table = $mapped_table->chado_table;
- $chado_column = $mapped_table->chado_field;
- // Construct a table for the vocabulary information.
- $headers = array();
- $rows = array();
- $rows[] = array(
- array(
- 'data' => 'Chado Table',
- 'header' => TRUE,
- 'width' => '20%',
- ),
- $chado_table
- );
- $rows[] = array(
- array(
- 'data' => 'Type Column',
- 'header' => TRUE,
- 'width' => '20%',
- ),
- $chado_column
- );
- $table = array(
- 'header' => $headers,
- 'rows' => $rows,
- 'attributes' => array(
- ),
- 'sticky' => FALSE,
- 'caption' => '',
- 'colgroups' => array(),
- 'empty' => '',
- );
- $form['chado_mapping'] = array(
- '#type' => 'item',
- '#title' => 'Chado Mapping',
- '#markup' => theme_table($table),
- '#description' => t('This content type maps to the table in Chado
- listed above. Chado allows multiple data types to be housed
- in a single table. Therefore, the column that is used to
- differentiate between data types is also listed above.'),
- '#weight' => 0,
- );
- }
|