function tripal_search_chado_token_across_nodetypes_getter_callback

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

Implements a getter callback for foreign keys collon between content types.

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_across_nodetypes_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 237
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_across_nodetypes_getter_callback($data, $options, $field_name, $type, $info) {

  // First, make sure this is a chado node.
  // Assumption #1: All chado node types are prefixed with chado_
  if (isset($data->nid)) {
    if (preg_match('/^chado_(\w+)/', $data->type, $matches)) {
      if (isset($info['schema field'])) {

        // Assumption #2: The base table is the suffix of the node type.
        $base_table = $matches[1];

        // Substitute in the  base table for "BASE" in the schema field.
        $format = str_replace('BASE', $base_table, $info['schema field']);

        // Replace all tokens for values and return the result.
        $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)
        );
      }
    }
    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;
}