You are here

function fft_realpath in Field Formatter Template 7

Same name and namespace in other branches
  1. 8.2 fft.module \fft_realpath()
  2. 8 fft.module \fft_realpath()

Get real path with token.

Parameters

string $file: File path. Use with {module-name} {theme-name} {theme} {fft}.

string $template_file: The template file.

Return value

string Real path.

2 calls to fft_realpath()
fft_field_formatter_settings_form in ./fft.module
Implements hook_field_formatter_settings_form().
fft_field_formatter_view in ./fft.module
Implements hook_field_formatter_view().

File

./fft.module, line 66
Field formatter template.

Code

function fft_realpath($file, $template_file = '') {
  $file = trim($file);
  if (strpos($file, '{') === FALSE) {
    return $file;
  }
  if (strpos($file, '{fft}') !== FALSE) {
    $theme_path = dirname($template_file);
    $file = str_replace('{fft}', $theme_path, $file);
    return $file;
  }
  if (strpos($file, '{theme}') !== FALSE) {
    $theme_default = $GLOBALS['conf']['theme_default'];
    $theme_path = drupal_get_path('theme', $theme_default);
    $file = str_replace('{theme}', $theme_path, $file);
    return $file;
  }
  $matches = array();
  $types = array(
    'module',
    'theme',
    'library',
  );
  foreach ($types as $type) {
    $pattern = '/\\{' . $type . '-(.+)\\}/';
    preg_match($pattern, $file, $matches);
    if ($type == "library") {
      if (count($matches) > 1 && ($path = libraries_get_path($matches[1])) != '') {
        $file = str_replace($matches[0], $path, $file);
        return $file;
      }
    }
    else {
      if (count($matches) > 1 && ($path = drupal_get_path($type, $matches[1])) != '') {
        $file = str_replace($matches[0], $path, $file);
        return $file;
      }
    }
  }
  return $file;
}