Browse Source

Reworked entity save function to write fields after entity is saved

Stephen Ficklin 9 years ago
parent
commit
383e8f3c08
1 changed files with 11 additions and 13 deletions
  1. 11 13
      tripal_entities/includes/TripalEntityController.inc

+ 11 - 13
tripal_entities/includes/TripalEntityController.inc

@@ -93,24 +93,11 @@ class TripalEntityController extends EntityAPIController {
       $invocation = 'entity_update';
       $pkeys = array('id');
     }
-    // Now we need to either insert or update the fields which are
-    // attached to this entity. We use the same primary_keys logic
-    // to determine whether to update or insert, and which hook we
-    // need to invoke.
-    if ($invocation == 'entity_insert') {
-      field_attach_insert($entity->entity_type, $entity);
-    }
-    else {
-      field_attach_update($entity->entity_type, $entity);
-    }
 
     // Invoke hook_entity_presave().
     module_invoke_all('entity_presave', $entity, $entity->entity_type);
 
     // Write out the entity record.
-    /* $tablename = 'feature';
-    $schema = chado_get_schema($tablename);
-    $pkey_field = $schema['primary key'][0]; */
     $record = array(
       'type'      => $entity->entity_type,
       'bundle'    => $entity->bundle,
@@ -127,6 +114,17 @@ class TripalEntityController extends EntityAPIController {
       $entity->id = $record['id'];
     }
 
+    // Now we need to either insert or update the fields which are
+    // attached to this entity. We use the same primary_keys logic
+    // to determine whether to update or insert, and which hook we
+    // need to invoke.
+    if ($invocation == 'entity_insert') {
+      field_attach_insert($entity->entity_type, $entity);
+    }
+    else {
+      field_attach_update($entity->entity_type, $entity);
+    }
+
     // Invoke either hook_entity_update() or hook_entity_insert().
     module_invoke_all($invocation, $entity, $entity->entity_type);