Commit ff0a1e84 authored by Fabian Galinski's avatar Fabian Galinski 😾
Browse files

[TASK] Refactoring of the addFileResourceAttachment function

parent ec43cbcb
......@@ -35,8 +35,6 @@ use Swift_Attachment;
use Swift_OutputByteStream;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Mail\MailMessage;
use TYPO3\CMS\Core\Resource\FileInterface;
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;
......@@ -398,30 +396,24 @@ class MailTemplateService {
}
/**
* Add a file resource as attachment
* Adds a file resource as attachment
*
* @param FileReference $file
*
* @param FileInterface|FileReference $file
* @return MailTemplateService
* @throws \TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException
*/
public function addFileResourceAttachment($file): MailTemplateService {
if ($file instanceof FileReference) {
$file = $file->getOriginalResource()->getOriginalFile();
}
$fileReference = $this->objectManager->get(FileReference::class);
$resourceFactory = $this->objectManager->get(ResourceFactory::class);
$falFileReference = $resourceFactory->createFileReferenceObject(
[
'uid_local' => $file->getUid(),
'uid_foreign' => uniqid('NEW_', TRUE),
'uid' => uniqid('NEW_', TRUE),
'crop' => NULL,
]
);
$fileReference->setOriginalResource($falFileReference);
$this->markers[] = $fileReference;
public function addFileResourceAttachment(FileReference $file): MailTemplateService {
$originalResource = $file->getOriginalResource();
if (!$originalResource) {
return $this;
}
$this->markers[] = $file;
/** @noinspection PhpParamsInspection */
$this->addAttachment($file->getContents(), $file->getName(), $file->getMimeType());
$this->addAttachment(
$originalResource->getContents(), $originalResource->getName(), $originalResource->getMimeType()
);
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