Skip to content

Commit

Permalink
update to render inserttags also in the backend - with some exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
markusmilkereit committed Jan 11, 2022
1 parent a7fe789 commit 62d4aa5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/EventListener/ParseBackendTemplateListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Magmell\Contao\Inserttags\EventListener;

use Contao\CoreBundle\ServiceAnnotation\Hook;
use Contao\InsertTags;
use Contao\Input;

/**
* @Hook("parseBackendTemplate")
*/
class ParseBackendTemplateListener
{
public function __invoke(string $buffer, string $template): string
{
if ('be_main' === $template) {
// modify only if we're not in any action mode
// modify only if there is no HTML content element involved
if(!Input::get('act')
AND strpos($buffer, '<div class="cte_type published">HTML</div>') === false
AND strpos($buffer, '<div class="cte_type unpublished">HTML</div>') === false
){
$objIt = new InsertTags();
$buffer = $objIt->replace($buffer, true);
}
}

return $buffer;
}
}
5 changes: 5 additions & 0 deletions src/Resources/contao/config/config.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<?php

$GLOBALS['TL_HOOKS']['replaceInsertTags'][] = ['Magmell\Contao\Inserttags\Hooks\InserttagsHook', 'doReplace'];

// automatic invoke did not work, force-link the hook here
use Magmell\Contao\Inserttags\EventListener\ParseBackendTemplateListener;

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

0 comments on commit 62d4aa5

Please sign in to comment.