function fft_get_templates in Field Formatter Template 8
Same name and namespace in other branches
- 8.2 fft.module \fft_get_templates()
- 7 fft.module \fft_get_templates()
Get available templates.
Parameters
string $start_with: Prefix template.
Return value
array List of Field formatter template.
3 calls to fft_get_templates()
- FFTFormatter::settingsForm in src/
Plugin/ Field/ FieldFormatter/ FFTFormatter.php - Returns a form to configure settings for the formatter.
- FFTFormatter::settingsSummary in src/
Plugin/ Field/ FieldFormatter/ FFTFormatter.php - Returns a short summary for the current formatter settings.
- ViewFormatterTemplate::buildOptionsForm in modules/
vff/ src/ Plugin/ views/ style/ ViewFormatterTemplate.php - Provide a form to edit options for this plugin.
File
- ./
fft.module, line 82 - Field formatter template.
Code
function fft_get_templates($start_with = 'fft') {
static $page_templates = [];
if (empty($page_templates[$start_with])) {
$page_templates[$start_with] = [];
$extension = fft_theme_extension();
$files = FileSystemInterface::scanDirectory(fft_storage_dir(), '/^.*' . $extension . '$/');
foreach ($files as $full_path => $file) {
$file_content = file_get_contents($full_path);
$header = [];
if (!preg_match('/\\{\\#Template Name:(.*?)\\#\\}/s', $file_content, $header)) {
continue;
}
$template_file = str_replace(fft_storage_dir() . "/", '', $file->uri);
$start_with_len = strlen($start_with);
if (substr($template_file, 0, $start_with_len) === $start_with) {
$page_templates[$start_with]['templates'][$template_file] = fft_cleanup_header_comment($header[1]);
$settings = [];
$page_templates[$start_with]['settings'][$template_file] = '';
if (preg_match('/\\{\\#Settings:(.*?)\\#\\}/s', $file_content, $settings)) {
$page_templates[$start_with]['settings'][$template_file] = trim($settings[1]);
}
}
}
}
return $page_templates[$start_with];
}