Browse Source

added the link between field listing in manage display and the table of content block and also updated the properties formatter to show more than one item

Shawna 7 years ago
parent
commit
962cb6780f

+ 9 - 7
tripal/includes/TripalBundleController.inc

@@ -3,6 +3,7 @@
  * The Controller for Tripal data type entities
  */
 class TripalBundleController extends EntityAPIControllerExportable {
+
   public function __construct($entityType) {
     parent::__construct($entityType);
 
@@ -19,20 +20,20 @@ class TripalBundleController extends EntityAPIControllerExportable {
    * @return
    *   A type object with all default fields initialized.
    */
-  public function create(array $values = array()) {
+  public function create(array $values = []) {
     // Add values that are specific to our entity
-    $values += array(
+    $values += [
       'id' => '',
       'is_new' => TRUE,
       'data' => '',
-    );
+    ];
     $bundle = parent::create($values);
 
     // Allow modules to make additions to the entity when it's created.
     $modules = module_implements('bundle_create');
     foreach ($modules as $module) {
       $function = $module . '_bundle_create';
-      $function($bundle, array());
+      $function($bundle, []);
     }
 
     return $bundle;
@@ -73,8 +74,9 @@ class TripalBundleController extends EntityAPIControllerExportable {
 
           // If the field has no more instances then purge it too.
           if (count($field['bundles']) == 1 and
-              count($field['bundles']['TripalEntity']) == 1 and
-              in_array($bundle->name, $field['bundles']['TripalEntity'])) {
+            count($field['bundles']['TripalEntity']) == 1 and
+            in_array($bundle->name, $field['bundles']['TripalEntity'])
+          ) {
             field_purge_field($field);
           }
         }
@@ -98,7 +100,7 @@ class TripalBundleController extends EntityAPIControllerExportable {
       // overrides.
       foreach ($bundles as $id => $bundle) {
         if (entity_has_status($this->entityType, $bundle, ENTITY_IN_CODE)) {
-          entity_defaults_rebuild(array($this->entityType));
+          entity_defaults_rebuild([$this->entityType]);
           break;
         }
       }

+ 14 - 7
tripal_chado/api/modules/tripal_chado.cv.api.inc

@@ -400,7 +400,7 @@ function tripal_update_cvtermpath_root_loop($rootid, $cvid){
   $ttype->condition($db_or);
   $result = $ttype->execute()->fetchObject();
 
-  tripal_update_cvtermpath_loop($rootid, $rootid, $cvid, $result->cvterm_id, 0, 0, array());
+  $result = tripal_update_cvtermpath_loop($rootid, $rootid, $cvid, $result->cvterm_id, 0, 0, array());
 
   $cterm = db_query(
     'SELECT *
@@ -411,9 +411,15 @@ function tripal_update_cvtermpath_root_loop($rootid, $cvid){
   );
 
   while($cterm_result = $cterm->fetchAssoc()) {
-    tripal_update_cvtermpath_root_loop($cterm_result['subject_id'], $cvid);
-  };
+    if ($result === 'LOOP'){
+      watchdog('debug', '<pre>$result: ' . print_r($result, TRUE) . '</pre>');
 
+      continue;
+    }
+    else {
+      tripal_update_cvtermpath_root_loop($cterm_result['subject_id'], $cvid);
+    }
+  }
 }
 
 /**
@@ -455,7 +461,9 @@ function tripal_update_cvtermpath_loop($origin, $child_id, $cv_id, $type_id, $de
           'pathdistance' => $depth,
         ));
       $rows = $query->execute();
-      if($rows) {
+      //watchdog('debug', '<pre>$rows: ' . print_r($rows, TRUE) . '</pre>');
+
+     // if($rows) {
         // Build the ID.
         $children_id = $origin . '|' . $child_id . '|' . $cv_id . '|' . $type_id;
         // Now check if the most recent entry already exists in the array.
@@ -468,7 +476,7 @@ function tripal_update_cvtermpath_loop($origin, $child_id, $cv_id, $type_id, $de
               watchdog('debug', '<pre>tripal_update_cvtermpath_loop  $result_of_loop_checker: ' . print_r($result_of_loop_checker, TRUE) . '</pre>');
               if ($result_of_loop_checker) {
                 watchdog('debug', 'Loop found exit the loop function');
-                break;
+                return 'LOOP';
               }
             }
           }
@@ -486,11 +494,10 @@ function tripal_update_cvtermpath_loop($origin, $child_id, $cv_id, $type_id, $de
         $cterm = $query->fetchAll();
 
         foreach ($cterm as $item) {
-          watchdog('message', '<pre>$loop_status: ' . print_r($loop_status, TRUE) . '</pre>');
           $increment_of_depth++;
           tripal_update_cvtermpath_loop($origin, $item->subject_id, $cv_id, $item->type_id, $depth + 1, $increment_of_depth, $array_of_children);
         }
-      }
+     // }
     }
   }
   catch(Exception $e){

+ 35 - 8
tripal_chado/includes/TripalFields/chado_linker__prop/chado_linker__prop_formatter.inc

@@ -24,14 +24,41 @@ class chado_linker__prop_formatter extends ChadoFieldFormatter {
     $field_name = $this->field['field_name'];
     $chado_table = $this->instance['settings']['chado_table'];
 
-    $content = '';
-    if ($items[0]['value']) {
-      $content = $items[0]['value'];
+    $content = array();
+    // If $items is not empty and it has more than one value all values need to
+    // be added to an array for display.
+    if ($items) {
+      if (count($items) > 1) {
+        foreach ($items as $index => $item) {
+          $content[$index] = $item['value'];
+        }
+      }
+      else {
+        $content = $items[0]['value'];
+      }
     }
-    $element[0] = array(
-      // We create a render array to produce the desired markup,
-      '#type' => 'markup',
-      '#markup' => $content,
-    );
+    // If more than one value has been found display all values in an unordered
+    // list.
+    if (count($content) > 1) {
+      $bullets = '<ul>';
+      $bullets .= '<li>';
+      $bullets .= implode("</li><li>", $content);
+      $bullets .= '</li>';
+      $bullets .= '</ul>';
+      $element[0] = array(
+        // We create a render array to produce the desired markup,
+        '#type' => 'markup',
+        '#markup' => $bullets,
+      );
+    }
+    // If it's a single value field display without bullets.
+    else {
+      $element[0] = array(
+        // We create a render array to produce the desired markup,
+        '#type' => 'markup',
+        '#markup' => $content,
+      );
+    }
+
   }
 }

+ 17 - 1
tripal_ds/includes/views/tripal_ds.views.inc

@@ -73,7 +73,23 @@ function tripal_ds_views_data() {
       'handler' => 'views_handler_argument_string',
     ),
   );
-
+  $data['tripal_ds']['weight'] = array(
+    'title' => t('Weight'),
+    'help' => t('The weight as determined by the order in the Manage Display tab of the content type.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE, // This is use by the table display plugin.
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
+    ),
+  );
   return $data;
 }
 

+ 68 - 63
tripal_ds/includes/views/tripal_ds.views_default.inc

@@ -4,58 +4,62 @@
 * Implements hook_views_default_views().
 */
 function tripal_ds_views_default_views() {
+  
+  $view = new view();
+  $view->name = 'tripal_content_type_toc';
+  $view->description = '';
+  $view->tag = 'default';
+  $view->base_table = 'tripal_ds';
+  $view->human_name = 'Tripal Content Type Table of Contents';
+  $view->core = 7;
+  $view->api_version = '3.0';
+  $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
 
-$view = new view();
-$view->name = 'tripal_content_type_toc';
-$view->description = '';
-$view->tag = 'default';
-$view->base_table = 'tripal_ds';
-$view->human_name = 'Tripal Content Type Table of Contents';
-$view->core = 7;
-$view->api_version = '3.0';
-$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially. */
-
-/* Display: Master */
-$handler = $view->new_display('default', 'Master', 'default');
-$handler->display->display_options['title'] = 'Table of Contents';
-$handler->display->display_options['use_more_always'] = FALSE;
-$handler->display->display_options['access']['type'] = 'none';
-$handler->display->display_options['cache']['type'] = 'none';
-$handler->display->display_options['query']['type'] = 'views_query';
-$handler->display->display_options['exposed_form']['type'] = 'basic';
-$handler->display->display_options['pager']['type'] = 'full';
-$handler->display->display_options['pager']['options']['items_per_page'] = '10';
-$handler->display->display_options['style_plugin'] = 'default';
-$handler->display->display_options['row_plugin'] = 'fields';
-/* Field: Tripal Panes: Field Name */
-$handler->display->display_options['fields']['tripal_ds_field_name']['id'] = 'tripal_ds_field_name';
-$handler->display->display_options['fields']['tripal_ds_field_name']['table'] = 'tripal_ds';
-$handler->display->display_options['fields']['tripal_ds_field_name']['field'] = 'tripal_ds_field_name';
-$handler->display->display_options['fields']['tripal_ds_field_name']['label'] = '';
-$handler->display->display_options['fields']['tripal_ds_field_name']['exclude'] = TRUE;
-$handler->display->display_options['fields']['tripal_ds_field_name']['element_label_colon'] = FALSE;
-/* Field: Tripal Panes: Bundle ID */
-$handler->display->display_options['fields']['bundle']['id'] = 'bundle';
-$handler->display->display_options['fields']['bundle']['table'] = 'tripal_ds';
-$handler->display->display_options['fields']['bundle']['field'] = 'bundle';
-$handler->display->display_options['fields']['bundle']['label'] = '';
-$handler->display->display_options['fields']['bundle']['exclude'] = TRUE;
-$handler->display->display_options['fields']['bundle']['element_label_colon'] = FALSE;
-/* Field: Tripal Panes: Field Label */
-$handler->display->display_options['fields']['tripal_ds_field_label']['id'] = 'tripal_ds_field_label';
-$handler->display->display_options['fields']['tripal_ds_field_label']['table'] = 'tripal_ds';
-$handler->display->display_options['fields']['tripal_ds_field_label']['field'] = 'tripal_ds_field_label';
-$handler->display->display_options['fields']['tripal_ds_field_label']['label'] = '';
-$handler->display->display_options['fields']['tripal_ds_field_label']['alter']['alter_text'] = TRUE;
-$handler->display->display_options['fields']['tripal_ds_field_label']['alter']['text'] = '<a href="#" class="tripal_pane-toc-list-item-link" id ="[tripal_ds_field_name]">[tripal_ds_field_label] </a>';
-$handler->display->display_options['fields']['tripal_ds_field_label']['element_label_colon'] = FALSE;
-/* Contextual filter: Tripal Panes: Bundle ID */
-$handler->display->display_options['arguments']['bundle']['id'] = 'bundle';
-$handler->display->display_options['arguments']['bundle']['table'] = 'tripal_ds';
-$handler->display->display_options['arguments']['bundle']['field'] = 'bundle';
-$handler->display->display_options['arguments']['bundle']['default_action'] = 'default';
-$handler->display->display_options['arguments']['bundle']['default_argument_type'] = 'php';
-$handler->display->display_options['arguments']['bundle']['default_argument_options']['code'] = '$url = current_path();
+  /* Display: Master */
+  $handler = $view->new_display('default', 'Master', 'default');
+  $handler->display->display_options['title'] = 'Table of Contents';
+  $handler->display->display_options['use_more_always'] = FALSE;
+  $handler->display->display_options['access']['type'] = 'none';
+  $handler->display->display_options['cache']['type'] = 'none';
+  $handler->display->display_options['query']['type'] = 'views_query';
+  $handler->display->display_options['exposed_form']['type'] = 'basic';
+  $handler->display->display_options['pager']['type'] = 'full';
+  $handler->display->display_options['pager']['options']['items_per_page'] = '10';
+  $handler->display->display_options['style_plugin'] = 'default';
+  $handler->display->display_options['row_plugin'] = 'fields';
+  /* Field: Tripal Panes: Field Name */
+  $handler->display->display_options['fields']['tripal_ds_field_name']['id'] = 'tripal_ds_field_name';
+  $handler->display->display_options['fields']['tripal_ds_field_name']['table'] = 'tripal_ds';
+  $handler->display->display_options['fields']['tripal_ds_field_name']['field'] = 'tripal_ds_field_name';
+  $handler->display->display_options['fields']['tripal_ds_field_name']['label'] = '';
+  $handler->display->display_options['fields']['tripal_ds_field_name']['exclude'] = TRUE;
+  $handler->display->display_options['fields']['tripal_ds_field_name']['element_label_colon'] = FALSE;
+  /* Field: Tripal Panes: Bundle ID */
+  $handler->display->display_options['fields']['bundle']['id'] = 'bundle';
+  $handler->display->display_options['fields']['bundle']['table'] = 'tripal_ds';
+  $handler->display->display_options['fields']['bundle']['field'] = 'bundle';
+  $handler->display->display_options['fields']['bundle']['label'] = '';
+  $handler->display->display_options['fields']['bundle']['exclude'] = TRUE;
+  $handler->display->display_options['fields']['bundle']['element_label_colon'] = FALSE;
+  /* Field: Tripal Panes: Field Label */
+  $handler->display->display_options['fields']['tripal_ds_field_label']['id'] = 'tripal_ds_field_label';
+  $handler->display->display_options['fields']['tripal_ds_field_label']['table'] = 'tripal_ds';
+  $handler->display->display_options['fields']['tripal_ds_field_label']['field'] = 'tripal_ds_field_label';
+  $handler->display->display_options['fields']['tripal_ds_field_label']['label'] = '';
+  $handler->display->display_options['fields']['tripal_ds_field_label']['alter']['alter_text'] = TRUE;
+  $handler->display->display_options['fields']['tripal_ds_field_label']['alter']['text'] = '<a href="#" class="tripal_pane-toc-list-item-link" id ="[tripal_ds_field_name]">[tripal_ds_field_label] </a>';
+  $handler->display->display_options['fields']['tripal_ds_field_label']['element_label_colon'] = FALSE;
+  /* Sort criterion: Tripal Panes: Weight */
+  $handler->display->display_options['sorts']['weight']['id'] = 'weight';
+  $handler->display->display_options['sorts']['weight']['table'] = 'tripal_ds';
+  $handler->display->display_options['sorts']['weight']['field'] = 'weight';
+  /* Contextual filter: Tripal Panes: Bundle ID */
+  $handler->display->display_options['arguments']['bundle']['id'] = 'bundle';
+  $handler->display->display_options['arguments']['bundle']['table'] = 'tripal_ds';
+  $handler->display->display_options['arguments']['bundle']['field'] = 'bundle';
+  $handler->display->display_options['arguments']['bundle']['default_action'] = 'default';
+  $handler->display->display_options['arguments']['bundle']['default_argument_type'] = 'php';
+  $handler->display->display_options['arguments']['bundle']['default_argument_options']['code'] = '$url = current_path();
 $url_exploded = explode("/", $url);
 $tripal_entity_id = (int)$url_exploded[1];
 
@@ -66,20 +70,21 @@ $tripal_entity_id = (int)$url_exploded[1];
       ->fetchField();
 
 return $result;';
-$handler->display->display_options['arguments']['bundle']['summary']['number_of_records'] = '0';
-$handler->display->display_options['arguments']['bundle']['summary']['format'] = 'default_summary';
-$handler->display->display_options['arguments']['bundle']['summary_options']['items_per_page'] = '25';
-$handler->display->display_options['arguments']['bundle']['limit'] = '0';
+  $handler->display->display_options['arguments']['bundle']['summary']['number_of_records'] = '0';
+  $handler->display->display_options['arguments']['bundle']['summary']['format'] = 'default_summary';
+  $handler->display->display_options['arguments']['bundle']['summary_options']['items_per_page'] = '25';
+  $handler->display->display_options['arguments']['bundle']['limit'] = '0';
+
+  /* Display: Page */
+  $handler = $view->new_display('page', 'Page', 'page');
+  $handler->display->display_options['path'] = 'tripal_ct_toc';
 
-/* Display: Page */
-$handler = $view->new_display('page', 'Page', 'page');
-$handler->display->display_options['path'] = 'tripal_ct_toc';
+  /* Display: Block */
+  $handler = $view->new_display('block', 'Block', 'block');
+  $handler->display->display_options['defaults']['pager'] = FALSE;
+  $handler->display->display_options['pager']['type'] = 'none';
+  $handler->display->display_options['pager']['options']['offset'] = '0';
 
-/* Display: Block */
-$handler = $view->new_display('block', 'Block', 'block');
-$handler->display->display_options['defaults']['pager'] = FALSE;
-$handler->display->display_options['pager']['type'] = 'none';
-$handler->display->display_options['pager']['options']['offset'] = '0';
 
 $views[$view->name] = $view;
 

+ 70 - 4
tripal_ds/tripal_ds.module

@@ -85,7 +85,7 @@ function tripal_ds_bundle_delete($bundle){
   tripal_ds_table_column_delete($bundle);
 }
 
-/*
+/**
  * Implements hook_ds_field_settings_alter()
  */
 function tripal_ds_ds_field_settings_alter(&$field_settings, $form, $form_state){
@@ -123,6 +123,8 @@ function tripal_ds_ds_field_settings_alter(&$field_settings, $form, $form_state)
       }
     }
   }
+  // Update the menu items weight.
+  tripal_ds_toc_order($bundle_id, $form_state['values']['fields']);
 }
 /**
  * Implements hook_field_group_pre_render().
@@ -151,11 +153,17 @@ function tripal_ds_field_group_pre_render(& $element, $group, & $form) {
   }
 }
  */
+
 /**
+ *
  * Trigger the update to the tripal_ds table when a tripal pane is deleted.
+ *
+ * @param $bundle_name
+ * @param $field_label
+ * @param $field_name
+ * @param $entity_type
  */
 function tripal_ds_bundle_menu_item($bundle_name, $field_label, $field_name, $entity_type){
-
   //Check the record does not already exist
   $tripal_ds_rows = db_select('tripal_ds', 'ds')
     ->fields('ds', array('tripal_ds_field_name', 'tripal_ds_field_label'))
@@ -163,7 +171,6 @@ function tripal_ds_bundle_menu_item($bundle_name, $field_label, $field_name, $en
     ->condition('tripal_ds_field_label', $field_label, '=')
     ->condition('tripal_ds_field_name', $field_name, '=')
     ->execute()->fetchAll();
-
   if(!empty($tripal_ds_rows)){
     foreach ($tripal_ds_rows as $tripal_ds_row){
       if(($field_label == $tripal_ds_row->tripal_ds_field_label) && ($field_name == $tripal_ds_row->tripal_ds_field_name) && ($bundle_name == $tripal_ds_rows->bundle)) {
@@ -184,7 +191,7 @@ function tripal_ds_bundle_menu_item($bundle_name, $field_label, $field_name, $en
   }
 }
 
-/*
+/**
  * Implements hook_ds_layout_info() to define layouts from code in a module for
  * display suite
  */
@@ -206,6 +213,18 @@ function tripal_ds_ds_layout_info() {
   return $layouts;
 }
 
+/**
+ * Implements hook_form()
+ *
+ * Adds a confirmation message to applying default layout option in 'Manage
+ * Display'
+ *
+ * @param $form
+ * @param $form_state
+ * @param $bundle_name
+ *
+ * @return mixed
+ */
 function tripal_ds_update_layout_form($form, &$form_state, $bundle_name) {
   $form = array();
   $form['bundle_name'] = array(
@@ -226,6 +245,7 @@ function tripal_ds_update_layout_form($form, &$form_state, $bundle_name) {
 }
 
 /**
+ * Implements hook_form_submit()
  *
  * @param $form_state
  * @param $form
@@ -321,6 +341,10 @@ function tripal_ds_field_create_field($field, $bundle_name) {
 }
  */
 /**
+ * Implements hook_form()
+ *
+ * Creates the button that creates an empty tripal pane.
+ *
  * @param $form
  * @param $form_state
  * @param $bundle_name
@@ -354,6 +378,7 @@ function tripal_ds_pane_addition_button_form($form, &$form_state, $bundle_name)
 }
 
 /**
+ * Implements hook_form_submit()
  *
  * @param $form_state
  * @param $form
@@ -460,6 +485,9 @@ function tripal_ds_field_display_alter(&$display, $context){
 
 */
 /**
+ * Identifies field_group parents to find tripal_panes and return that
+ * information to the function that calls it.
+ *
  * @param $field_name
  * @param $entity_type
  * @param $bundle
@@ -513,3 +541,41 @@ function tripal_ds_find_field_group_parent($field_name, $entity_type, $bundle, $
   return $field_groups_to_hide;
 
 }
+
+/**
+ * @param $bundle
+ * @param array $fields
+ */
+function tripal_ds_toc_order($bundle, $fields = array()){
+  // On bundle save grab the #ds_layout->settings ->regions->right array
+  // then use the index of each 'group' && 'tripalpane, and 'gp_*' to update
+  // the weight of the item in the tripal_ds table.
+  // Don't forget to update the view.
+
+  // Find all menu items associated with the bundle id.
+  $menu_items = db_select('tripal_ds', 'ds')
+    ->fields('ds')
+    ->condition('bundle', $bundle, '=')
+    ->execute()->fetchAll();
+
+  // Now find all menu items in the $fields array
+  foreach ($menu_items as $menu_items => $menu_item) {
+    $toc_field_name = $menu_item->tripal_ds_field_name;
+    // Compare the field name from the table with the fields in the array.
+    if (array_key_exists($toc_field_name, $fields)) {
+      $weight = $fields[$toc_field_name]['weight'];
+      //If a weight is returned update the tripal_ds table.
+      if(!empty($weight)){
+        watchdog('debug', '<pre>$weight: '. print_r($weight, TRUE) .'</pre>');
+        db_update('tripal_ds')
+          ->fields(array(
+            'weight' => $weight,
+          ))
+          ->condition('bundle', $bundle, '=')
+          ->condition('tripal_ds_field_name', $toc_field_name, '=')
+          ->execute();
+      }
+    }
+  }
+}
+