function fft_realpath in Field Formatter Template 8
Same name and namespace in other branches
- 8.2 fft.module \fft_realpath()
- 7 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: Template file.
Return value
string Real path.
1 call to fft_realpath()
- fft_field_formatter_render in ./
fft.module - Render field formatter.
File
- ./
fft.module, line 25 - 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 = [];
$types = [
'module',
'theme',
];
foreach ($types as $type) {
$pattern = '/\\{' . $type . '-(.+)\\}/';
preg_match($pattern, $file, $matches);
if (count($matches) > 1 && ($path = drupal_get_path($type, $matches[1])) != '') {
$file = str_replace($matches[0], $path, $file);
return $file;
}
}
return $file;
}