Skip to content

Commit

Permalink
backend styling fix
Browse files Browse the repository at this point in the history
  • Loading branch information
j25j5 committed May 3, 2024
1 parent 842ccdc commit f7988d1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
22 changes: 18 additions & 4 deletions src/EventListener/ParseBackendTemplateListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
namespace Magmell\Contao\Inserttags\EventListener;

use Contao\CoreBundle\ServiceAnnotation\Hook;
use Contao\InsertTags;
use Contao\Input;
use Contao\System;
use Contao\CoreBundle\InsertTag\InsertTagParser;
use Contao\Template;
use Contao\StringUtil;
use Contao\BackendTemplate;

/**
* @Hook("parseBackendTemplate")
*/
class ParseBackendTemplateListener
class ParseBackendTemplateListener extends BackendTemplate
{
public function __invoke(string $buffer, string $template): string
{
Expand All @@ -26,9 +27,22 @@ public function __invoke(string $buffer, string $template): string
AND strpos($buffer, '<div class="cte_type unpublished">HTML</div>') === false
){
$buffer = System::getContainer()->get('contao.insert_tag.parser')->replace($buffer);

if (!empty($GLOBALS['TL_CSS']) && \is_array($GLOBALS['TL_CSS']))
{
$strStyleSheets = '';

foreach (array_unique($GLOBALS['TL_CSS']) as $stylesheet)
{
$options = StringUtil::resolveFlaggedUrl($stylesheet);
$strStyleSheets .= Template::generateStyleTag($this->addStaticUrlTo($stylesheet), $options->media, $options->mtime);
}

$this->stylesheets .= $strStyleSheets;
$buffer = str_replace('<head>', '<head>' . $this->stylesheets, $buffer);
}
}
}

return $buffer;
}
}
3 changes: 0 additions & 3 deletions src/EventListener/ParseFrontendTemplateListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
use Contao\CoreBundle\ServiceAnnotation\Hook;
use Contao\System;
use Contao\FrontendTemplate;
use Contao\InsertTags;
use Contao\ArticleModel;
use Contao\PageModel;
use Contao\Input;
use Contao\CoreBundle\InsertTag\InsertTagParser;

/**
* @Hook("parseFrontendTemplate")
Expand All @@ -23,7 +21,6 @@ public function __invoke(string $buffer, string $templateName, FrontendTemplate
if (!isset($GLOBALS['objPage']) || !$GLOBALS['objPage']) {
$a = ArticleModel::findById(Input::get("id"));
$b = PageModel::findByPk($a->pid);

if($b->trail) {
$GLOBALS['objPage'] = PageModel::findByPk($b->trail[0]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
use Magmell\Contao\Inserttags\EventListener\ParseTemplateListener;

$GLOBALS['TL_HOOKS']['parseBackendTemplate'][] = [ParseBackendTemplateListener::class, '__invoke'];
$GLOBALS['TL_HOOKS']['parseTemplate'][] = [ParseTemplateListener::class, '__invoke'];
//$GLOBALS['TL_HOOKS']['parseTemplate'][] = [ParseTemplateListener::class, '__invoke'];

0 comments on commit f7988d1

Please sign in to comment.