function tripal_search_chado_token_getter_callback

2.x tripal_core.search.inc tripal_search_chado_token_getter_callback($data, $options, $field_name, $type, $info)
3.x tripal_core.search.inc tripal_search_chado_token_getter_callback($data, $options, $field_name, $type, $info)

Implements a getter callback for chado token formats.

A chado token format is a string containing chado tokens.

Chado tokens are expected to follow the format of tokens auto-generated using chado_node_generate_tokens(). For example, [feature.uniquename] indicates you should return the uniquename of a feature node and [feature.organism_id>organism.species] indicates you should return the organism genus of the feature node.

The chado token format must be stored in the 'schema field' when defining the property in hook_entity_property_info() in order for this getter to work.

Parameters

$data: The entity object (in our case the node we need to retrieve feature properties for).

$options:

$field_name: The machine name for the entity property.

$info: The full property definition from entity property info.

Return value

A string representing the "value" of the field.

1 string reference to 'tripal_search_chado_token_getter_callback'
tripal_core_entity_property_info_alter in tripal_core/includes/tripal_core.search.inc
Implements hook_entity_property_info_alter().

File

tripal_core/includes/tripal_core.search.inc, line 181
Adds support for Drupal indexing of Chado. It's important to note that not all of Chado is indexed but instead Only fields indicated in hook_search_include_chado_fields().

Code

function tripal_search_chado_token_getter_callback($data, $options, $field_name, $type, $info) {

  if (isset($data->nid)) {
    if (isset($info['schema field'])) {
      $format = $info['schema field'];

      // Determine our base table so we know if this is even the right node type.
      if (preg_match('/\[(\w+)\.(\w+)/', $format, $matches)) {
        $base_table = $matches[1];
        $field_name = $matches[2];

        // For some weird reason nodes of all types are trying to get a value for fields
        // that we defined as specific to a given node type (ie: bundle). As such we need
        // this check here to ensure this field is actually for this node type.
        if (!isset($data->{$base_table})) {
          return NULL;
        }

        $format = tripal_core_get_token_value_for_property($base_table, $field_name, $format, $data, $info);
        return $format;
      }
      else {
        // Not able to determine table?
        tripal_report_error(
        'tripal_search', 
        TRIPAL_ERROR, 
        'Unable to extract the base table from the format (:format) for :field because it didn\'t match the expected format: [tablename.field...', 
        array(':field' => $field_name, ':format' => $format)
        );
        return NULL;
      }
    }
    else {
      tripal_report_error(
      'tripal_search', 
      TRIPAL_ERROR, 
      'Unable to get value for :field because the schema field was not set.', 
      array(':field' => $field_name)
      );
      return NULL;
    }
  }
}