You are here

function linkit_taxonomy_linkit_get_search_styled_link in Linkit 6

Same name and namespace in other branches
  1. 7 plugins/linkit_taxonomy/linkit_taxonomy.module \linkit_taxonomy_linkit_get_search_styled_link()

Implementation of hook_linkit_get_search_styled_link().

File

plugins/linkit_taxonomy/linkit_taxonomy.module, line 62
Extend Linkit with taxonomy links.

Code

function linkit_taxonomy_linkit_get_search_styled_link($string) {

  // Term links created with Linkit will always begin with "internal:"
  if (strpos($string, 'internal:') === FALSE) {
    return;
  }

  // Check to see that the link really is a term link
  $splitted_string = explode('/', str_replace('internal:', '', $string));
  if (!is_numeric($splitted_string[count($splitted_string) - 1])) {
    return;
  }

  // Try to get a term object
  $term = taxonomy_get_term($splitted_string[count($splitted_string) - 1]);

  // taxonomy_get_term is returns an object
  if (!is_object($term)) {
    return;
  }

  // Ok, this looks like a term, get the path
  $path = taxonomy_term_path($term);

  // If $path is the same as the provided $string, we have a match.
  if ($path == str_replace('internal:', '', $string)) {
    return check_plain($term->name) . ' [path:internal:' . taxonomy_term_path($term) . ']';
  }
}