function chado_get_node_url

2.x tripal_core.chado_nodes.title_and_path.api.inc chado_get_node_url($node)
3.x tripal_core.chado_nodes.title_and_path.inc chado_get_node_url($node)

Get the url of a node based on the url 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

Parameters

$node: The node object

Related topics

1 call to chado_get_node_url()
chado_set_node_url in tripal_core/api/tripal_core.chado_nodes.title_and_path.api.inc
Set the URL for a given node.

File

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

Code

function chado_get_node_url($node) {
  $content_type = $node->type;

  // Get the tokens and format
  $tokens = array(); // this will be set by chado_node_get_url_format
  $url = chado_node_get_url_format($content_type, $tokens);

  // Determine which tokens were used in the format string
  if (preg_match_all('/\[[^]]+\]/', $url, $used_tokens)) {

    // Get the value for each token used
    foreach ($used_tokens[0] as $token) {
      $token_info = $tokens[$token];
      if (!empty($token_info)) {
        $value = chado_get_token_value($token_info, $node);
        if (is_string($value)) {
          $url = str_replace($token, $value, $url);
        }
        else {
          tripal_report_error('chado_node_api', TRIPAL_ERROR, 
          'Unable to replace %token. The value in the node should be a string but is instead: \'%value\'', 
          array('%token' => $token, '%value' => print_r($value, TRUE))
          );
        }
      }
    }
  }
  else {
    return $url;
  }

  return $url;
}