Browse Source

Working to merge all bundles into a single type

Stephen Ficklin 9 years ago
parent
commit
30aabf4370

+ 1 - 1
tripal_entities/api/tripal_entities.api.inc

@@ -40,7 +40,7 @@ function tripal_bundle_delete(TripalBundle $type) {
  */
 function tripal_entity_uri(TripalEntity $entity){
   return array(
-    'path' => 'data/' . $entity->id,
+    'path' => 'BioData/' . $entity->id,
   );
 }
 

+ 5 - 5
tripal_entities/includes/TripalBundleController.inc

@@ -14,11 +14,11 @@ class TripalBundleController extends EntityAPIControllerExportable {
     // We just want one menu item.  So to support one menu item that
     // can handle all of the Tripal entity types, we have to set the
     // 'bundle of' property here rather than in the hook_entity_info() function.
-    $bundle_of = $entityType;
-    $bundle_of = preg_replace('/_bundle/', '', $bundle_of);
-    $info = entity_get_info($bundle_of);
-    $this->bundleKey = $info['bundle keys']['bundle'];
-    $this->entityInfo['bundle of'] = $bundle_of;
+//     $bundle_of = $entityType;
+//     $bundle_of = preg_replace('/_bundle/', '', $bundle_of);
+//     $info = entity_get_info($bundle_of);
+//     $this->bundleKey = $info['bundle keys']['bundle'];
+//     $this->entityInfo['bundle of'] = $bundle_of;
   }
 
   /**

+ 4 - 4
tripal_entities/includes/TripalBundleUIController.inc

@@ -19,10 +19,10 @@ class TripalBundleUIController extends EntityDefaultUIController {
     // We just want one menu item.  So to support one menu item that
     // can handle all of the Tripal entity types, we have to set the
     // 'bundle of' property here rather than in the hook_entity_info() function.
-    $bundle_of = $entity_type;
-    $bundle_of = preg_replace('/_bundle/', '', $bundle_of);
-    $entity_info['bundle of'] = $bundle_of;
-    parent::__construct($entity_type, $entity_info);
+//     $bundle_of = $entity_type;
+//     $bundle_of = preg_replace('/_bundle/', '', $bundle_of);
+//     $entity_info['bundle of'] = $bundle_of;
+//     parent::__construct($entity_type, $entity_info);
   }
 
   /**

+ 17 - 14
tripal_entities/includes/TripalEntity.inc

@@ -35,20 +35,23 @@ class TripalEntity extends Entity {
     // If we do not have an ID then we need to do a few queries to get
     // information about the chado table this entity maps to.
     else {
-      // Use the cvterm_id to look up the base table for this term.  We find
-      // the base table by looking in the term_usage table for the mapping.
-      $sel_values = array(
-        'term_id' => array(
-          'cvterm_id' => $this->cvterm_id,
-        ),
-      );
-      $term_usage = chado_generate_var('tripal_term_usage', $sel_values, array('return_array' => 1));
+//       // Use the cvterm_id to look up the base table for this term.  We find
+//       // the base table by looking in the term_usage table for the mapping.
+//       $sel_values = array(
+//         'term_id' => array(
+//           'cvterm_id' => $this->cvterm_id,
+//         ),
+//       );
+//       $term_usage = chado_generate_var('tripal_term_usage', $sel_values, array('return_array' => 1));
 
-      // For each table that uses this term, insert the field recursively
-      foreach ($term_usage as $usage) {
-        $this->chado_table = $usage->data_table;
-        $this->chado_field = $usage->field;
-      }
+//       // For each table that uses this term, insert the field recursively
+//       foreach ($term_usage as $usage) {
+//         $this->chado_table = $usage->data_table;
+//         $this->chado_field = $usage->field;
+//       }
+      $this->chado_table = '';
+      $this->chado_field = '';
+      $this->chado_entity_id = NULL;
     }
   }
 
@@ -57,7 +60,7 @@ class TripalEntity extends Entity {
   }
 
   protected function defaultUri() {
-    return array('path' => 'data/' . $this->id);
+    return array('path' => 'BioData/' . $this->id);
   }
 
 }

+ 3 - 3
tripal_entities/includes/TripalEntityController.inc

@@ -68,7 +68,7 @@ class TripalEntityController extends EntityAPIController {
     try {
       // Invoke hook_entity_delete().
       module_invoke_all('entity_delete', $entity, $entity->type);
-      field_attach_delete($entity->type, $entity);
+      field_attach_delete('BioData', $entity);
 
       db_delete('tripal_entity')
         ->condition('id', $entity->id)
@@ -144,10 +144,10 @@ class TripalEntityController extends EntityAPIController {
       // to determine whether to update or insert, and which hook we
       // need to invoke.
       if ($invocation == 'entity_insert') {
-        field_attach_insert($entity->type, $entity);
+        field_attach_insert('BioData', $entity);
       }
       else {
-        field_attach_update($entity->type, $entity);
+        field_attach_update('BioData', $entity);
       }
 
       // Invoke either hook_entity_update() or hook_entity_insert().

+ 7 - 7
tripal_entities/includes/TripalEntityUIController.inc

@@ -41,7 +41,7 @@ class TripalEntityUIController extends EntityDefaultUIController {
     );
 
      // Set a custom page for adding new tripal data entities.
-    $items['data/add'] = array(
+    $items['BioData/add'] = array(
       'title' => 'Add Tripal data',
       'description' => 'Add a new tripal data record',
       'page callback'  => 'drupal_get_form',
@@ -55,7 +55,7 @@ class TripalEntityUIController extends EntityDefaultUIController {
     );
 
     // Link for viewing a tripal data type.
-    $items['data/' . $wildcard] = array(
+    $items['BioData/' . $wildcard] = array(
       'title callback' => 'tripal_entities_entity_title',
       'title arguments' => array(1),
       'page callback' => 'tripal_entities_view_entity',
@@ -66,7 +66,7 @@ class TripalEntityUIController extends EntityDefaultUIController {
     );
 
     // 'View' tab for an individual entity page.
-    $items['data/' . $wildcard . '/view'] = array(
+    $items['BioData/' . $wildcard . '/view'] = array(
       'title' => 'View',
       'page callback' => 'tripal_entities_view_entity',
       'page arguments' => array(1),
@@ -78,7 +78,7 @@ class TripalEntityUIController extends EntityDefaultUIController {
     );
 
     // 'Edit' tab for an individual entity page.
-    $items['data/' . $wildcard . '/edit'] = array(
+    $items['BioData/' . $wildcard . '/edit'] = array(
       'title' => 'Edit',
       'page callback' => 'drupal_get_form',
       'page arguments' => array('tripal_entities_entity_form', NULL, 1),
@@ -90,7 +90,7 @@ class TripalEntityUIController extends EntityDefaultUIController {
       'weight' => -8,
     );
 
-    $items['data/' . $wildcard . '/manage'] = array(
+    $items['BioData/' . $wildcard . '/manage'] = array(
       'title' => 'Manage',
       'page callback' => 'tripal_entity_manage_fields',
       'page arguments' => array(1),
@@ -103,7 +103,7 @@ class TripalEntityUIController extends EntityDefaultUIController {
     );
 
     // Menu item for deleting tripal data entities.
-    $items['data/' . $wildcard . '/delete'] = array(
+    $items['BioData/' . $wildcard . '/delete'] = array(
       'title'  => 'Delete',
       'page callback' => 'drupal_get_form',
       'page arguments' => array('tripal_entities_entity_delete_form', 1),
@@ -123,6 +123,6 @@ class TripalEntityUIController extends EntityDefaultUIController {
  * @param unknown $entity
  */
 function tripal_entity_manage_fields($entity) {
-  drupal_goto('admin/structure/bio_data/' . $entity->type . '/manage/' . $entity->bundle . '/fields');
+  drupal_goto('admin/structure/BioData/manage/' . $entity->bundle . '/fields');
   return '';
 }

+ 4 - 4
tripal_entities/includes/tripal_entities.admin.inc

@@ -97,14 +97,14 @@ function tripal_entities_content_overview_form($form, &$form_state) {
   while ($entity = $entities->fetchObject()) {
     $author = user_load($entity->uid);
     $rows[] = array(
-      l($entity->title, 'data/' . $entity->id),
+      l($entity->title, 'BioData/' . $entity->id),
       $entity->type,
       $entity->bundle,
       l($author->name, 'user/' . $entity->uid),
       $entity->status == 1 ? 'published' : 'unpublished',
       format_date($entity->changed, 'short'),
-      l('edit', 'data/' . $entity->id . '/edit') . '  ' .
-      l('delete', 'data/' . $entity->id . '/delete')
+      l('edit', 'BioData/' . $entity->id . '/edit') . '  ' .
+      l('delete', 'BioData/' . $entity->id . '/delete')
     );
   }
 
@@ -354,7 +354,7 @@ function tripal_entities_admin_publish_form_submit($form, &$form_state) {
 
     // Create the bundle name and entity type name.
     $bundle_name = $cvterm->dbxref_id->db_id->name . '_' . $cvterm->dbxref_id->accession;
-    $entity_type_name = $cvterm->dbxref_id->db_id->name;
+    $entity_type_name = 'BioData'; // $cvterm->dbxref_id->db_id->name;
 
     // Clear the entity cache so that Drupal will read our
     // hook_entity_info() implementation which now will have the entities

+ 19 - 22
tripal_entities/includes/tripal_entities.entity_form.inc

@@ -111,7 +111,8 @@ function tripal_entities_entity_form($form, &$form_state, $term_name = '', $enti
   // records.
   if ($num_terms == 1){
     $cvterm = $terms[0];
-    $bundle_id = $cvterm->dbxref_id->db_id->name .'_' .$cvterm->dbxref_id->accession;
+    //$bundle_id = $cvterm->dbxref_id->db_id->name .'_' .$cvterm->dbxref_id->accession;
+    $bundle_id = 'dbxref_' . $cvterm->dbxref_id->dbxref_id;
 
     $form['cv_id'] = array(
       '#type' => 'hidden',
@@ -176,9 +177,8 @@ function tripal_entities_entity_form_add_new($bundle_id, $cvterm, &$form, &$form
 
   // If the entity doesn't exist then create one.
   if (!$entity) {
-    $entity_type = $cvterm->dbxref_id->db_id->name;
-    $entity = entity_get_controller($entity_type)->create(array('bundle' => $bundle_id));
-    field_attach_form($cvterm->dbxref_id->db_id->name, $entity, $form, $form_state);
+    $entity = entity_get_controller('BioData')->create(array('bundle' => $bundle_id));
+    field_attach_form('BioData', $entity, $form, $form_state);
 
     $form['add_button'] = array(
       '#type' => 'submit',
@@ -188,7 +188,7 @@ function tripal_entities_entity_form_add_new($bundle_id, $cvterm, &$form, &$form
     );
   }
   else {
-    field_attach_form($cvterm->dbxref_id->db_id->name, $entity, $form, $form_state);
+    field_attach_form('BioData', $entity, $form, $form_state);
     $form['entity_id'] = array(
       '#type' => 'hidden',
       '#value' => $entity->id
@@ -279,7 +279,7 @@ function tripal_entities_entity_form_validate($form, &$form_state) {
       $form_state['clicked_button']['#name'] =='add_data') {
     $tripal_entity = (object) $form_state['values'];
     $entity_type = $form_state['values']['type'];
-    field_attach_form_validate($entity_type, $tripal_entity, $form, $form_state);
+    field_attach_form_validate('BioData', $tripal_entity, $form, $form_state);
   }
 }
 
@@ -425,7 +425,7 @@ function tripal_entities_entity_form_submit($form, &$form_state) {
   if ($form_state['clicked_button']['#name'] =='cancel') {
     if (array_key_exists('id', $form_state['values'])) {
       $entity_id = $form_state['values']['entity_id'];
-      $form_state['redirect'] = "data/$entity_id";
+      $form_state['redirect'] = "BioData/$entity_id";
     }
     else {
       $form_state['redirect'] = "admin/structure/tripal_entity";
@@ -442,16 +442,13 @@ function tripal_entities_entity_form_submit($form, &$form_state) {
   }
   if ($form_state['clicked_button']['#name'] =='update_data' or
       $form_state['clicked_button']['#name'] =='add_data') {
-    // Use the Entity API to get the entity from the form state, then
-    // attach the fields and save.
-    $entity_type = $form_state['values']['type'];
-    $entity = entity_ui_controller($entity_type)->entityFormSubmitBuildEntity($form, $form_state);
+    $entity = entity_ui_controller('BioData')->entityFormSubmitBuildEntity($form, $form_state);
     $entity->save();
-    $form_state['redirect'] = "data/$entity->id";
+    $form_state['redirect'] = "BioData/$entity->id";
   }
   if ($form_state['clicked_button']['#name'] =='delete_data') {
     $entity_id = $form_state['values']['entity_id'];
-    $form_state['redirect'] = 'data/' .$entity_id .'/delete';
+    $form_state['redirect'] = 'BioData/' .$entity_id .'/delete';
   }
 }
 
@@ -498,15 +495,15 @@ function tripal_entities_entity_delete_form_submit($form, &$form_state) {
  */
 function tripal_entities_add_bundle($cvterm) {
 
-  // Create the bundle name and entity type name.
-  $type = $cvterm->dbxref_id->db_id->name;
-  $bundle_name = $type . '_' . $cvterm->dbxref_id->accession;
-  $entity_type_name = $cvterm->dbxref_id->db_id->name;
+  // Create the bundle name and entity type name.  The bundle name is the
+  // dbxref ID.  This isn't very human readable, but the alternative is to
+  // use the accession which may not always be alpha-numeric.
+  $bundle_name = 'dbxref_' . $cvterm->dbxref_id->dbxref_id;
 
   // Check to see if this bundle exists. If not then create it
   $bundle = db_select('tripal_bundle', 't')
     ->fields('t')
-    ->condition('type', $type)
+    ->condition('type', 'BioData')
     ->condition('bundle', $bundle_name)
     ->execute()
     ->fetchObject();
@@ -515,18 +512,18 @@ function tripal_entities_add_bundle($cvterm) {
     // The TripalBundle Entity manages the bundles we have available.
     // Therefore, we need to add a new entity for each bundle "type".
     $vals = array(
-      'label' => $bundle_name  . ' (' . $cvterm->name . ')',
-      'type' => $entity_type_name,
+      'label' => $cvterm->name,
+      'type' => 'BioData',
       'bundle' => $bundle_name,
       'data' => serialize(array()),
       'module' => 'tripal_entities'
     );
-    $tripal_bundle = new TripalBundle($vals, $entity_type_name . '_bundle');
+    $tripal_bundle = new TripalBundle($vals, 'BioData_bundles');
     $tripal_bundle->save();
   }
 
   // Allow modules to now add fields to the bundle
-  module_invoke_all('add_bundle_fields', $entity_type_name, $bundle_name, $cvterm);
+  module_invoke_all('add_bundle_fields', 'BioData', $bundle_name, $cvterm);
 
 }
 /**

+ 2 - 4
tripal_entities/tripal_entities.install

@@ -504,7 +504,7 @@ function tripal_entities_schema() {
         'default' => '',
       ),
       'settings' => array(
-        'description' => 'Contains a serialized array of settings for the panel.',
+        'description' => 'Contains a serialized array tripal_fields_layoutof settings for the panel.',
         'type' => 'text',
         'not null' => FALSE,
       ),
@@ -585,10 +585,8 @@ function tripal_entities_schema() {
 function tripal_entities_uninstall() {
   $terms = chado_generate_var('tripal_term', array('publish' => 1), array('return_array' => 1));
   foreach ($terms as $term) {
-    $entity_type = $term->vocab_id->db_id->name;
     $bundle_id = $term->cvterm_id->dbxref_id->db_id->name . '_' . $term->cvterm_id->dbxref_id->accession;
-    print "$entity_type : $bundle_id\n";
-    field_attach_delete_bundle($entity_type, $bundle_id);
+    field_attach_delete_bundle('BioData', $bundle_id);
   }
 }
 

+ 23 - 33
tripal_entities/tripal_entities.module

@@ -38,13 +38,13 @@ function tripal_entities_menu() {
   );
 
   // The default tab.
-  $items['admin/tripal/bio_data/default'] = array(
+  $items['admin/tripal/BioData/default'] = array(
     'title' => 'Biological Data',
     'type' => MENU_DEFAULT_LOCAL_TASK,
     'weight' =>  1,
   );
 
-  $items['admin/tripal/bio_data/publish'] = array(
+  $items['admin/tripal/BioData/publish'] = array(
     'title' => 'Publish',
     'description' => 'Publish Data',
     'page callback' => 'tripal_entities_publish',
@@ -53,7 +53,7 @@ function tripal_entities_menu() {
     'type' => MENU_LOCAL_TASK,
     'weight' => 2
   );
-  $items['admin/tripal/bio_data/publish/%'] = array(
+  $items['admin/tripal/BioData/publish/%'] = array(
     'title' => 'Publish',
     'description' => 'Publish Data',
     'page callback' => 'tripal_entities_publish',
@@ -63,7 +63,7 @@ function tripal_entities_menu() {
     'type' => MENU_CALLBACK,
   );
 
-  $items['admin/tripal/bio_data/access'] = array(
+  $items['admin/tripal/BioData/access'] = array(
     'title' => 'Access',
     'description' => 'Set default access permissions for collections of data.',
     'page callback' => 'drupal_get_form',
@@ -153,13 +153,13 @@ function tripal_entities_entity_info() {
   $entities = array();
 
   // Get a list of published vocabularies from 'tripal_vocabulary
-  $published_vocs = chado_generate_var('tripal_vocabulary', array('publish' => 1), array('return_array' => 1));
+//   $published_vocs = chado_generate_var('tripal_vocabulary', array('publish' => 1), array('return_array' => 1));
 
-  foreach ($published_vocs as $voc) {
-    $entities[$voc->db_id->name] = array (
+//   foreach ($published_vocs as $voc) {
+    $entities['BioData'] = array (
       // A human readable label to identify our entity.
-      'label' => $voc->db_id->name . ' (' . $voc->cv_id->name . ')',
-      'plural label' => $voc->db_id->name . ' (' . $voc->cv_id->name . ')',
+      'label' => 'Biological Data',
+      'plural label' => 'Biological Data',
 
       // The entity class and controller class extend the classes provided by the
       // Entity API.
@@ -202,7 +202,7 @@ function tripal_entities_entity_info() {
       // key here is mean to appear on the 'Find Content' page of the
       // administrative menu.
       'admin ui' => array (
-        'path' => 'admin/content/bio_data',
+        'path' => 'admin/content/BioData',
         'controller class' => 'TripalEntityUIController',
         'menu wildcard' => '%tripal_entity',
         'file' => 'includes/TripalEntityUIController.inc'
@@ -219,8 +219,8 @@ function tripal_entities_entity_info() {
       )
     );
     // The entity that holds information about the entity types.
-    $entities [$voc->db_id->name . '_bundle'] = array (
-      'label' => $voc->db_id->name . ' (' . $voc->cv_id->name . ') Data Type',
+    $entities ['BioData_bundles'] = array (
+      'label' => 'Biological Data Type', //$voc->db_id->name . ' (' . $voc->cv_id->name . ') Data Type',
       'entity class' => 'TripalBundle',
       'controller class' => 'TripalBundleController',
       'base table' => 'tripal_bundle',
@@ -235,13 +235,13 @@ function tripal_entities_entity_info() {
       'module' => 'tripal_entities',
       // Enable the entity API's admin UI.
       'admin ui' => array (
-        'path' => 'admin/structure/bio_data/' . $voc->db_id->name,
+        'path' => 'admin/structure/BioData', // . $voc->db_id->name,
         'controller class' => 'TripalBundleUIController',
         'file' => 'includes/TripalBundleUIController.inc',
         'menu wildcard' => '%tripal_bundle',
       )
     );
-  }
+//   }
   return $entities;
 }
 /**
@@ -261,16 +261,16 @@ function tripal_entities_entity_info_alter(&$entity_info) {
     // associated with a base entity type.
     // We want to dynamically add the bundles (or term types) to the entity.
     $cvterm = $term->cvterm_id;
-    $entity_type  = $cvterm->dbxref_id->db_id->name;
+    $entity_type = 'BioData'; // $cvterm->dbxref_id->db_id->name;
     $accession = $cvterm->dbxref_id->accession;
-    $bundle_id = $entity_type . '_' . $accession;
+    $bundle_id = $cvterm->dbxref_id->db_id->name . '_' . $accession;
 
     $label = preg_replace('/_/', ' ', ucwords($cvterm->name));
     $entity_info[$entity_type]['bundles'][$bundle_id] = array (
       'label' => $label,
       'admin' => array (
-        'path' => 'admin/structure/bio_data/' . $entity_type . '/manage/%tripal_bundle',
-        'real path' => 'admin/structure/bio_data/' . $entity_type . '/manage/' . $bundle_id,
+        'path' => 'admin/structure/BioData/manage/%tripal_bundle',
+        'real path' => 'admin/structure/BioData/manage/' . $bundle_id,
         'bundle argument' => 5,
         'access arguments' => array (
           'administer tripal data types'
@@ -317,7 +317,8 @@ function tripal_entities_get_published_terms_as_select_options($cv_id = NULL) {
   foreach ($published_terms as $term) {
     if (!$cv_id) {
       $options [$term->cvterm_id->name] = $term->cvterm_id->name;
-    } else {
+    }
+    else {
       if ($term->cvterm_id->cv_id->cv_id == $cv_id) {
         $options [$term->cvterm_id->name] = $term->cvterm_id->name;
       }
@@ -345,7 +346,8 @@ function tripal_bundle_load($bundle_type, $reset = FALSE) {
 
   // Load the tripal_bundle entity. These entities are always the same
   // as an Tripal entity type but with a '_bundle' extension.
-  $entity = entity_load($bundle_types->type . '_bundle', array($bundle_types->id), array(), $reset);
+  $entity = entity_load('BioData_bundles', array($bundle_types->id), array(), $reset);
+
   return reset($entity);
 }
 
@@ -365,19 +367,7 @@ function tripal_bundle_load($bundle_type, $reset = FALSE) {
  * @see tripal_entity_load_multiple()
  */
 function tripal_entity_load($id, $reset = FALSE) {
-
-  // Get the type of entity by the ID.
-  $entity_type = db_select('tripal_entity', 'td')
-    ->fields('td', array('type'))
-    ->condition('id', $id)
-    ->execute()
-    ->fetchField();
-
-  // Load the entity.
-  if ($entity_type) {
-    $entity = entity_load($entity_type, array($id), array(), $reset);
+    $entity = entity_load('BioData', array($id), array(), $reset);
     return reset($entity);
-  }
-  return FALSE;
 }
 

+ 12 - 5
tripal_fields/includes/fields/dbxref_id.inc

@@ -45,11 +45,18 @@ function tripal_fields_dbxref_id_widget(&$widget, $form, $form_state, $field, $i
   $field_name = $field['field_name'];
 
   // Get the field defaults.
-  $dbxref_id = $items[$delta]['value'];
-  $db_id = $items[$delta]['dbxref__db_id'];
-  $accession = $items[$delta]['dbxref__accession'];
-  $version = $items[$delta]['dbxref__version'];
-  $description = $items[$delta]['dbxref__description'];
+  $dbxref_id = '';
+  $db_id = '';
+  $accession = '';
+  $version = '';
+  $description = '';
+  if (array_key_exists($delta, $items)) {
+    $dbxref_id = $items[$delta]['value'];
+    $db_id = $items[$delta]['dbxref__db_id'];
+    $accession = $items[$delta]['dbxref__accession'];
+    $version = $items[$delta]['dbxref__version'];
+    $description = $items[$delta]['dbxref__description'];
+  }
 
   // If we are here because our parent was triggered in a form submit
   // then that means an ajax call was made and we don't want the fieldset to