mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-18 14:58:43 +02:00
N°3567 - Migrate backoffice pages to new UIBlock system : App. upgrade (display twig errors)
This commit is contained in:
@@ -32,7 +32,6 @@ use MetaModel;
|
||||
use ReflectionClass;
|
||||
use SetupPage;
|
||||
use SetupUtils;
|
||||
use Twig_Error;
|
||||
use utils;
|
||||
use ZipArchive;
|
||||
|
||||
@@ -158,8 +157,6 @@ abstract class Controller
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
require_once(APPROOT."/setup/setuppage.class.inc.php");
|
||||
|
||||
http_response_code(500);
|
||||
$oP = new ErrorPage(Dict::S('UI:PageTitle:FatalError'));
|
||||
$oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
|
||||
@@ -529,20 +526,7 @@ abstract class Controller
|
||||
{
|
||||
throw new Exception('Not initialized. Call Controller::InitFromModule() or Controller::SetViewPath() before any display');
|
||||
}
|
||||
try
|
||||
{
|
||||
return $this->m_oTwig->render($sName.'.'.$sTemplateFileExtension.'.twig', $aParams);
|
||||
}
|
||||
catch (Twig_Error $e)
|
||||
{
|
||||
// Ignore errors
|
||||
if (!utils::StartsWith($e->getMessage(), 'Unable to find template'))
|
||||
{
|
||||
IssueLog::Error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
return TwigHelper::RenderTemplate($this->m_oTwig, $aParams, $sName, $sTemplateFileExtension, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
namespace Combodo\iTop\Application\TwigBase\Twig;
|
||||
|
||||
use Combodo\iTop\Application\TwigBase\UI\UIBlockExtension;
|
||||
use Exception;
|
||||
use IssueLog;
|
||||
use Twig\Environment;
|
||||
use Twig_Environment;
|
||||
@@ -110,21 +111,30 @@ class TwigHelper
|
||||
* @param array $aParams
|
||||
* @param string $sName
|
||||
* @param string $sTemplateFileExtension
|
||||
* @param bool $bLogMissingFile
|
||||
*
|
||||
* @return string
|
||||
* @throws \Twig\Error\LoaderError
|
||||
* @throws \Twig\Error\RuntimeError
|
||||
* @throws \Twig\Error\SyntaxError
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function RenderTemplate(Environment $oTwig, $aParams, $sName, $sTemplateFileExtension = self::DEFAULT_FILE_TYPE)
|
||||
public static function RenderTemplate(Environment $oTwig, array $aParams, string $sName, string $sTemplateFileExtension = self::DEFAULT_FILE_TYPE, bool $bLogMissingFile = true): string
|
||||
{
|
||||
try {
|
||||
return $oTwig->render($sName.'.'.$sTemplateFileExtension.'.twig', $aParams);
|
||||
} catch (Twig_Error $e) {
|
||||
$sPath = '';
|
||||
if ($e->getSourceContext()) {
|
||||
$sPath = utils::LocalPath($e->getSourceContext()->getPath()).' ('.$e->getLine().') - ';
|
||||
}
|
||||
$sMessage = $sPath.$e->getMessage();
|
||||
if (!utils::StartsWith($e->getMessage(), 'Unable to find template')) {
|
||||
IssueLog::Error($e->getMessage());
|
||||
} else {
|
||||
IssueLog::Debug($e->getMessage());
|
||||
IssueLog::Error($sMessage);
|
||||
// Todo 3.0 Less violent message
|
||||
throw new Exception($sMessage);
|
||||
} elseif ($bLogMissingFile) {
|
||||
IssueLog::Debug($sMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,8 @@ class UIBlockNode extends Node
|
||||
->write("ob_end_clean();\n")
|
||||
->write("if (strlen(\$sHtml) > 0) {\n")
|
||||
->indent()->write("end(\$context['UIBlockParent'])->AddSubBlock(new \Combodo\iTop\Application\UI\Base\Component\Html\Html(\$sHtml));\n")->outdent()
|
||||
->write("}\n") ->write("\$aParams = ")
|
||||
->write("}\n")
|
||||
->write("\$aParams = ")
|
||||
->subcompile($oParams)
|
||||
->raw(";\n");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user