Browse Source

Fixed bug in dbxref widget. Removed kvpropert_adder field from entity overview forms

Stephen Ficklin 9 years ago
parent
commit
ec614cc0c4

+ 5 - 5
tripal_db/tripal_db.module

@@ -160,16 +160,16 @@ function tripal_db_theme($existing, $type, $theme, $path) {
  * for searching for accession that begin with the provided string
  *
  * @param $db_id
- * The DB ID in which to search for the term
+ *   The DB ID in which to search for the term
  * @param $string
- * The string to search for
+ *   The string to search for
  *
  * @return
- * A json array of terms that begin with the provided string
+ *   A json array of terms that begin with the provided string
  *
  * @ingroup tripal_db_api
  */
-function tripal_db_dbxref_accession_autocomplete ($db_id, $string = '') {
+function tripal_db_dbxref_accession_autocomplete($db_id, $string = '') {
   if (!$db_id) {
     return drupal_json_output(array());
   }
@@ -185,6 +185,6 @@ function tripal_db_dbxref_accession_autocomplete ($db_id, $string = '') {
   foreach ($results as $ref) {
     $items[$ref->accession] = $ref->accession;
   }
-  
+
   drupal_json_output($items);
 }

+ 0 - 1
tripal_entities/includes/tripal_entities.chado_entity.inc

@@ -66,7 +66,6 @@ function tripal_entities_entity_delete($entity, $type) {
 }
 
 /**
- *
  * @param unknown $display
  * @param unknown $context
  */

+ 1 - 2
tripal_entities/includes/tripal_entities.entity_form.inc

@@ -52,7 +52,7 @@ function tripal_entities_entity_form($form, &$form_state, $dbxref_id = '', $enti
   $bundle_id = 'dbxref_' . $dbxref_id;
 
   // Add a vertical tabs element
-  $form['ev_tabs'] = array(
+  $form['entity_form_vtabs'] = array(
     '#type' => 'vertical_tabs',
     '#weight' => 999,
   );
@@ -91,7 +91,6 @@ function tripal_entities_entity_form($form, &$form_state, $dbxref_id = '', $enti
 
   $form['#prefix'] = "<div id='$bundle_id-entity-form'>";
   $form['#suffix'] = "</div>";
-
   return $form;
 
 }

+ 4 - 0
tripal_entities/tripal_entities.module

@@ -88,6 +88,10 @@ function tripal_entities_menu_local_tasks_alter(&$data, $router_item, $root_path
   }
 }
 
+/**
+ *
+ * @param unknown $account
+ */
 function tripal_entities_shortcut_default_set($account) {
   $sets = shortcut_sets();
   $found = FALSE;

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

@@ -50,6 +50,9 @@ function tripal_fields_dbxref_id_widget(&$widget, $form, $form_state, $field, $i
   $accession = '';
   $version = '';
   $description = '';
+
+  // If the field already has a value then it will come through the $items
+  // array.  This happens when editing an existing record.
   if (array_key_exists($delta, $items)) {
     $dbxref_id = $items[$delta]['value'];
     $db_id = $items[$delta]['dbxref__db_id'];
@@ -58,6 +61,15 @@ function tripal_fields_dbxref_id_widget(&$widget, $form, $form_state, $field, $i
     $description = $items[$delta]['dbxref__description'];
   }
 
+  // Check $form_state['values'] to see if an AJAX call set the values.
+  if (array_key_exists('values', $form_state)) {
+    $dbxref_id = tripal_fields_get_field_form_values($field_name, $form_state, 0, $field_name);
+    $db_id = tripal_fields_get_field_form_values($field_name, $form_state, 0, "dbxref__db_id");
+    $accession = tripal_fields_get_field_form_values($field_name, $form_state, 0, "dbxref__accession");
+    $version = tripal_fields_get_field_form_values($field_name, $form_state, 0, "dbxref__version");
+    $description = tripal_fields_get_field_form_values($field_name, $form_state, 0, "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
   // be closed when it returns from the ajax call.

+ 9 - 31
tripal_fields/includes/fields/kvproperty_adder.inc

@@ -19,22 +19,17 @@ function tripal_fields_kvproperty_adder_formatter(&$element, $entity_type, $enti
 }
 /**
  *
- * @param unknown $field_name
- * @param unknown $widget
- * @param unknown $form
- * @param unknown $form_state
- * @param unknown $field
- * @param unknown $instance
- * @param unknown $langcode
- * @param unknown $itemsG
- * @param unknown $delta
- * @param unknown $element
  */
-function tripal_fields_kvproperty_adder_widget(&$widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element) {
+function tripal_fields_kvproperty_adder_widget(&$widget, $form, $form_state,
+    $field, $instance, $langcode, $items, $delta, $element) {
   // This field has no value field.  Just a fieldset for adding new properties.
-  $widget['#theme'] = 'tripal_fields_kvproperty_addr_widget';
   $widget['#element_validate'] = array('tripal_fields_kvproperty_adder_widget_validate');
 
+  $widget['#type'] = 'fieldset';
+  $widget['#title'] = $element['#title'];
+  $widget['#description'] = $element['#description'];
+  $widget['#group'] = 'entity_form_vtabs';
+
   $widget['kvproperty_instructions'] = array(
     '#type' => 'item',
     '#markup' => t('You may add additional properties to this form by
@@ -47,7 +42,8 @@ function tripal_fields_kvproperty_adder_widget(&$widget, $form, $form_state, $fi
   $widget['value'] = array(
     '#title' => t('Property Type'),
     '#type' => 'textfield',
-    '#description' => t("Please enter the type of property that you want to add.  As you type, suggestions will be provided."),
+    '#description' => t("Please enter the type of property that you want to
+        add.  As you type, suggestions will be provided."),
     '#autocomplete_path' => "admin/tripal/chado/tripal_cv/cvterm/auto_name/",
   );
   $widget['kvproperty_adder_link'] = array(
@@ -69,24 +65,6 @@ function tripal_fields_kvproperty_adder_widget(&$widget, $form, $form_state, $fi
     '#limit_validation_errors' => array(array($field['field_name'])),
   );
 }
-/**
- * Theme function for the kvproperty_addr_widget.
- *
- * @param $variables
- */
-function theme_tripal_fields_kvproperty_addr_widget($variables) {
-  $element = $variables['element'];
-  $fieldset = array(
-    '#title' => $element['#title'],
-    '#value' => '',
-    '#description' => $element['#description'],
-    '#children' => drupal_render_children($element),
-    '#group' => 'ev_tabs',
-    '#attributes' => array(),
-  );
-
-  return theme('fieldset', array('element' => $fieldset));
-}
 /**
  * Callback function for validating the tripal_fields_kvproperty_adder_widget.
  */

+ 34 - 2
tripal_fields/tripal_fields.module

@@ -278,11 +278,43 @@ function tripal_fields_field_widget_form(&$form, &$form_state, $field,
       tripal_fields_kvproperty_widget($widget, $form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
       break;
   }
-
   return $widget;
 }
 
-
+/**
+ * Implements hook_form_FORM_ID_alter().
+ *
+ * The field_ui_display_overview_form is used for formatting the display
+ * or layout of fields attached to an entity and shown on the entity view page.
+ */
+function tripal_fields_form_field_ui_display_overview_form_alter(&$form, &$form_state, $form_id) {
+  // Remove the kvproperty_addr field as it isn't ever displayed. It's just used
+  // on the add/edit form of an entity for adding new property fields.
+  $fields_names = element_children($form['fields']);
+  foreach ($fields_names as $field_name) {
+    $field_info = field_info_field($field_name);
+    if ($field_info['type'] == 'kvproperty_adder') {
+      unset($form['fields'][$field_name]);
+    }
+  }
+}
+/**
+ * Implements hook_form_FORM_ID_alter().
+ *
+ * The field_ui_field_overview_form is used for ordering and configuring the
+ * fields attached to an entity.
+ */
+function tripal_fields_form_field_ui_field_overview_form_alter(&$form, &$form_state, $form_id) {
+  // Remove the kvproperty_addr field as it isn't ever displayed. It's just used
+  // on the add/edit form of an entity for adding new property fields.
+  $fields_names = element_children($form['fields']);
+  foreach ($fields_names as $field_name) {
+    $field_info = field_info_field($field_name);
+    if ($field_info['type'] == 'kvproperty_adder') {
+      unset($form['fields'][$field_name]);
+    }
+  }
+}
 /**
  * Implements hook_field_is_empty().
  */

+ 1 - 0
tripal_fields_layout/theme/templates/tripal_fields_layout_generic.tpl.php

@@ -23,6 +23,7 @@ foreach ($panels AS $panel_id => $panel) {
           'data' => $field['#title'],
           'header' => TRUE,
           'width' => '20%',
+          'nowrap' => 'nowrap'
         ),
         $field[0]['#markup']
       );

+ 0 - 1
tripal_fields_layout/tripal_fields_layout.module

@@ -507,7 +507,6 @@ function tripal_fields_layout_theme($existing, $type, $theme, $path) {
  * Implements hook_entity_view.
  */
 function tripal_fields_layout_entity_view($entity, $type, $view_mode, $langcode) {
-  //dpm(array($entity, $type, $view_mode, $langcode));
   switch ($type) {
     case 'BioData':
       // Use the generic template to render the fields