|
@@ -1,6 +1,5 @@
|
|
|
<?php
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* Implements hook_entity_create().
|
|
|
*
|
|
@@ -20,7 +19,7 @@ function tripal_chado_entity_create(&$entity, $type, $bundle = NULL) {
|
|
|
|
|
|
// Set some defaults on vars needed by this module.
|
|
|
if (!property_exists($entity, 'chado_table')) {
|
|
|
- $entity->chado_table = NULL;
|
|
|
+ $entity->chado_table = NULL;
|
|
|
$entity->chado_column = NULL;
|
|
|
$entity->chado_linker = NULL;
|
|
|
$entity->chado_type_id = NULL;
|
|
@@ -29,7 +28,7 @@ function tripal_chado_entity_create(&$entity, $type, $bundle = NULL) {
|
|
|
|
|
|
// Add in the Chado table information for this entity type.
|
|
|
if (!$bundle) {
|
|
|
- $bundle = tripal_load_bundle_entity(array('name' => $entity->bundle));
|
|
|
+ $bundle = tripal_load_bundle_entity(['name' => $entity->bundle]);
|
|
|
}
|
|
|
if ($bundle->data_table) {
|
|
|
$entity->chado_table = $bundle->data_table;
|
|
@@ -46,6 +45,7 @@ function tripal_chado_entity_create(&$entity, $type, $bundle = NULL) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* Implements hook_entity_presave().
|
|
|
*/
|
|
@@ -97,7 +97,7 @@ function tripal_chado_entity_load($entities, $type) {
|
|
|
$entity->chado_record_id = NULL;
|
|
|
|
|
|
// Add in the Chado table information for this entity type.
|
|
|
- $bundle = tripal_load_bundle_entity(array('name' => $entity->bundle));
|
|
|
+ $bundle = tripal_load_bundle_entity(['name' => $entity->bundle]);
|
|
|
if (!$bundle) {
|
|
|
continue;
|
|
|
}
|
|
@@ -112,7 +112,8 @@ function tripal_chado_entity_load($entities, $type) {
|
|
|
->fetchObject();
|
|
|
if ($chado_entity) {
|
|
|
$schema = chado_get_schema($entity->chado_table);
|
|
|
- $record = chado_generate_var($entity->chado_table, array($schema['primary key'][0] => $chado_entity->record_id));
|
|
|
+ $record = chado_generate_var($entity->chado_table,
|
|
|
+ [$schema['primary key'][0] => $chado_entity->record_id]);
|
|
|
$entity->chado_record = $record;
|
|
|
$entity->chado_record_id = $chado_entity->record_id;
|
|
|
}
|
|
@@ -157,107 +158,107 @@ function tripal_chado_entity_delete($entity, $type) {
|
|
|
* Overrides the default titles.
|
|
|
*/
|
|
|
function tripal_chado_tripal_default_title_format($bundle, $available_tokens) {
|
|
|
- $format = array();
|
|
|
+ $format = [];
|
|
|
|
|
|
$table = $bundle->data_table;
|
|
|
|
|
|
if ($table == 'organism') {
|
|
|
if (chado_get_version() <= '1.2') {
|
|
|
- $format[] = array(
|
|
|
+ $format[] = [
|
|
|
'format' => '[taxrank__genus] [taxrank__species]',
|
|
|
- 'weight' => -5
|
|
|
- );
|
|
|
+ 'weight' => -5,
|
|
|
+ ];
|
|
|
}
|
|
|
else {
|
|
|
- $format[] = array(
|
|
|
+ $format[] = [
|
|
|
'format' => '[taxrank__genus] [taxrank__species] [taxrank__infraspecific_taxon,TAXRANK:0000045]',
|
|
|
- 'weight' => -5
|
|
|
- );
|
|
|
+ 'weight' => -5,
|
|
|
+ ];
|
|
|
}
|
|
|
}
|
|
|
if ($table == 'arraydesign') {
|
|
|
- $format[] = array(
|
|
|
+ $format[] = [
|
|
|
'format' => '[schema__name]',
|
|
|
- 'weight' => -5
|
|
|
- );
|
|
|
+ 'weight' => -5,
|
|
|
+ ];
|
|
|
}
|
|
|
if ($table == 'assay') {
|
|
|
- $format[] = array(
|
|
|
+ $format[] = [
|
|
|
'format' => '[schema__name]',
|
|
|
- 'weight' => -5
|
|
|
- );
|
|
|
+ 'weight' => -5,
|
|
|
+ ];
|
|
|
}
|
|
|
if ($table == 'biomaterial') {
|
|
|
- $format[] = array(
|
|
|
+ $format[] = [
|
|
|
'format' => '[schema__name]',
|
|
|
- 'weight' => -5
|
|
|
- );
|
|
|
+ 'weight' => -5,
|
|
|
+ ];
|
|
|
}
|
|
|
if ($table == 'analysis') {
|
|
|
- $format[] = array(
|
|
|
+ $format[] = [
|
|
|
'format' => '[schema__name]',
|
|
|
- 'weight' => -5
|
|
|
- );
|
|
|
+ 'weight' => -5,
|
|
|
+ ];
|
|
|
}
|
|
|
if ($table == 'feature') {
|
|
|
- $format[] = array(
|
|
|
+ $format[] = [
|
|
|
'format' => '[schema__name]',
|
|
|
- 'weight' => -5
|
|
|
- );
|
|
|
+ 'weight' => -5,
|
|
|
+ ];
|
|
|
}
|
|
|
if ($table == 'featuremap') {
|
|
|
- $format[] = array(
|
|
|
+ $format[] = [
|
|
|
'format' => '[schema__name]',
|
|
|
- 'weight' => -5
|
|
|
- );
|
|
|
+ 'weight' => -5,
|
|
|
+ ];
|
|
|
}
|
|
|
if ($table == 'stock') {
|
|
|
- $format[] = array(
|
|
|
+ $format[] = [
|
|
|
'format' => '[schema__name]',
|
|
|
- 'weight' => -5
|
|
|
- );
|
|
|
+ 'weight' => -5,
|
|
|
+ ];
|
|
|
}
|
|
|
if ($table == 'pub') {
|
|
|
- $format[] = array(
|
|
|
+ $format[] = [
|
|
|
'format' => '[tpub__title]',
|
|
|
'weight' => -5,
|
|
|
- );
|
|
|
+ ];
|
|
|
}
|
|
|
if ($table == 'cvterm') {
|
|
|
- $format[] = array(
|
|
|
+ $format[] = [
|
|
|
'format' => '[schema__name]',
|
|
|
'weight' => -5,
|
|
|
- );
|
|
|
+ ];
|
|
|
}
|
|
|
if ($table == 'project') {
|
|
|
- $format[] = array(
|
|
|
+ $format[] = [
|
|
|
'format' => '[schema__name]',
|
|
|
'weight' => -5,
|
|
|
- );
|
|
|
+ ];
|
|
|
}
|
|
|
if ($table == 'contact') {
|
|
|
- $format[] = array(
|
|
|
+ $format[] = [
|
|
|
'format' => '[schema__name]',
|
|
|
'weight' => -5,
|
|
|
- );
|
|
|
+ ];
|
|
|
}
|
|
|
if ($table == 'phylotree') {
|
|
|
- $format[] = array(
|
|
|
+ $format[] = [
|
|
|
'format' => '[schema__name]',
|
|
|
'weight' => -5,
|
|
|
- );
|
|
|
+ ];
|
|
|
}
|
|
|
if ($table == 'library') {
|
|
|
- $format[] = array(
|
|
|
+ $format[] = [
|
|
|
'format' => '[schema__name]',
|
|
|
'weight' => -5,
|
|
|
- );
|
|
|
+ ];
|
|
|
}
|
|
|
if ($table == 'protocol') {
|
|
|
- $format[] = array(
|
|
|
+ $format[] = [
|
|
|
'format' => '[schema__name]',
|
|
|
'weight' => -5,
|
|
|
- );
|
|
|
+ ];
|
|
|
}
|
|
|
return $format;
|
|
|
}
|
|
@@ -270,36 +271,37 @@ function tripal_chado_entity_view($entity, $type, $view_mode, $langcode) {
|
|
|
// If this entity is a TripalEntity and is a full view, then
|
|
|
// we want to support the legacy view, but only if the legacy
|
|
|
// module is enabled (the functions exist).
|
|
|
- if ($type =='TripalEntity') {
|
|
|
+ if ($type == 'TripalEntity') {
|
|
|
// Use the generic template to render the fields
|
|
|
if ($view_mode == 'full') {
|
|
|
|
|
|
// Get the Chado table for this data type.
|
|
|
- $bundle = tripal_load_bundle_entity(array('name' => $entity->bundle));
|
|
|
+ $bundle = tripal_load_bundle_entity(['name' => $entity->bundle]);
|
|
|
$chado_table = $bundle->data_table;
|
|
|
$chado_field = $bundle->type_column;
|
|
|
|
|
|
// Get the list of templates that should be used for entities and generatte
|
|
|
// the key in the array for this entity type (using the chado table the
|
|
|
// entity maps to).
|
|
|
- $enabled_templates = variable_get('tripal_chado_enabled_legacy_templates', array());
|
|
|
+ $enabled_templates = variable_get('tripal_chado_enabled_legacy_templates',
|
|
|
+ []);
|
|
|
$legacy_template = 'legacy_template--chado_' . $chado_table;
|
|
|
|
|
|
// If the site admin has indicated that this entity type should use
|
|
|
// a legacy tmplate then prepare the entity and content to fake a
|
|
|
// node.
|
|
|
- if (key_exists($legacy_template, $enabled_templates) && $enabled_templates[$legacy_template]) {
|
|
|
+ if (key_exists($legacy_template,
|
|
|
+ $enabled_templates) && $enabled_templates[$legacy_template]) {
|
|
|
// Remove the fields added by the chado_field_storage.
|
|
|
$fields = field_info_fields();
|
|
|
- foreach($fields as $field) {
|
|
|
- if ($field['storage']['type'] == 'field_chado_storage' or
|
|
|
- $field['storage']['type'] == 'tripal_no_storage') {
|
|
|
- $field_name = $field['field_name'];
|
|
|
- if (property_exists($entity, $field_name)) {
|
|
|
- $entity->$field_name = NULL;
|
|
|
- unset($entity->content[$field_name]);
|
|
|
- }
|
|
|
- }
|
|
|
+ foreach ($fields as $field) {
|
|
|
+ if ($field['storage']['type'] == 'field_chado_storage' or $field['storage']['type'] == 'tripal_no_storage') {
|
|
|
+ $field_name = $field['field_name'];
|
|
|
+ if (property_exists($entity, $field_name)) {
|
|
|
+ $entity->$field_name = NULL;
|
|
|
+ unset($entity->content[$field_name]);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Make the entity look like a node.
|
|
@@ -341,10 +343,12 @@ function tripal_chado_entity_view_alter(&$build) {
|
|
|
// For the legacy support, we need to make sure the TOC
|
|
|
// is built.
|
|
|
if ($build['#entity_type'] == 'TripalEntity') {
|
|
|
- $enabled_templates = variable_get('tripal_chado_enabled_legacy_templates', array());
|
|
|
+ $enabled_templates = variable_get('tripal_chado_enabled_legacy_templates',
|
|
|
+ []);
|
|
|
$entity = $build['#entity'];
|
|
|
$legacy_template = 'legacy_template--' . $entity->type;
|
|
|
- if (key_exists($legacy_template, $enabled_templates) && $enabled_templates[$legacy_template]) {
|
|
|
+ if (key_exists($legacy_template,
|
|
|
+ $enabled_templates) && $enabled_templates[$legacy_template]) {
|
|
|
$build['#entity']->nid = NULL;
|
|
|
$build['#node'] = $build['#entity'];
|
|
|
$modules = module_list();
|
|
@@ -357,3 +361,4 @@ function tripal_chado_entity_view_alter(&$build) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|