Browse Source

Issue #102: Provides defaults so that Tripal Views doesn't issue excessive errors when the custom table array isn't as expected.

Lacey Sanderson 7 years ago
parent
commit
5a36a56508

+ 9 - 1
tripal_chado_views/api/tripal_chado_views.api.inc

@@ -697,7 +697,15 @@ function tripal_add_views_integration($defn_array, $setup_id = FALSE) {
     );
 
     // Insert Field Definitions
-    foreach ($defn_array['fields'] as $field) {
+    foreach ($defn_array['fields'] as $key => $field) {
+      // Set some defaults.
+      $field['name'] = (isset($field['name'])) ? $field['name'] : $key;
+      $field['title'] = (isset($field['title'])) ? $field['title'] : $field['name'];
+      $field['type'] = (isset($field['type'])) ? $field['type'] : 'text';
+      $field['description'] = (isset($field['description'])) ? $field['description'] : $field['name'];
+      $field['handlers'] = (isset($field['handlers'])) ? $field['handlers'] : array('field' => array('name' => 'views_handler_field'));
+
+      // Build the field record.
       $field_record = array(
         'setup_id' => $view_record['setup_id'],
         'column_name' => $field['name'],

+ 2 - 2
tripal_chado_views/tripal_chado_views.views.inc

@@ -218,7 +218,7 @@ function tripal_chado_views_views_data() {
       foreach ($fields as $column => $attrs) {
         $base_fields[$column] = array(
           'column_name' => $column,
-          'type' => $attrs['type'],
+          'type' => (isset($attrs['type'])) ? $attrs['type'] : 'text',
         );
       }
 
@@ -663,4 +663,4 @@ function tripal_chado_views_views_data_alter(&$data) {
  */
 function tripal_chado_views_views_pre_view(&$view, &$display_id, &$args) {
   $_GET = array_merge($_GET, $_POST);
-}
+}