Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored custom backend view implementations.
This implementation gets rid of the route attribute 'custom_backend_view = true'. It introduces a new twig function to wrap specific content blocks with the be_main template of the Contao backend. This way is more intuitive and a less explicit approach.
- Loading branch information
Showing
5 changed files
with
65 additions
and
53 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,17 +1,9 @@ | ||
{% set _panel = block('panel') %} | ||
{% set _errors = block('errors') %} | ||
{% set _main = block('main') %} | ||
{% set _headline = block('headline') %} | ||
{% set _error = block('error') %} | ||
|
||
{% if _panel is not empty %} | ||
<div class="tl_panel"> | ||
{{ _panel | raw }} | ||
</div> | ||
{% endif %} | ||
|
||
{% if _errors is not empty %} | ||
<p class="tl_gerror">{{ _errors | raw }}</p> | ||
{% endif %} | ||
|
||
<div class="tl_listing_container"> | ||
{% block content %} | ||
{% endblock %} | ||
</div> | ||
{{ contao_base_template_wrapper({ | ||
main: _main, | ||
error: _error, | ||
headline: _headline | ||
}) | raw }} |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Contao\CoreBundle\Twig\Extension; | ||
|
||
use Contao\BackendRoute; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
|
||
class ContaoBaseTemplateExtension extends \Twig_Extension | ||
{ | ||
protected $requestStack; | ||
|
||
public function __construct(RequestStack $requestStack) | ||
{ | ||
$this->requestStack = $requestStack; | ||
} | ||
|
||
public function getFunctions() | ||
{ | ||
return [ | ||
new \Twig_SimpleFunction('contao_base_template_wrapper', [$this, 'wrapWithBaseTemplate']) | ||
]; | ||
} | ||
|
||
public function wrapWithBaseTemplate(array $blocks = []) | ||
{ | ||
$scope = $this->requestStack->getCurrentRequest()->attributes->get('_scope'); | ||
|
||
if ('backend' !== $scope) { | ||
return ''; | ||
} | ||
|
||
$backendRoute = new BackendRoute(); | ||
$backendTemplate = $backendRoute->getBaseTemplate(); | ||
|
||
foreach ($blocks as $key => $content) { | ||
$backendTemplate->{$key} = $content; | ||
} | ||
|
||
$response = $backendRoute->run(); | ||
|
||
return $response->getContent(); | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'base_template_wrapper'; | ||
} | ||
|
||
} |