[TASK] Improve ajax and mail sending handling

This commit is contained in:
Philipp Dieter
2021-10-26 23:50:04 +02:00
parent 46f7b519b7
commit f206c8fb0e
4 changed files with 293 additions and 18 deletions

View File

@@ -24,6 +24,7 @@ use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
use TYPO3\CMS\Extbase\Property\PropertyMapper;
use TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationBuilder;
use TYPO3\CMS\Extbase\Service\EnvironmentService;
use TYPO3\CMS\Extbase\Service\ExtensionService;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
@@ -148,6 +149,22 @@ class ActionController extends BaseController
$this->extensionService = $extensionService;
}
/**
* environmentService
*
* @var EnvironmentService
*/
protected $environmentService;
/**
* @param
*/
public function injectEnvironmentService(
EnvironmentService $environmentService
) {
$this->environmentService = $environmentService;
}
/**
* propertyMapper
*
@@ -253,7 +270,7 @@ class ActionController extends BaseController
}
/**
* returns an instance of uribuilder
*
*/
public function persistAll()
{
@@ -596,11 +613,14 @@ class ActionController extends BaseController
->setCreateAbsoluteUri(true)
->setAddQueryString(true)
->setTargetPageType($this->ajaxPageType)
->setArguments(['cid' => $this->contentObjectUid])
->setArguments([
'cid' => $this->contentObjectUid,
'type' => $this->ajaxPageType,
])
->uriFor($this->request->getControllerActionName());
$this->ajaxEnv = [
'uri' => $uri,
'object' => $object,
'uri' => $uri,
'object' => $object,
'namespace' => $this->getPluginNamespace(),
];
}
@@ -744,7 +764,11 @@ class ActionController extends BaseController
$this->response->setStatus($this->responseStatus);
}
if ($this->pageType == $this->ajaxPageType) {
$GLOBALS['TSFE']->setContentType('application/json');
if ($this->environmentService->isEnvironmentInBackendMode()) {
header('Content-Type: application/json');
} else {
$GLOBALS['TSFE']->setContentType('application/json');
}
}
unset($result['data']);
if ($this->redirect) {
@@ -769,5 +793,4 @@ class ActionController extends BaseController
}
$this->view->assignMultiple($result);
}
}

View File

@@ -36,9 +36,10 @@ class MailUtility
*/
public static function parseContentTemplate(
$text,
$markers = []
$markers = [],
$lineEnd = "\r\n"
) {
$textParts = explode("\r\n\r\n", $text);
$textParts = explode($lineEnd . $lineEnd, $text);
$result = [];
foreach ($textParts as $textPart) {
$type = 'text';
@@ -54,6 +55,22 @@ class MailUtility
$type = 'headline3';
$textPart = substr($textPart, 4);
}
if (substr($textPart, 0, 2) === '- ') {
$type = 'list';
$textPart = substr($textPart, 2);
}
if (substr($textPart, 0, 2) === '| ') {
$type = 'table';
$textPart = substr($textPart, 2);
}
if (substr($textPart, 0, 3) === '|| ') {
$type = 'tableLayout';
$textPart = substr($textPart, 3);
}
if (substr($textPart, 0, 9) === '%subject ') {
$type = 'subject';
$textPart = substr($textPart, 9);
}
foreach ($markers as $markerName => $markerContent) {
$textPart = str_replace(
'###' . $markerName . '###',
@@ -61,10 +78,40 @@ class MailUtility
$textPart
);
}
$result[] = [
'type' => $type,
'data' => $textPart,
];
switch($type) {
case 'table':
case 'tableLayout':
if (
$result[count($result) - 1]['type'] == $type
&& count($result[count($result) - 1]['data']) == 1
) {
$result[count($result) - 1]['data'][] = $textPart;
} else {
$result[] = [
'type' => $type,
'data' => [$textPart],
];
}
break;
case 'list':
if (
$result[count($result) - 1]['type'] == 'list'
) {
$result[count($result) - 1]['data'][] = $textPart;
} else {
$result[] = [
'type' => 'list',
'data' => [$textPart],
];
}
break;
default:
$result[] = [
'type' => $type,
'data' => $textPart,
];
break;
}
}
return $result;
}
@@ -107,12 +154,22 @@ class MailUtility
$htmlView->setTemplate($templateNameHtml);
$textView = $objectManager->get(StandaloneView::class);
if ($templatePaths) {
$partialRootPaths = $htmlView->getPartialRootPaths();
$partialRootPaths[] = GeneralUtility::getFileAbsFileName(
'EXT:templates_aide/Resources/Private/Partials/'
);
$htmlView->setTemplateRootPaths(
$templatePaths->getTemplateRootPaths()
);
$htmlView->setPartialRootPaths(
$partialRootPaths
);
$textView->setTemplateRootPaths(
$templatePaths->getTemplateRootPaths()
);
$textView->setPartialRootPaths(
$partialRootPaths
);
} else {
$htmlView->getTemplatePaths()->fillDefaultsByPackageName(
'templates_aide'
@@ -130,6 +187,9 @@ class MailUtility
foreach ($data as $row) {
switch($row['type']) {
case 'text':
case 'table':
case 'tableLayout':
case 'list':
case 'textbold':
case 'headline':
case 'headline2':