PHP-Code:
<?php
$editableTemplateFilesArray = array('php', 'twig', 'css', 'txt', 'csv', 'xml');
$editableTemplateFilesString = ',' . implode(',', $editableTemplateFilesArray);
use Contao\Config;
use Contao\CoreBundle\Util\PackageUtil;
if (
is_callable([PackageUtil::class, 'getContaoVersion'])
&& version_compare(PackageUtil::getContaoVersion(), '4.7', '>=')
) {
if (!empty($GLOBALS['TL_DCA']['tl_templates']['config']['validFileTypes'])) {
#$GLOBALS['TL_DCA']['tl_templates']['config']['validFileTypes'] .= ',php,twig,css,txt,csv,xml';
$GLOBALS['TL_DCA']['tl_templates']['config']['validFileTypes'] .= $editableTemplateFilesString;
}
$GLOBALS['TL_DCA']['tl_templates']['config']['onload_callback'][] = function() {
#Config::set('editableFiles', Config::get('editableFiles') . ',php,twig,css,txt,csv,xml');
Config::set('editableFiles', Config::get('editableFiles') . $editableTemplateFilesString);
};
$originalButtonCallback = $GLOBALS['TL_DCA']['tl_templates']['list']['operations']['source']['button_callback'];
$GLOBALS['TL_DCA']['tl_templates']['list']['operations']['source']['button_callback'] = function($row, $href, $label, $title, $icon, $attributes) use ($originalButtonCallback) {
#if (!in_array(pathinfo($row['id'], PATHINFO_EXTENSION), array('php', 'twig', 'css', 'txt', 'csv', 'xml'))) {
if (!in_array(pathinfo($row['id'], PATHINFO_EXTENSION), $editableTemplateFilesArray)) {
if (is_array($originalButtonCallback)) {
return System::importStatic($originalButtonCallback[0])->{$originalButtonCallback[1]}($row, $href, $label, $title, $icon, $attributes);
}
return $originalButtonCallback($row, $href, $label, $title, $icon, $attributes);
}
return '<a href="' . \Contao\Backend::addToUrl($href . '&id=' . $row['id']) . '" title="' . Contao\StringUtil::specialchars($title) . '"' . $attributes . '>' . Contao\Image::getHtml($icon, $label) . '</a> ';
};
}