Преглед на файлове

Updated web services to indicate the Tripal formatters that a field can support

Stephen Ficklin преди 7 години
родител
ревизия
8f7bcc99fc

+ 32 - 1
tripal/api/tripal.fields.api.inc

@@ -164,7 +164,38 @@ function tripal_get_field_widgets() {
 }
 
 /**
- * Retrieves a list of TripalFieldFormatters.
+ * Retrieves a list of field formatters compatible with a given field.
+ * @param unknown $field
+ */
+function tripal_get_field_field_formatters($field) {
+  $field_name = $field['field_name'];
+  $field_type = $field['type'];
+  $field_module = $field['module'];
+
+  $downloaders = array();
+
+  // All fields should support the Tab and CSV downloaders.
+  tripal_load_include_downloader_class('TripalTabDownloader');
+  $downloaders['TripalTabDownloader'] = TripalTabDownloader::$label;
+  tripal_load_include_downloader_class('TripalCSVDownloader');
+  $downloaders['TripalCSVDownloader'] = TripalCSVDownloader::$label;
+
+  if (tripal_load_include_field_class($field_type)) {
+    $settings = $field_type::$default_instance_settings;
+    if (array_key_exists('download_formatters', $settings)) {
+      foreach ($settings['download_formatters'] as $class_name) {
+        if (!array_key_exists($class_name, $downloaders)) {
+          tripal_load_include_downloader_class($class_name);
+          $downloaders[$class_name] = $class_name::$label;
+        }
+      }
+    }
+  }
+
+  return $downloaders;
+}
+/**
+ * Retrieves a list of all the TripalFieldFormatters available on this site.
  *
  * The TripalFieldFormatter classes can be added by a site developer and should
  * be placed in the [module]/includes/TripalFields directory.  Tripal will

+ 9 - 4
tripal/includes/TripalEntityCollection.inc

@@ -162,15 +162,17 @@ class TripalEntityCollection {
             $field_type = $field_info['type'];
             $field_module = $field_info['module'];
             $instance = field_info_instance('TripalEntity', $field_name, $bundle_name);
-    
+
             $downloaders = array();
-    
+
+            // TODO: replace this code with the new tripal_get_field_field_formatters()
+            // API function
             // All fields should support the Tab and CSV downloaders.
             tripal_load_include_downloader_class('TripalTabDownloader');
             $this->downloaders['TripalTabDownloader'] = TripalTabDownloader::$label;
             tripal_load_include_downloader_class('TripalCSVDownloader');
             $this->downloaders['TripalCSVDownloader'] = TripalCSVDownloader::$label;
-    
+
             if (tripal_load_include_field_class($field_type)) {
               $settings = $field_type::$default_instance_settings;
               if (array_key_exists('download_formatters', $settings)) {
@@ -196,6 +198,9 @@ class TripalEntityCollection {
 
           $downloaders = array();
 
+          // TODO: replace this code with the new tripal_get_field_field_formatters()
+          // API function
+
           // All fields should support the Tab and CSV downloaders.
           tripal_load_include_downloader_class('TripalTabDownloader');
           $this->downloaders['TripalTabDownloader'] = TripalTabDownloader::$label;
@@ -392,7 +397,7 @@ class TripalEntityCollection {
         $unserialized_result[] = $unserialized_field_list;
       }
     }
- 
+
     return $unserialized_result;
   }
 

+ 4 - 0
tripal_ws/includes/TripalWebService.inc

@@ -478,6 +478,7 @@ class TripalWebService {
     $supported_class->addContextItem('readable', 'hydra:readable');
     $supported_class->addContextItem('writeable', 'hydra:writeable');
     $supported_class->addContextItem('required', 'hydra:required');
+    $supported_class->addContextItem('tripal_formatters', 'tripal:tripal_formatters');
     $class_prop = array(
       'property' => $prop['type'],
       'hydra:title' => $prop['title'],
@@ -498,6 +499,9 @@ class TripalWebService {
         $class_prop['supportedOperation'][] = $this->generateOp($supported_class, $op, $op_details);
       }
     }
+    if (array_key_exists('tripal_formatters', $prop)) {
+      $class_prop['tripal_formatters'] = array_keys($prop['tripal_formatters']);
+    }
     return $class_prop;
   }
   /**

+ 3 - 0
tripal_ws/includes/TripalWebService/TripalEntityService_v0_1.inc

@@ -1160,6 +1160,8 @@ class TripalEntityService_v0_1 extends TripalWebService {
         $proptype = $link;
       }
 
+      $formatters = tripal_get_field_field_formatters($field);
+
       $property = array(
         'type' => $proptype,
         'title' => $instance['label'],
@@ -1167,6 +1169,7 @@ class TripalEntityService_v0_1 extends TripalWebService {
         "required" => $instance['required'] ? TRUE : FALSE,
         "readonly" => FALSE,
         "writeonly" => TRUE,
+        "tripal_formatters" => $formatters,
       );
       $properties[] = $property;
     }