Skip to content

Commit 761fbe9

Browse files
committed
[BUGFIX] Fix false positive error message that TypoScript is missing
When marketing static template was added. After some testing and playing with same strange results with the old method (throwing flashmessages in controller) I decided to switch to a ViewHelper were the check happens now. Beside that this seems to work for Pi1 and Pi2 more robust I think it is a better option, because someone can remove the VH and the check completely now if wanted. Related: #610
1 parent 2b3fe4e commit 761fbe9

File tree

6 files changed

+58
-47
lines changed

6 files changed

+58
-47
lines changed

Classes/Controller/FormController.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -403,21 +403,6 @@ public function initializeObject()
403403
$this->signalDispatch(__CLASS__, __FUNCTION__ . 'Settings', [$this, &$this->settings]);
404404
}
405405

406-
/**
407-
* @return void
408-
* @codeCoverageIgnore
409-
*/
410-
public function initializeAction()
411-
{
412-
parent::initializeAction();
413-
414-
// @codeCoverageIgnoreStart
415-
if (!isset($this->settings['staticTemplate'])) {
416-
$this->controllerContext = $this->buildControllerContext();
417-
$this->addFlashMessage(LocalizationUtility::translate('error_no_typoscript'), '', AbstractMessage::ERROR);
418-
}
419-
}
420-
421406
/**
422407
* Forward to formAction if wrong form in plugin variables given
423408
* used for createAction() and confirmationAction()

Classes/Controller/OutputController.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
*/
3333
class OutputController extends AbstractController
3434
{
35-
3635
/**
3736
* @return void
3837
* @throws InvalidQueryException
@@ -286,24 +285,6 @@ protected function assignMultipleActions(): void
286285
$this->view->assign('editPid', $this->settings['edit']['pid']);
287286
}
288287

289-
/**
290-
* @return void
291-
*/
292-
protected function initializeAction()
293-
{
294-
parent::initializeAction();
295-
296-
// check if ts is included
297-
if (!isset($this->settings['staticTemplate'])) {
298-
$this->controllerContext = $this->buildControllerContext();
299-
$this->addFlashMessage(
300-
LocalizationUtility::translate('error_no_typoscript_pi2'),
301-
'',
302-
AbstractMessage::ERROR
303-
);
304-
}
305-
}
306-
307288
/**
308289
* Add parameters to piVars from TypoScript
309290
*
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
declare(strict_types=1);
3+
namespace In2code\Powermail\ViewHelpers\Misc;
4+
5+
use In2code\Powermail\Utility\LocalizationUtility;
6+
use TYPO3\CMS\Core\Messaging\AbstractMessage;
7+
use TYPO3\CMS\Core\Messaging\FlashMessage;
8+
use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
9+
use TYPO3\CMS\Core\Utility\GeneralUtility;
10+
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
11+
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
12+
13+
/**
14+
* Class CheckForTypoScriptViewHelper
15+
* @noinspection PhpUnused
16+
*/
17+
class CheckForTypoScriptViewHelper extends AbstractViewHelper
18+
{
19+
/**
20+
* @return void
21+
*/
22+
public function initializeArguments()
23+
{
24+
parent::initializeArguments();
25+
$this->registerArgument('settings', 'array', 'settings array', true);
26+
}
27+
28+
/**
29+
* @param array $arguments
30+
* @param \Closure $renderChildrenClosure
31+
* @param RenderingContextInterface $renderingContext
32+
* @return void
33+
*/
34+
public static function renderStatic(
35+
array $arguments,
36+
\Closure $renderChildrenClosure,
37+
RenderingContextInterface $renderingContext
38+
): void {
39+
if ($arguments['settings']['staticTemplate'] !== '1') {
40+
/** @var FlashMessageQueue $flashMessageQueue */
41+
$flashMessageQueue = $renderingContext->getControllerContext()->getFlashMessageQueue(null);
42+
/** @var FlashMessage $flashMessage */
43+
$flashMessage = GeneralUtility::makeInstance(
44+
FlashMessage::class,
45+
LocalizationUtility::translate('error_no_typoscript'),
46+
'',
47+
AbstractMessage::ERROR
48+
);
49+
$flashMessageQueue->addMessage($flashMessage);
50+
}
51+
}
52+
}

Resources/Private/Language/de.locallang.xlf

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,8 @@
173173
<target state="translated">Fehler, die Nachricht konnte leider nicht korrekt versendet werden!</target>
174174
</trans-unit>
175175
<trans-unit id="error_no_typoscript">
176-
<source>No TypoScript settings given. Admin, did you already include the "Main" static template?</source>
177-
<target state="translated">Kein TypoScript gefunden. Sind Sie sicher, dass Sie das "Main" Static Template eingebunden haben?</target>
178-
</trans-unit>
179-
<trans-unit id="error_no_typoscript_pi2">
180-
<source>No TypoScript settings given. Admin, did you already include the "Powermail_Frontend" static template?</source>
181-
<target state="translated">Kein TypoScript gefunden. Sind Sie sicher, dass Sie das "Powermail_Frontend" Static Template eingebunden haben?</target>
176+
<source>TypoScript settings are missing. Did you include the related static templates?</source>
177+
<target state="translated">TypoScript benötigt. Sind Sie sicher, dass Sie die erforderlichen Static Templates eingebunden haben?</target>
182178
</trans-unit>
183179
<trans-unit id="error_no_sender_name">
184180
<source>No Sendername</source>

Resources/Private/Language/locallang.xlf

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,7 @@
130130
<source>Error, Mail could not sent correctly!</source>
131131
</trans-unit>
132132
<trans-unit id="error_no_typoscript" resname="error_no_typoscript">
133-
<source>No TypoScript settings given. Admin, did you already include the "Main" static template?</source>
134-
</trans-unit>
135-
<trans-unit id="error_no_typoscript_pi2" resname="error_no_typoscript_pi2">
136-
<source>No TypoScript settings given. Admin, did you already include the "Powermail_Frontend" static template?</source>
133+
<source>TypoScript settings are missing. Did you include the related static templates?</source>
137134
</trans-unit>
138135
<trans-unit id="error_no_sender_name" resname="error_no_sender_name">
139136
<source>No Sendername</source>

Resources/Private/Partials/Misc/FlashMessages.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<f:comment>
2-
Flashmessages for TYPO3 8.6 and newer
3-
</f:comment>
1+
{namespace vh=In2code\Powermail\ViewHelpers}
2+
<vh:misc.checkForTypoScript settings="{settings}" />
3+
44
<f:flashMessages as="flashMessages">
55
<ul class="powermail_message {flashMessageClass}">
66
<f:for each="{flashMessages}" as="flashMessage">

0 commit comments

Comments
 (0)