Commit c6f468bd authored by Paul Ilea's avatar Paul Ilea
Browse files

[BUGFIX] File references are moved from original record to mail

parent a7e8c34d
......@@ -35,6 +35,7 @@ use Swift_Attachment;
use Swift_OutputByteStream;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Mail\MailMessage;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Extbase\Object\ObjectManager;
......@@ -153,6 +154,11 @@ class MailTemplateService {
*/
protected $objectManager;
/**
* @var TYPO3\CMS\Core\Resource\ResourceFactory
*/
protected $resourceFactory;
/**
* MailTemplateService constructor.
*
......@@ -175,6 +181,7 @@ class MailTemplateService {
$tsSettings = $typoScriptSettingsService->getSettings(0, 'tx_sgmail');
$this->templateRepository = $this->objectManager->get(TemplateRepository::class);
$this->persistenceManager = $this->objectManager->get(PersistenceManager::class);
$this->resourceFactory = $this->objectManager->get(ResourceFactory::class);
// use defaultMailFromAddress if it is provided in LocalConfiguration.php; use the sg_mail TS setting as fallback
if (filter_var($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'], FILTER_VALIDATE_EMAIL)) {
......@@ -401,9 +408,30 @@ class MailTemplateService {
* @param FileReference $file
*
* @return MailTemplateService
* @throws \TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException
*/
public function addFileResourceAttachment(FileReference $file): MailTemplateService {
$this->markers[] = $file;
$originalResource = $file->getOriginalResource();
if (!$originalResource) {
return $this;
}
$originalFile = $originalResource->getOriginalFile();
if (!$originalFile) {
return $this;
}
$coreFileReferenceMailFile = $this->resourceFactory->createFileReferenceObject(
[
'uid_local' => $originalFile->getUid(),
'table_local' => 'sys_file',
'uid' => uniqid('NEW_MAIL', TRUE)
]
);
$newFileReference = GeneralUtility::makeInstance(FileReference::class);
$newFileReference->setOriginalResource($coreFileReferenceMailFile);
$this->markers[] = $newFileReference;
return $this;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment