function chado_node_get_title_format

2.x tripal_core.chado_nodes.title_and_path.api.inc chado_node_get_title_format($content_type, &$tokens, $base_table = NULL)
3.x tripal_core.chado_nodes.title_and_path.inc chado_node_get_title_format($content_type, &$tokens, $base_table = NULL)

Get the title format for a specific content type

If the title format has not yet been set then the following will be done 1) Check to see if there is a legacy title format set (features & stocks) 2) Check if there is a defined default for this content type 3) Create a format using any name fields and the unique constraint for the base table associated with this content type

Define a default for a specific content type by implementing a function of the name [content type]_chado_node_default_title_format() that returns a string describing the default format.

Parameters

$content_type: The name of the content (node) type you are interested in (ie: chado_feature)

$tokens: An array, passed by reference that is filled to include the tokens for this node type. Each token is an array with the following keys: -table: the name of the chado table -field: the name of the field in the above table -token: the token string (ie: [stock.stock_id]) -description: a very short description of the token (displayed when tokens are listed) -location: the location of the value in a chado node variable with each level separated by an arrow (->) symbol. For example, the location for $node->feature->type_id->name is feature>type_id>name

Return value

A string containing tokens describing the default format for the title of nodes of the specified content type.

2 calls to chado_node_get_title_format()
chado_add_admin_form_set_title in tripal_core/api/tripal_core.chado_nodes.title_and_path.api.inc
Generic "Set Node Title" sub-form for setting the title of any chado node
chado_get_node_title in tripal_core/api/tripal_core.chado_nodes.title_and_path.api.inc
Get the title of a node based on the Title Format set in the admin section of the module. If the format has not yet been set than the the unique constrain and name fields will be used to generate a default format

File

tripal_core/api/tripal_core.chado_nodes.title_and_path.api.inc, line 420
Contains API functions to set titles and paths for all chado nodes

Code

function chado_node_get_title_format($content_type, &$tokens, $base_table = NULL) {
  $format_record_format = $format = '';
  $format_record_tokens = '';

  // Is there a title format set?
  $format_record = chado_node_get_token_format('title', $content_type, array('return_record' => TRUE));
  if (!empty($format_record)) {
    $format_record_format = $format = $format_record->format;
    $format_record_tokens = $tokens = $format_record->tokens;
  }

  // All three options below need the tokens to be generated so do that now
  if (empty($format)) {
    if (empty($base_table)) {
      $base_table = chado_node_get_base_table($content_type);
    }
    $tokens = chado_node_generate_tokens($base_table);
  }

  // 1) Check for legacy format
  if (empty($format)) {
    $format = chado_node_get_legacy_title_default($content_type);
  }

  // 2) Module-defined default format
  if (empty($format)) {
    $hook = $content_type . '_chado_node_default_title_format';
    if (function_exists($hook)) {
      $format = call_user_func($hook);
    }
  }

  // 3) Create unique constraint format
  if (empty($format)) {
    if (empty($base_table)) {
      $base_table = chado_node_get_base_table($content_type);
    }
    $format = chado_node_get_unique_constraint_format($base_table);
  }

  // Add the format to table so we can use it later
  // (optimization: to speed up bulk updates, don't update the record if
  // the format and tokens are unchanged)
  if ($format != $format_record_format || $tokens != $format_record_tokens) {
    chado_node_add_token_format('title', $content_type, $format, $tokens);
  }

  return $format;
}