Pārlūkot izejas kodu

Added theme for the field instance setting form

Stephen Ficklin 4 gadi atpakaļ
vecāks
revīzija
e65cac10dc

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

@@ -668,10 +668,44 @@ class TripalField {
 
     $element['#field'] = $this->field;
     $element['#instance'] = $this->instance;
+    $element['#theme'] = ['tripal_field_settings_default'];
     $element['#element_validate'][] = 'tripal_field_instance_settings_form_validate';
     return $element;
   }
 
+  /**
+   * The theme function for the instance settings form.
+   *
+   * @param $element
+   * A form element array containing basic properties for the widget:
+   *  - #entity_type: The name of the entity the field is attached to.
+   *  - #bundle: The name of the field bundle the field is contained in.
+   *  - #field_name: The name of the field.
+   *  - #language: The language the field is being edited in.
+   *  - #field_parents: The 'parents' space for the field in the form. Most
+   *    widgets can simply overlook this property. This identifies the location
+   *    where the field values are placed within $form_state['values'], and is
+   *    used to access processing information for the field through the
+   *    field_form_get_state() and field_form_set_state() functions.
+   *  - #columns: A list of field storage columns of the field.
+   *  - #title: The sanitized element label for the field instance, ready for
+   *    output.
+   *  - #description: The sanitized element description for the field instance,
+   *    ready for output.
+   *  - #required: A Boolean indicating whether the element value is required;
+   *    for required multiple value fields, only the first widget's values are
+   *    required.
+   *  - #delta: The order of this item in the array of subelements; see
+   *    $delta above
+   *
+   * @return
+   *   A drupal renderable array or HTML or an empty string if no
+   *   theming is to be applied.
+   */
+  public function settingsTheme($element) {
+
+  }
+
   /**
    * Provides validation of the instance settings form.
    *

+ 21 - 2
tripal/includes/tripal.fields.inc

@@ -445,7 +445,8 @@ function tripal_field_instance_settings_form($field, $instance) {
   $field_class = $field['type'];
   if (tripal_load_include_field_class($field_class)) {
     $field = new $field_class($field, $instance);
-    return $field->instanceSettingsForm();
+    $form =  $field->instanceSettingsForm();
+    return [$form];
   }
 }
 
@@ -827,7 +828,6 @@ function tripal_field_formatter_settings_form($field, $instance,
     $formatter = new $formatter_class($field, $instance);
     $elements = $formatter->settingsForm($view_mode, $form, $form_state);
   }
-
   return $elements;
 }
 
@@ -928,6 +928,7 @@ function tripal_form_field_ui_display_overview_form_alter(&$form, &$form_state,
  * @param $variables
  */
 function theme_tripal_field_default($variables) {
+
   $element = $variables['element'];
   $field = $element['#field'];
   $instance = $element['#instance'];
@@ -940,3 +941,21 @@ function theme_tripal_field_default($variables) {
     return $widget->theme($element);
   }
 }
+
+/**
+ * Theme function for all TripalFieldWidget objects.
+ *
+ * @param $variables
+ */
+function theme_tripal_field_settings_default($variables) {
+
+  $element = $variables['element'];
+  $field = $element['#field'];
+  $instance = $element['#instance'];
+  $field_class = $element['#field']['field_name'];
+  tripal_load_include_field_class($field_class);
+  if (class_exists($field_class)) {
+    $field = new $field_class($field, $instance);
+    return $field->settingsTheme($element);
+  }
+}

+ 6 - 1
tripal/tripal.module

@@ -817,6 +817,11 @@ function tripal_theme($existing, $type, $theme, $path) {
       'render element' => 'element',
       'file' => 'includes/tripal.fields.inc',
     ),
+    // Theming for all field settings forms.
+    'tripal_field_settings_default' => array(
+      'render element' => 'element',
+      'file' => 'includes/tripal.fields.inc',
+    ),
     // Themed forms
     'tripal_views_handler_area_collections_fields_fset' => array(
       'render element' => 'form',
@@ -1657,7 +1662,7 @@ function tripal_job_describe_args($callback, $args) {
 
 /**
  * Returns the current version of Tripal, according to the tripal.info file
- * 
+ *
  * @return string
  *   The version string of Tripal. Ex. 7.x-3.1
  */

+ 2 - 0
tripal_chado/includes/TripalFields/ChadoField.inc

@@ -323,6 +323,8 @@ class ChadoField extends TripalField {
    * @see TripalField::instanceSettingsForm()
    */
   public function instanceSettingsForm() {
+    $element = parent::instanceSettingsForm();
+
     // Make sure we don't lose our Chado table mappings when the settings
     // are updated.  Setting them as values in the form ensures they don't
     // get accidentally overwritten.

+ 1 - 1
tripal_chado/includes/TripalFields/data__accession/data__accession_widget.inc

@@ -178,7 +178,7 @@ class data__accession_widget extends ChadoFieldWidget {
     $fieldset = [
       '#title' => $element['#title'],
       '#value' => '',
-      '#description' => $element['#description'],
+      '#description' =>  $element['#description'],
       '#children' => $layout,
     ];
 

+ 115 - 1
tripal_chado/includes/TripalFields/so__transcript/so__transcript.inc

@@ -35,6 +35,10 @@ class so__transcript extends ChadoField {
     // type. This will create form elements when editing the field instance
     // to allow the site admin to change the term settings above.
     'term_fixed' => FALSE,
+    // Contains the list of fields on the transcript child that the
+    // user wants to have displayed for the transcript.  The
+    // `so__transcript_expanded_formatter will display these.
+    'transcript_fields' => []
   ];
 
   // The default widget for this field.
@@ -183,4 +187,114 @@ class so__transcript extends ChadoField {
     }
   }
 
-}
+  /**
+   * @see TripalField::globalSettingsForm()
+   */
+  public function instanceSettingsForm() {
+    $element = parent::instanceSettingsForm();
+
+    $settings = $this->instance['settings'];
+
+
+    $element['transcript_fields'] = [
+      '#type' => 'value',
+      '#default_value' => $settings['transcript_fields'],
+    ];
+
+    //Get the content type for the mRNA term (SO:0000234) and it's feilds.
+    $bundle = tripal_load_bundle_entity(['accession' => 'SO:0000234']);
+    $fields = field_info_instances('TripalEntity', $bundle->name);
+
+    foreach ($fields as $field_name => $details) {
+      $weight = $details['display']['default']['weight'];
+      $element['field-'. $weight] = [
+        '#type' => 'value',
+        '#value' => $field_name,
+        '#weight' => $weight,
+      ];
+      $element['field-'. $weight . '-check'] = [
+        '#type' => 'checkbox',
+        '#weight' => $weight,
+      ];
+      $element['field-'. $weight . '-label'] = [
+        '#type' => 'markup',
+        '#markup' => t($details['label']),
+        '#weight' => $weight,
+      ];
+      $element['field-'. $weight . '-description'] = [
+        '#type' => 'markup',
+        '#markup' => t($details['description']),
+        '#weight' => $weight,
+      ];
+      $element['field-'. $weight . '-weight'] = [
+        '#type' => 'textfield',
+        '#default_value' => $weight,
+        '#weight' => $weight,
+        '#size' => 3,
+        '#attributes' => [
+          'class' => ['tripal-field-settings-table-weights'],
+        ],
+      ];
+    }
+    return $element;
+  }
+
+  /**
+   * @see TripalField::settingsTheme()
+   */
+  public function settingsTheme($element) {
+
+    $headers = ['', 'Field', 'Description', ''];
+    $rows = [];
+    foreach (element_children($element) as $child) {
+      $matches = [];
+      if (preg_match('/^field-(\d+)-(.+)$/', $child, $matches)) {
+        $weight = $matches[1];
+        switch ($matches[2]) {
+          case 'check':
+            $rows[$weight]['data'][0] = drupal_render($element[$child]);
+            break;
+          case 'label':
+            $rows[$weight]['data'][1] = drupal_render($element[$child]);
+            break;
+          case 'description':
+            $rows[$weight]['data'][2] = drupal_render($element[$child]);
+            break;
+          case 'weight':
+            $rows[$weight]['data'][3] = drupal_render($element[$child]);
+            break;
+        }
+        ksort($rows[$weight]['data']);
+        $rows[$weight]['class'] = ['draggable'];
+      }
+    }
+    ksort($rows);
+
+    $table = [
+      'header' => $headers,
+      'rows' => $rows,
+      'attributes' => ["id" => 'tripal-field-settings-table'],
+      'sticky' => TRUE,
+      'caption' => t('Content Panes Available in the TOC'),
+      'colgroups' => [],
+      'empty' => t('There are no content panes for this page'),
+    ];
+    drupal_add_tabledrag('tripal-field-settings-table', 'order', 'sibling', 'tripal-field-settings-table-weights');
+
+    $fset = [];
+    $fset['fields'] = [
+      '#type' => 'fieldset',
+      '#title' => 'Field Selection',
+      '#description' => t('Select the fields that you want displayed on the gene page for each transcript that belongs to the gene.  If no fields are selected then a default display is provided.'),
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+    ];
+    $fset['fields']['table'] = [
+      '#type' => 'markup',
+      '#markup' => theme_table($table),
+    ];
+
+    return drupal_render($fset['fields']);
+  }
+
+}