Explorar el Código

Added a new instanceSettingsForm() to the TripalField class

Stephen Ficklin hace 8 años
padre
commit
7f2ef5e873

+ 3 - 1
tripal/api/tripal.jobs.api.inc

@@ -336,7 +336,9 @@ function tripal_launch_job($do_parallel = 0, $job_id = NULL) {
 
     // Include the necessary files
     foreach (unserialize($job->includes) as $path) {
-      require_once $path;
+      if ($path) {
+        require_once $path;
+      }
     }
     // set the start time for this job
     $record = new stdClass();

+ 47 - 2
tripal/includes/TripalField.inc

@@ -603,7 +603,52 @@ class TripalField {
    * @param $has_data
    *   TRUE if the field already has data, FALSE if not.
    */
-  public static function settingsForm($field, $instance, $has_data) {
+  public static function instanceSettingsForm($field, $instance) {
+    $settings = $instance['settings'];
+    $element = array();
+
+    //     $element['semantic_web'] = array(
+    //       '#type' => 'textfield',
+    //       '#title' => 'Semantic Web',
+    //       '#description' => t('Each field must be associated with a term
+    //           from a controlled vocabulary.  This allows computer programs to understand
+    //           the data provided on this site.  Please be cautions changing these
+    //           values.  Defaults are set by Tripal and sites that use the same
+    //           terms can exchange information.'),
+    //       '#collapsed' => TRUE,
+    //       '#collapsible' => TRUE,
+    //       '#tree' => TRUE,
+    //     );
+    $module = $field['module'];
+    $element['#field'] = $field;
+    $element['#instance'] = $instance;
+    $element['#element_validate'][] = $module . '_instance_settings_form_validate';
+
+    return $element;
+  }
+  /**
+   *
+   * @param unknown $form
+   * @param unknown $form_state
+   */
+  public static function instanceSettingsFormValidate($form, &$form_state) {
+
+  }
+
+  /**
+   * Provides a form for the 'Field Settings' of the field management page.
+   *
+   * 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.
+   */
+  public static function fieldSettingsForm($field, $instance, $has_data) {
     $settings = $field['settings'];
     $element = array();
 
@@ -631,7 +676,7 @@ class TripalField {
    * @param unknown $form
    * @param unknown $form_state
    */
-  public static function settingsFormValidate($form, &$form_state) {
+  public static function fieldSettingsFormValidate($form, &$form_state) {
 
   }
 

+ 2 - 2
tripal_chado/includes/fields/chado_base__organism_id.inc

@@ -293,11 +293,11 @@ class chado_base__organism_id extends TripalField {
   /**
    * @see TripalField::settings_form()
    */
-  public static function settingsForm($field, $instance, $has_data) {
+  public static function fieldSettingsForm($field, $instance, $has_data) {
+    $element = parent::fieldSettingsForm($field, $instance, $has_data);
 
     $settings = $field['settings'];
 
-    $element = array();
     $element['instructions'] = array(
       '#type' => 'item',
       '#markup' => 'You may rewrite the way this field is presented to the end-user.

+ 8 - 8
tripal_chado/includes/fields/chado_linker__relationship.inc

@@ -11,7 +11,6 @@ class chado_linker__relationship extends TripalField {
       'default_widget' => 'chado_linker__relationship_widget',
       'default_formatter' => 'chado_linker__relationship_formatter',
       'settings' => array(
-        'relationship_types' => ''
       ),
       'storage' => array(
         'type' => 'field_chado_storage',
@@ -106,6 +105,7 @@ class chado_linker__relationship extends TripalField {
       'required' => FALSE,
       'settings' => array(
         'auto_attach' => FALSE,
+        'relationship_types' => '',
       ),
       'widget' => array(
         'type' => 'chado_linker__relationship_widget',
@@ -364,7 +364,7 @@ class chado_linker__relationship extends TripalField {
       $options = array();
       $widget['type_name'] = array(
         '#type' => 'textfield',
-        '#title' => t('Type'),
+        '#title' => t('Relationship Type'),
         '#size' => 15,
         '#autocomplete_path' => "admin/tripal/storage/chado/auto_name/cvterm/$cv_id"
       );
@@ -860,15 +860,15 @@ class chado_linker__relationship extends TripalField {
    * @param unknown $instance
    * @param unknown $has_data
    */
-  public static function settingsForm($field, $instance, $has_data) {
-    $element = parent::settingsForm($field, $instance, $has_data);
+  public static function fieldSettingsForm($field, $instance, $has_data) {
+    $element = parent::fieldSettingsForm($field, $instance, $has_data);
     $element['instructions'] = array(
       '#type' => 'item',
       '#markup' => 'You may provide a list of terms that will be available in a select box
-        as the relationship types. This select box will replace the vocabulary select box if the 
+        as the relationship types. This select box will replace the vocabulary select box if the
         following value is set.'
     );
-    
+
     $element['relationship_types'] = array(
       '#type' => 'textarea',
       '#title' => 'Relationship Types',
@@ -884,7 +884,7 @@ class chado_linker__relationship extends TripalField {
    * @param unknown $instance
    * @param unknown $has_data
    */
-  public static function settingsFormValidate($form, &$form_state) {
+  public static function fieldSettingsFormValidate($form, &$form_state) {
     //dpm($form);dpm($form_state);
   }
 }
@@ -932,7 +932,7 @@ function chado_linker__relationship_widget_form_ajax_callback(&$form, $form_stat
   if (isset($form[$field][$lang][$delta])) {
     return $form[$field][$lang][$delta];
   }
-  // Alternatively, return the default value widget for the widget setting form 
+  // Alternatively, return the default value widget for the widget setting form
   else {
     return $form['instance']['default_value_widget'][$field];
   }

+ 31 - 3
tripal_chado/includes/tripal_chado.fields.inc

@@ -526,7 +526,19 @@ function tripal_chado_field_settings_form($field, $instance, $has_data) {
   $field_type = $field['type'];
   module_load_include('inc', 'tripal_chado', 'includes/fields/' . $field_type);
   if (class_exists($field_type)) {
-    $form = $field_type::settingsForm($field, $instance, $has_data);
+    $form = $field_type::fieldSettingsForm($field, $instance, $has_data);
+  }
+  return $form;
+}
+/**
+ * Implements hook_instance_settings_form()
+ */
+function tripal_chado_instance_settings_form($field, $instance) {
+  $form = array();
+  $field_type = $field['type'];
+  module_load_include('inc', 'tripal_chado', 'includes/fields/' . $field_type);
+  if (class_exists($field_type)) {
+    $form = $field_type::instanceSettingsForm($field, $instance);
   }
   return $form;
 }
@@ -535,8 +547,8 @@ function tripal_chado_field_settings_form($field, $instance, $has_data) {
  * 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 settingsFormValidate() member
- * function.
+ * to alow the TripalField objects to have a fieldSettingsFormValidate()
+ * member function.
  */
 function tripal_chado_field_settings_form_validate($form, &$form_state) {
   $field = $form['#field'];
@@ -547,6 +559,22 @@ function tripal_chado_field_settings_form_validate($form, &$form_state) {
     $form = $field_type::settingsFormValidate($field, $instance, $form, $form_state);
   }
 }
+/**
+ * Implements hook_instance_settings_form_validate().
+ *
+ * This is not an actual Drpual hook, but rather a Tripal created hook
+ * to alow the TripalField objects to have a instanceSettingsFormValidate()
+ * member function.
+ */
+function tripal_chado_field_settings_form_validate($form, &$form_state) {
+  $field = $form['#field'];
+  $instance = $form['#instance'];
+  $field_type = $field['type'];
+  module_load_include('inc', 'tripal_chado', 'includes/fields/' . $field_type);
+  if (class_exists($field_type)) {
+    $form = $field_type::instanceSettingsFormValidate($field, $instance, $form, $form_state);
+  }
+}
 
 /**
  * Implements hook_field_formatter_settings_summary().