Browse Source

Added functionality for better integration with Searching

Stephen Ficklin 7 years ago
parent
commit
18f4907f12

+ 1 - 1
tripal/includes/TripalFieldDownloaders/TripalFieldDownloader.inc

@@ -153,7 +153,7 @@ abstract class TripalFieldDownloader {
   }
 
   /**
-   * Formats the entity and the specified fields for utput.
+   * Formats the entity and the specified fields for output.
    *
    * This function should be implemented by a child class. It should iterate
    * over the fields for the entity and return the appropriate format. It may

+ 1 - 1
tripal/includes/TripalFields/TripalField.inc

@@ -497,7 +497,7 @@ class TripalField {
   }
 
   /**
-   * Provides the list of elements returned by the 'value' of the field. \
+   * Provides the list of elements returned by the 'value' of the field.
    *
    * The elements provided by this function are used to integrate with
    * Drupal Views and Web services.  The return value is an associative array

+ 25 - 17
tripal/includes/TripalFields/TripalFieldFormatter.inc

@@ -99,23 +99,31 @@ class TripalFieldFormatter {
    * This function corresponds to the hook_field_formatter_view()
    * function of the Drupal Field API.
    *
-   *  This function provides the display for a field when it is viewed on
-   *  the web page.  The content returned by the formatter should only include
-   *  what is present in the $items[$delta]['values] array. This way, the
-   *  contents that are displayed on the page, via webservices and downloaded
-   *  into a CSV file will always be identical.  The view need not show all
-   *  of the data in the 'values' array.
-   *
-   *  @param $element
-   *  @param $entity_type
-   *  @param $entity
-   *  @param $langcode
-   *  @param $items
-   *  @param $display
-   *
-   *  @return
-   *    An element array compatible with that returned by the
-   *    hook_field_formatter_view() function.
+   * This function provides the display for a field when it is viewed on
+   * as a full page, teaser, indexing for searching, etc.  The content
+   * returned by the formatter should only include what is present in the
+   * $items[$delta]['values] array. This way, the contents that are displayed
+   * on the page, via web services and downloaded into a CSV file will
+   * always be identical.  The view need not show all of the data in the
+   * 'values' array.
+   *
+   * @param $element
+   *   A renderable array for the $items, as an array of child elements keyed
+   *   by numeric indexes starting from 0.  When implemented as a child
+   *   class, this argument is set for the display.
+   * @param $entity_type
+   *   The type of $entity.
+   * @param $entity
+   *   The entity object.
+   * @param $langcode
+   *   The language associated with $items.
+   * @param $items
+   *   Array of values for this field.
+   * @param $display
+   *   The display settings to use, as found in the 'display' entry of instance
+   *   definitions. The array notably contains the following keys and values;
+   *     - type: The name of the formatter to use.
+   *     - settings: The array of formatter settings.
    */
   public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
 

+ 25 - 2
tripal/includes/tripal.entity.inc

@@ -139,7 +139,7 @@ function tripal_entity_info() {
     'base table' => 'tripal_entity',
 
     // Returns the uri elements of an entity.
-    'uri callback' => 'tripal_vocbulary_term_uri',
+    'uri callback' => 'tripal_entity_uri',
 
     // IF fieldable == FALSE, we can't attach fields.
     'fieldable' => TRUE,
@@ -191,7 +191,20 @@ function tripal_entity_info() {
     )
   );
 
-  //
+  // Search integration
+  if (module_exists('search')) {
+    $entities['TripalEntity']['view modes'] += array(
+      'search_index' => array(
+        'label' => t('Search index'),
+        'custom settings' => FALSE,
+      ),
+      'search_result' => array(
+        'label' => t('Search result highlighting input'),
+        'custom settings' => FALSE,
+      ),
+    );
+  }
+
   // The TripalBundle entity is used manage the bundle types.  The 'bundle of'
   // attribute links this to the TripalEntity and allows the UI provided
   // by the entity module to work for each TripalEntity bundle.
@@ -224,6 +237,16 @@ function tripal_entity_info() {
   return $entities;
 }
 
+/**
+ * Implements the Entity URI callback function.
+ */
+function tripal_entity_uri($entity) {
+  return array(
+    'path' => 'bio-data/' . $entity->id,
+    'options' => array(),
+  );
+}
+
 /**
  * Implements hook_entities_info_alter().
  *

+ 0 - 5
tripal/includes/tripal.fields.inc

@@ -220,11 +220,6 @@ function tripal_field_formatter_view($entity_type, $entity, $field,
     return;
   }
 
-  // TODO: (Shawna) 1) Check the entity type (bundle) settings to see if empty fieleds
-  // should be ignored by default. 2)  Check the field itself to see if it
-  // overides the bundle default.  The idea being do not show fields when
-  // people don't want them shown.
-
   $element = array();
   $formatter_class = $display['type'];
   $is_loaded = tripal_load_include_field_class($formatter_class);

+ 18 - 0
tripal_ws/tripal_ws.module

@@ -435,3 +435,21 @@ function tripal_ws_remote_data_single_field_pull($field, $entity_url){
   }
   return $data;
 }
+
+
+/**
+ * Implements hook_entity_info_alter()
+ *
+ * Add the web services display as a view mode.
+ */
+function tripal_ws_entity_info_alter(&$entity_info) {
+
+  // Set the controller class for nodes to an alternate implementation of the
+  // DrupalEntityController interface.
+  $entity_info['TripalEntity']['view modes']  += array(
+    'tripal_ws' => array(
+      'label' => t('Tripal Web Services'),
+      'custom settings' => FALSE,
+    ),
+  );
+}