forked from glpi-project/glpi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
AbstractController
and common twig templates rendering
- Loading branch information
1 parent
f402aae
commit eb703aa
Showing
11 changed files
with
182 additions
and
55 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
/** | ||
* --------------------------------------------------------------------- | ||
* | ||
* GLPI - Gestionnaire Libre de Parc Informatique | ||
* | ||
* http://glpi-project.org | ||
* | ||
* @copyright 2015-2024 Teclib' and contributors. | ||
* @licence https://www.gnu.org/licenses/gpl-3.0.html | ||
* | ||
* --------------------------------------------------------------------- | ||
* | ||
* LICENSE | ||
* | ||
* This file is part of GLPI. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* --------------------------------------------------------------------- | ||
*/ | ||
|
||
namespace Glpi\Controller; | ||
|
||
use Glpi\Application\View\TemplateRenderer; | ||
use Glpi\DependencyInjection\PublicService; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
abstract class AbstractController implements PublicService | ||
{ | ||
/** | ||
* Helper method to get a response containing the content of a rendered | ||
* twig template. | ||
* | ||
* @param string $view Path to a twig template, which will be looked for in | ||
* the "templates" folder. | ||
* For example, "my_template.html.twig" will be resolved to `templates/my_template.html.twig`. | ||
* For plugins, you must use the "@my_plugin_name" prefix. | ||
* For example, "@formcreator/my_template.html.twig will resolve to | ||
* `(plugins|marketplace)/formcreator/templates/my_template.html.twig`. | ||
* @param array $parameters The expected parameters of the twig template. | ||
* @param Response $response Optional parameter which serves as the "base" | ||
* response into which the renderer twig content will be inserted. | ||
* You should only use it if you need to set some specific headers into the | ||
* response or to set an http return code different than 200. | ||
* | ||
* @return Response | ||
*/ | ||
final protected function render( | ||
string $view, | ||
array $parameters = [], | ||
Response $response = new Response(), | ||
): Response { | ||
$twig = TemplateRenderer::getInstance(); | ||
|
||
// We must use output buffering here as Html::header() and Html::footer() | ||
// output content directly. | ||
// TODO: fix header() and footer() methods and remove output buffering | ||
ob_start(); | ||
$twig->display($view, $parameters); | ||
$content = ob_get_clean(); | ||
|
||
$response->setContent($content); | ||
return $response; | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{# | ||
# --------------------------------------------------------------------- | ||
# | ||
# GLPI - Gestionnaire Libre de Parc Informatique | ||
# | ||
# http://glpi-project.org | ||
# | ||
# @copyright 2015-2024 Teclib' and contributors. | ||
# @licence https://www.gnu.org/licenses/gpl-3.0.html | ||
# | ||
# --------------------------------------------------------------------- | ||
# | ||
# LICENSE | ||
# | ||
# This file is part of GLPI. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
# | ||
# --------------------------------------------------------------------- | ||
#} | ||
|
||
{% do call(['Html', 'header'], { | ||
title: title, | ||
sector: menu[0] ?? 'none', | ||
item : menu[1] ?? 'none', | ||
option: menu[2] ?? '', | ||
}) %} | ||
|
||
{% block content %} | ||
{% endblock content %} | ||
|
||
{% do call(['Html', 'footer']) %} |
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,50 @@ | ||
{# | ||
# --------------------------------------------------------------------- | ||
# | ||
# GLPI - Gestionnaire Libre de Parc Informatique | ||
# | ||
# http://glpi-project.org | ||
# | ||
# @copyright 2015-2024 Teclib' and contributors. | ||
# @licence https://www.gnu.org/licenses/gpl-3.0.html | ||
# | ||
# --------------------------------------------------------------------- | ||
# | ||
# LICENSE | ||
# | ||
# This file is part of GLPI. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
# | ||
# --------------------------------------------------------------------- | ||
#} | ||
|
||
{% extends "layout/page_skeleton.html.twig" %} | ||
|
||
{% block content %} | ||
<div class="page-header mt-0"> | ||
<div class="container container-{{ container_size ?? "xl" }}"> | ||
<h1 class="page title mb-0"> | ||
{% block content_title %} | ||
{% endblock content_title %} | ||
</h1> | ||
</div> | ||
</div> | ||
<div class="page-body mt-3"> | ||
<div class="container container-{{ container_size ?? "xl" }}"> | ||
{% block content_body %} | ||
{% endblock content_body %} | ||
</div> | ||
</div> | ||
{% endblock content %} |