Browse Source

Fixed various bugs

Stephen Ficklin 8 years ago
parent
commit
52d1570eb8

+ 2 - 2
tripal/includes/TripalBundleUIController.inc

@@ -158,10 +158,10 @@ function tripal_tripal_bundle_form($form, &$form_state, $entityDataType) {
     '#description' => t('Describe this content type. The text will be displayed on the <em>Add new content page</em>.'),
   );
   if ($term) {
-    $form['description']['#default_value'] = tripal_get_bundle_variable('description', $entity_type->id, $term->definition);
+    $form['description']['#default_value'] = tripal_get_bundle_variable('description', $bundle->id, $term->definition);
   }
   else {
-    $form['description']['#default_value'] = tripal_get_bundle_variable('description', $entity_type->id, '');
+    $form['description']['#default_value'] = tripal_get_bundle_variable('description', $bundle->id, '');
   }
 
   $form['additional_settings'] = array(

+ 0 - 4
tripal/includes/TripalFields/TripalField.inc

@@ -236,10 +236,6 @@ class TripalField {
    * This is an optional hook function and is similar to the
    * hook_field_settings_form function().
    *
-   * @param $field
-   *   The field structure being configured.
-   * @param $instance
-   *   The instance structure being configured.
    * @param $has_data
    *   TRUE if the field already has data, FALSE if not.
    */

+ 69 - 66
tripal/includes/tripal.fields.inc

@@ -318,15 +318,39 @@ function tripal_module_implements_alter(&$implementations, $hook) {
  * Implements hook_field_settings_form()
  */
 function tripal_field_settings_form($field, $instance, $has_data) {
-//   $form = array();
-//   $field_type = $field['type'];
-//   //$is_loaded = tripal_load_include_field_class($field_type);
-//   tripal_load_include_field_class($field_type);
-//   if (class_exists($field_type)) {
-//     $tfield = new $field_type($field, $instance);
-//     $form = $tfield->globalSettingsForm($field, $instance, $has_data);
-//   }
-//   return $form;
+  $field_class = $field['type'];
+  if (tripal_load_include_field_class($field_type)) {
+    $field = new $field_class($field, $instance);
+    return $field->settingsForm($has_data);
+  }
+}
+
+/**
+ * Implements hook_instance_settings_form()
+ */
+function tripal_field_instance_settings_form($field, $instance) {
+  $field_class = $field['type'];
+  if (tripal_load_include_field_class($field_type)) {
+    $field = new $field_class($field, $instance);
+    return $field->instanceSettingsForm();
+  }
+}
+/**
+ * Validates the TripalField instance settings form.
+ *
+ * This function is called because the TripalField::instanceSettingsForm()
+ * adds it to the form element.  By default, Drupal does not provide a
+ * validate hook for the instance settings form.
+ */
+function tripal_field_instance_settings_form_validate($element, &$form_state, $form) {
+  $field = $element['#field'];
+  $instance = $element['#instance'];
+
+  $field_class = $field['type'];
+  if (tripal_load_include_field_class($field_type)) {
+    $field = new $field_class($field, $instance);
+    return $field->instanceSettingsForm();
+  }
 }
 
 /**
@@ -351,17 +375,17 @@ function tripal_field_instance_settings_form_alter(&$form, $form_state) {
   // function.  To make it work we have to add a process function. Inisde
   // of that process function is where the form additions get added that use
   // Ajax.
-  $form['field_term'][$language->language][0]['#process'] = array('tripal_field_instance_settings_form_process');
+  $form['field_term'][$language->language][0]['#process'] = array('tripal_field_instance_settings_form_alter_process');
   $form['#submit'][] = 'tripal_field_instance_settings_form_submit';
 }
 
 /**
- * Implements a process function for the instnace settings form.
+ * Implements a process function for the instance settings form.
  *
  * See the comment in the tripal_field_instance_settings_form_alter() for
  * more details.
  */
-function tripal_field_instance_settings_form_process($element, &$form_state, $form) {
+function tripal_field_instance_settings_form_alter_process($element, &$form_state, $form) {
   $field = $form['#field'];
   $instance = $form['#instance'];
 
@@ -528,7 +552,7 @@ function tripal_field_instance_settings_form_process($element, &$form_state, $fo
       );
     }
   }
-  $element['#element_validate'][] = 'tripal_field_instance_settings_form_validate';
+  $element['#element_validate'][] = 'tripal_field_instance_settings_form_alter_validate';
   return $element;
 }
 
@@ -538,25 +562,10 @@ function tripal_field_instance_settings_form_process($element, &$form_state, $fo
 function tripal_fields_select_term_form_ajax_callback($form, $form_state) {
   return $form['field_term'];
 }
-/**
- * Implements hook_instance_settings_form()
- */
-function tripal_field_instance_settings_form($field, $instance) {
-//   $form = array();
-//   $field_type = $field['type'];
-//   tripal_load_include_field_class($field_type);
-//   if (class_exists($field_type)) {
-//     $tfield = new $field_type($field, $instance);
-//     $form = $tfield->instanceSettingsForm();
-//   }
-//   return $form;
-}
 /**
  * Validate our custom instance settings form fields.
  */
-function tripal_field_instance_settings_form_validate($form, &$form_state) {
-  $field = $form['#field'];
-  $instance = $form['#instance'];
+function tripal_field_instance_settings_form_alter_validate($form, &$form_state) {
 
   // If the user clicked the submit button then we want set the
   // instance settings values accordingly.
@@ -588,6 +597,7 @@ function tripal_field_instance_settings_form_validate($form, &$form_state) {
         $form_state['values']['instance']['settings']['term_name'] = $term->name;
         $selected_term = TRUE;
         $num_selected++;
+        $has_default =  TRUE;
       }
     }
 
@@ -600,7 +610,9 @@ function tripal_field_instance_settings_form_validate($form, &$form_state) {
           from the "Controlled Vocabulary Term" section below.');
     }
     if (!$has_default) {
-      form_set_error('term_name', 'Fields attached to this content type must be associated with a controlled vocabulary term. Please provide one.');
+      form_set_error('new_name', 'Fields attached to this content type must ' .
+          'be associated with a controlled vocabulary term. Please ' .
+          'provide one below.');
     }
   }
 }
@@ -631,19 +643,19 @@ function tripal_field_widget_form_validate($element, &$form_state, $form) {
 /**
  * Implements hook_field_settings_form_validate().
  *
- * This is not an actual Drpual hook, but rather a Tripal created hook
- * to alow the TripalField objects to have a globalSettingsFormValidate()
- * member function.
+ * This function is called because the TripalField::settingsForm()
+ * adds it to the form element.  By default, Drupal does not provide a
+ * validate hook for the settings form.
  */
-function tripal_field_settings_form_validate($form, &$form_state) {
-//   $field = $form['#field'];
-//   $instance = $form['#instance'];
-//   $field_type = $field['type'];
-//   tripal_load_include_field_class($field_type);
-//   if (class_exists($field_type)) {
-//     $tfield = new $field_type($field, $instance);
-//     $form = $tfield->globalSettingsFormValidate($field, $instance, $form, $form_state);
-//   }
+function tripal_field_settings_form_validate($element, &$form_state, $form) {
+  $field = $element['#field'];
+  $instance = $element['#instance'];
+
+  $field_class = $field['type'];
+  if (tripal_load_include_field_class($field_type)) {
+    $field = new $field_class($field, $instance);
+    $field->settingsFormValidate($form, $form_state);
+  }
 }
 
 
@@ -651,15 +663,11 @@ function tripal_field_settings_form_validate($form, &$form_state) {
  * Implements hook_field_formatter_settings_summary().
  */
 function tripal_field_formatter_settings_summary($field, $instance, $view_mode) {
-
-//   $summary = '';
-//   $field_type = $field['type'];
-//   tripal_load_include_field_class($field_type);
-//   if (class_exists($field_type)) {
-//     $tfield = new $field_type($field, $instance);
-//     $form = $tfield->formatterSettingsSummary($view_mode);
-//   }
-//   return $summary;
+  $formatter_class = $field['type'] . '_formatter';
+  if (tripal_load_include_field_class($formatter_class)) {
+    $formatter = new $formatter_class($field, $instance);
+    return $formatter->settingsSummary($form, $form_state);
+  }
 }
 
 /**
@@ -668,14 +676,11 @@ function tripal_field_formatter_settings_summary($field, $instance, $view_mode)
 function tripal_formatter_settings_form($field, $instance,
     $view_mode, $form, &$form_state) {
 
-//   $form = array();
-//   $field_type = $field['type'];
-//   tripal_load_include_field_class($field_type);
-//   if (class_exists($field_type)) {
-//     $tfield = new $field_type($field, $instance);
-//     $form = $tfield->formatterSettingsForm($view_mode, $form, $form_state);
-//   }
-//   return $form;
+  $formatter_class = $field['type'] . '_formatter';
+  if (tripal_load_include_field_class($formatter_class)) {
+    $formatter = new $formatter_class($field, $instance);
+    return $formatter->settingsSummaryForm($view_mode, $form, $form_state);
+  }
 }
 
 
@@ -736,13 +741,11 @@ function tripal_field_widget_form_alter(&$element, &$form_state, $context) {
 function tripal_field_validate($entity_type, $entity, $field, $instance,
     $langcode, $items, &$errors) {
 
-//   $field_type = $field['type'];
-//   $is_loaded = tripal_load_include_field_class($field_type);
-//   if ($is_loaded) {
-//     $tfield = new $field_type($field, $instance);
-//     $tfield->validate($entity_type, $entity, $langcode,
-//         $items, $errors);
-//   }
+   $field_type = $field['type'];
+   if (tripal_load_include_field_class($field_type)) {
+     $tfield = new $field_type($field, $instance);
+     $tfield->validate($entity_type, $entity, $langcode,$items, $errors);
+   }
 }
 
 /**

+ 1 - 1
tripal_chado/api/tripal_chado.api.inc

@@ -164,7 +164,7 @@ function tripal_chado_publish_records($values, $job_id = NULL) {
   // Perform the query.
   $sql = $select . $from . $where;
   $records = chado_query($sql, $args);
-  $transaction  = db_transaction();
+  //$transaction  = db_transaction();
 
   print "\nNOTE: publishing records is performed using a database transaction. \n" .
       "If the load fails or is terminated prematurely then the entire set of \n" .

+ 11 - 11
tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference.inc

@@ -141,7 +141,7 @@ class sbo__database_cross_reference extends ChadoField {
 
 
     // Get the field values.
-    foreach ($form_state[$field_name] as $delta => $values) {
+    foreach ($items as $delta => $values) {
 
       // Get the field values.
       $dbxref_id = $values['chado-' . $field_table . '__dbxref_id'];
@@ -158,23 +158,23 @@ class sbo__database_cross_reference extends ChadoField {
       // we borrow the code from the 'form_error' function and append the field
       // so that the proper field is highlighted on error.
       if (!$db_id and $accession) {
-      $errors[$field_name][$delta]['und'][] = array(
-      'message' => t("A database and the accession must both be provided."),
+        $errors[$field_name][$delta]['und'][] = array(
+          'message' => t("A database and the accession must both be provided."),
           'error' => 'sbo__database_cross_reference',
         );
       }
-          if ($db_id and !$accession) {
-          $errors[$field_name][$delta]['und'][] = array(
-            'message' => t("A database and the accession must both be provided."),
+      if ($db_id and !$accession) {
+        $errors[$field_name][$delta]['und'][] = array(
+          'message' => t("A database and the accession must both be provided."),
           'error' => 'sbo__database_cross_reference',
         );
       }
-                if (!$db_id and !$accession and ($version or $description)) {
-                $errors[$field_name][$delta]['und'][] = array(
-                  'message' => t("A database and the accession must both be provided."),
+      if (!$db_id and !$accession and ($version or $description)) {
+        $errors[$field_name][$delta]['und'][] = array(
+          'message' => t("A database and the accession must both be provided."),
           'error' => 'sbo__database_cross_reference',
         );
-                }
-                }
+      }
     }
+  }
 }

+ 0 - 1
tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference_widget.inc

@@ -188,7 +188,6 @@ class sbo__database_cross_reference_widget extends ChadoFieldWidget {
    * @see TripalFieldWidget::theme()
    */
   public function theme($element) {
-    $element = $variables['element'];
 
     // These two fields were added to the widget to help identify the fields
     // for layout.

+ 5 - 4
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -312,15 +312,16 @@ function tripal_chado_field_storage_write_merge_fields($fields, $entity_type, $e
     // Get the field name and information about it.
     $field = field_info_field_by_id($field_id);
     $field_name = $field['field_name'];
+    $instance = field_info_instance('TripalEntity', $field['field_name'], $entity->bundle);
     // Some fields (e.g. chado_linker_cvterm_adder) don't add data to
     // Chado so they don't have a table, but they are still attached to the
     // entity. Just skip these.
-    if (!array_key_exists('chado_table', $field['settings'])) {
+    if (!array_key_exists('chado_table', $instance['settings'])) {
       continue;
     }
-    $chado_table = $field['settings']['chado_table'];
-    $chado_column = $field['settings']['chado_column'];
-    $base_table = $field['settings']['base_table'];
+    $chado_table = $instance['settings']['chado_table'];
+    $chado_column = $instance['settings']['chado_column'];
+    $base_table = $instance['settings']['base_table'];
 
     // Iterate through the field's items. Fields with cardinality ($delta) > 1
     // are multi-valued.

+ 53 - 47
tripal_chado/includes/tripal_chado.fields.inc

@@ -1625,54 +1625,60 @@ function tripal_chado_field_instance_settings_form_alter(&$form, $form_state) {
   $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),
-  );
+  $base_table = array_key_exists('base_table', $instance['settings']) ? $instance['settings']['base_table'] : '';
+  $chado_table = array_key_exists('chado_table', $instance['settings']) ? $instance['settings']['chado_table'] : '';
+  $chado_column = array_key_exists('chado_column', $instance['settings']) ? $instance['settings']['chado_column'] : '';
+
+
+  if ($chado_table) {
+    // Construct a table for the vocabulary information.
+    $headers = array();
+    $rows = array();
+    $rows[] = array(
+      array(
+        'data' => 'Base Table',
+        'header' => TRUE,
+        'width' => '20%',
+      ),
+      $base_table
+    );
+    $rows[] = array(
+      array(
+        'data' => 'Record Table',
+        'header' => TRUE,
+        'width' => '20%',
+      ),
+      $chado_table
+    );
+    $rows[] = array(
+      array(
+        'data' => 'ID 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' => '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),
+    );
+  }
 }
 
 /**