Эх сурвалжийг харах

Fixed problem with 'Cancel' button on TripalEntity entities

Stephen Ficklin 8 жил өмнө
parent
commit
bd089a112e

+ 29 - 22
tripal/includes/TripalEntityUIController.inc

@@ -338,18 +338,24 @@ function tripal_view_entity($entity, $view_mode = 'full') {
        '#name' => 'update_data',
        '#weight' => 1000
      );
+
+     // Put the delete button on the far-right so that it's harder
+     // to accidentally click it.
      $form['delete_button'] = array(
        '#type' => 'submit',
        '#value' => t('Delete'),
        '#name' => 'delete_data',
-       '#weight' => 1002
+       '#weight' => 1002,
+       '#attributes' => array('style' => 'float: right')
      );
    }
    $form['cancel_button'] = array(
      '#type' => 'submit',
      '#value' => t('Cancel'),
      '#name' => 'cancel_data',
-     '#weight' => 1001
+     '#weight' => 1001,
+     '#limit_validation_errors' => array(array('')),
+     '#submit' => array('tripal_entity_form_submit'),
    );
 
    // The entity object must be added to the $form_state in order for
@@ -389,6 +395,21 @@ function tripal_entity_form_ajax_callback($form, $form_state) {
  function tripal_entity_form_submit($form, &$form_state) {
    $entity = $form_state['TripalEntity'];
 
+   if ($form_state['clicked_button']['#name'] =='cancel_data') {
+     if (property_exists($entity, 'id')) {
+       $form_state['redirect'] = "bio_data/" . $entity->id;
+     }
+     else {
+       $form_state['redirect'] = 'bio_data/add';
+     }
+     return;
+   }
+
+   if ($form_state['clicked_button']['#name'] =='delete_data') {
+     $form_state['redirect'] = 'bio_data/' . $entity->id .'/delete';
+     return;
+   }
+
    // Allow the fields to perform actions prior to submit by calling
    // a hook_field_submit() functino.
    $fields = field_info_instances('TripalEntity', $entity->bundle);
@@ -413,28 +434,14 @@ function tripal_entity_form_ajax_callback($form, $form_state) {
      }
    }
 
-   if ($form_state['clicked_button']['#name'] =='cancel_data') {
-     if ($entity) {
-      $form_state['redirect'] = "bio_data/" . $entity->id;
-     }
-     else {
-       $form_state['redirect'] = '';
-     }
-   }
-   if ($form_state['clicked_button']['#name'] =='update_data' or
-       $form_state['clicked_button']['#name'] =='add_data') {
-
-     $entityform = entity_ui_controller('TripalEntity')->entityFormSubmitBuildEntity($form, $form_state);
-     if ($entityform->save()) {
-       $form_state['redirect'] = "bio_data/" . $entity->id;
-     }
-     else {
-       drupal_set_message('Cannot save entity', 'error');
-     }
+   $entityform = entity_ui_controller('TripalEntity')->entityFormSubmitBuildEntity($form, $form_state);
+   if ($entityform->save()) {
+     $form_state['redirect'] = "bio_data/" . $entity->id;
    }
-   if ($form_state['clicked_button']['#name'] =='delete_data') {
-     $form_state['redirect'] = 'bio_data/' . $entity->id .'/delete';
+   else {
+     drupal_set_message('Cannot save entity', 'error');
    }
+
  }
 
 

+ 4 - 3
tripal_chado/includes/fields/chado_linker__relationship.inc

@@ -319,7 +319,7 @@ class chado_linker__relationship extends TripalField {
       $object_name = $item['object_name'];
 
 
-      // If the row is empty then just return, there's nothing to validate.
+      // If the row is empty then just continue, there's nothing to validate.
       if (!$type_name and !$subject_name and !$object_name) {
         continue;
       }
@@ -423,10 +423,11 @@ class chado_linker__relationship extends TripalField {
         );
       }
 
-      if ($object_id == $chado_record_id  and $subject_id == $chado_record_id) {
+      // Make sure that the object and subject are not both the same thing.
+      if ($object_id == $subject_id) {
         $errors[$field['field_name']][$langcode][$delta][] = array(
           'error' => 'chado_linker__relationship',
-          'message' =>  t("The subject and the object in the relationship cannot both refer to this record."),
+          'message' =>  t("The subject and the object in the relationship cannot both refer to the same record."),
         );
       }
     }