private function TripalContentService_v0_1::addDocBundleFieldProperties

3.x TripalContentService_v0_1.inc private TripalContentService_v0_1::addDocBundleFieldProperties($bundle, $bundle_term)

Every content type (bundle) has fields that need to be set as properties.

1 call to TripalContentService_v0_1::addDocBundleFieldProperties()
TripalContentService_v0_1::addDocBundleClasses in tripal_ws/includes/TripalWebService/TripalContentService_v0_1.inc
Adds classes for every content type to the documentation for this service.

File

tripal_ws/includes/TripalWebService/TripalContentService_v0_1.inc, line 1160

Class

TripalContentService_v0_1

Code

private function addDocBundleFieldProperties($bundle, $bundle_term) {
  $properties = array();

  $content_type_accession = $bundle_term->vocab->vocabulary . ':' . $bundle_term->accession;

  $instances = field_info_instances('TripalEntity', $bundle->name);
  foreach ($instances as $instance) {
    // Skip deleted fields.
    if ($instance['deleted']) {
      continue;
    }
    // Skip hidden fields.
    if ($instance['display']['default']['type'] == 'hidden') {
      continue;
    }

    $accession = $instance['settings']['term_vocabulary'] . ":" . $instance['settings']['term_accession'];

    $field_name = $instance['field_name'];
    $field = field_info_field($field_name);
    $field_type = $field['type'];
    // Skip fields of remote data.
    if ($field_type == 'remote__data') {
      continue;
    }

    // Check if this field is an auto attach. If not, then we have alink and
    // we need to indicate that the link has operations.
    $proptype = $instance['settings']['term_vocabulary'] . ':' . $instance['settings']['term_accession'];
    if ($instance['settings']['auto_attach'] == FALSE) {

      // Create a WebServiceResource for the hydra:Link type.
      $id = $content_type_accession . '/' . $accession;
      $link = new TripalWebServiceResource($this->base_path);
      $link->setID($accession);
      $link->setType('hydra:Link');
      $link->addContextItem('domain', array(
        "@id" => "rdfs:domain",
        "@type" => "@id"
      ));
      $link->addContextItem('range', array(
        "@id" => "rdfs:range",
        "@type" => "@id"
      ));
      $link->addContextItem('readable', 'hydra:readable');
      $link->addContextItem('writeable', 'hydra:writeable');
      $link->addContextItem('required', 'hydra:required');
      $link->addContextItem('description', 'rdfs:comment');
      $link->addContextItem('label', 'rdfs:label');
      $link->addProperty('hydra:title', $instance['label']);
      $link->addProperty('hydra:description', $instance['description']);
      //       $link->addProperty('domain', $service_path . '#EntryPoint');
      //       $link->addProperty('range', $service_class::$label);

      $ops = array();
      $op = new TripalWebServiceResource($this->base_path);

      $op->setID('_:' . $field_name . '_retrieve');
      $op->setType('hydra:Operation');
      $op->addContextItem('method', 'hydra:method');
      $op->addContextItem('label', 'rdfs:label');
      $op->addContextItem('description', 'rdfs:comment');
      $op->addContextItem('expects', array(
        "@id" => "hydra:expects",
        "@type" => "@id"
      ));
      $op->addContextItem('returns', array(
        "@id" => "hydra:returns",
        "@type" => "@id"
      ));
      $op->addContextItem('statusCodes', 'hydra:statusCodes');
      $op->addProperty('method', "GET");
      $op->addProperty('label', 'Retrieves the ' . $instance['label'] . ' resource.');
      $op->addProperty('description', $instance['description']);
      $op->addProperty('expects', NULL);
      $op->addProperty('returns', $accession);
      $op->addProperty('statusCodes', array());
      $ops[] = $op;
      $link->addContextItem('supportedOperation', 'hydra:supportedOperation');
      $link->addProperty('supportedOperation', $ops);
      $proptype = $link;
    }

    $formatters = tripal_get_field_field_formatters($field, $instance);

    $property = array(
      'type' => $proptype,
      'title' => $instance['label'],
      'description' => $instance['description'],
      "required" => $instance['required'] ? TRUE : FALSE,
      "readonly" => FALSE,
      "writeonly" => TRUE,
      "tripal_formatters" => $formatters,
    );
    $properties[] = $property;
  }
  return $properties;
}