-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Block rendering templates in backend
Injected `RequestStack` and `ScopeMatcher` into several Grid element classes and added checks to bypass rendering when a backend request is detected. This prevents unnecessary output in the backend context, improving efficiency and clarity.
- Loading branch information
Showing
4 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,10 @@ | |
use Contao\ContentModel; | ||
use Contao\CoreBundle\Controller\ContentElement\AbstractContentElementController; | ||
use Contao\CoreBundle\DependencyInjection\Attribute\AsContentElement; | ||
use Contao\CoreBundle\Routing\ScopeMatcher; | ||
use Contao\Template; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
/** | ||
|
@@ -28,11 +30,26 @@ | |
* @author Stefan Schulz-Lauterbach <[email protected]> | ||
*/ | ||
|
||
#[AsContentElement('cp_column_stop', 'cp_grid', template: 'ce_grid_column_stop')] | ||
#[AsContentElement(type: 'cp_column_stop', category: 'cp_grid', template: 'ce_grid_column_stop')] | ||
class GridColumnStop extends AbstractContentElementController | ||
{ | ||
public function __construct( | ||
readonly RequestStack $requestStack, | ||
readonly ScopeMatcher $scopeMatcher, | ||
) { | ||
} | ||
|
||
protected function getResponse(Template $template, ContentModel $model, Request $request): Response | ||
{ | ||
if ($this->scopeMatcher->isBackendRequest()) { | ||
return new Response(''); | ||
} | ||
|
||
$parentKey = ($model->ptable ?: 'tl_article') . '__' . $model->pid; | ||
if (isset($GLOBALS['TL_CP_GRID'][$parentKey]) && !$GLOBALS['TL_CP_GRID'][$parentKey]['active']) { | ||
$GLOBALS['TL_CP_GRID'][$parentKey]['active'] = true; | ||
} | ||
|
||
return $template->getResponse(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters