Browse Source

Added tripal_formatters to web services vocabulary

Stephen Ficklin 7 years ago
parent
commit
5465a1bfd5

+ 34 - 0
tripal/api/tripal.fields.api.inc

@@ -215,6 +215,40 @@ function tripal_get_field_widgets() {
   return $widgets;
 }
 
+/**
+ * Retrieves a list of field formatters compatible with a given field.
+ *
+ * @param $field
+ *   A field array as returned by the field_info_field() function.
+ * @return
+ *   A list of file formatter class names.
+ */
+function tripal_get_field_field_formatters($field) {
+  $field_name = $field['field_name'];
+  $field_type = $field['type'];
+
+  $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 TripalFieldFormatters.
  *

+ 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;
   }
   /**

+ 5 - 3
tripal_ws/includes/TripalWebService/TripalContentService_v0_1.inc

@@ -1168,13 +1168,15 @@ class TripalContentService_v0_1 extends TripalWebService {
         $proptype = $link;
       }
 
+      $formatters = tripal_get_field_field_formatters($field);
       $property = array(
         'type' => $proptype,
         'title' => $instance['label'],
         'description' => $instance['description'],
-        "required" => $instance['required'] ? TRUE : FALSE,
-        "readonly" => FALSE,
-        "writeonly" => TRUE,
+        'required' => $instance['required'] ? TRUE : FALSE,
+        'readonly' => FALSE,
+        'writeonly' => TRUE,
+        'tripal_formatters' => $formatters,
       );
       $properties[] = $property;
     }