Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: [ '7.3', '7.4' ]
flow-versions: [ '6.3', '7.0' ]
include:
- php-versions: '7.2'
flow-versions: '6.0'
- php-versions: '8.0'
flow-versions: '7.0'
php-versions: [ '8.2', '8.3', '8.4' ]
flow-versions: [ '8.3', '9.0' ]

runs-on: ubuntu-latest

Expand Down
1 change: 1 addition & 0 deletions Classes/Domain/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ public function calculateHiddenFields(?string $content = null): array
//
if ($request && ($this->enableReferrer === true)) {
$childRequestArgumentNamespace = null;
/** @phpstan-ignore-next-line */
while ($request instanceof ActionRequest) {
$requestArgumentNamespace = $request->getArgumentNamespace();
$hiddenFields[$this->prefixFieldName('__referrer[@package]', $requestArgumentNamespace)] = $request->getControllerPackageKey();
Expand Down
55 changes: 31 additions & 24 deletions Classes/Runtime/Action/EmailAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,31 @@
* source code.
*/

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\ActionResponse;
use Neos\Flow\ResourceManagement\PersistentResource;
use Neos\Fusion\Form\Runtime\Domain\Exception\ActionException;
use Neos\SwiftMailer\Message as SwiftMailerMessage;
use Neos\SymfonyMailer\Service\MailerService;
use Neos\Utility\MediaTypes;
use Psr\Http\Message\UploadedFileInterface;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Part\DataPart;
use Symfony\Component\Mime\Part\File;

class EmailAction extends AbstractAction
{
#[Flow\Inject]
protected MailerService $mailerService;

/**
* @return ActionResponse|null
* @throws ActionException
*/
public function perform(): ?ActionResponse
{
if (!class_exists(SwiftMailerMessage::class)) {
throw new ActionException('The "neos/swiftmailer" doesn\'t seem to be installed, but is required for the EmailAction to work!', 1503392532);
if (!class_exists(MailerService::class)) {
throw new ActionException('The "neos/symfonymailer" doesn\'t seem to be installed, but is required for the EmailAction to work!', 1503392532);
}

$subject = $this->options['subject'] ?? null;
Expand Down Expand Up @@ -59,37 +67,36 @@ public function perform(): ?ActionResponse
throw new ActionException('The option "senderAddress" must be set for the EmailAction.', 1327060210);
}

$mail = new SwiftMailerMessage();

$mail = new Email();
$mail
->setFrom($senderName ? [$senderAddress => $senderName] : $senderAddress)
->setSubject($subject);
->addFrom(new Address($senderAddress, $senderName))
->subject($subject);

if (is_array($recipientAddress)) {
$mail->setTo($recipientAddress);
$mail->addTo(...array_map(fn ($entry) => new Address($entry), $recipientAddress));
} else {
$mail->setTo($recipientName ? [$recipientAddress => $recipientName] : $recipientAddress);
$mail->addTo(new Address($recipientAddress, $recipientName));
}

if ($replyToAddress !== null) {
$mail->setReplyTo($replyToAddress);
$mail->addReplyTo(new Address($replyToAddress));
}

if ($carbonCopyAddress !== null) {
$mail->setCc($carbonCopyAddress);
$mail->addCc(new Address($carbonCopyAddress));
}

if ($blindCarbonCopyAddress !== null) {
$mail->setBcc($blindCarbonCopyAddress);
$mail->addBcc(new Address($blindCarbonCopyAddress));
}

if ($text !== null && $html !== null) {
$mail->setBody($html, 'text/html');
$mail->addPart($text, 'text/plain');
$mail->html($html);
$mail->text($text);
} elseif ($text !== null) {
$mail->setBody($text, 'text/plain');
$mail->text($text);
} elseif ($html !== null) {
$mail->setBody($html, 'text/html');
$mail->html($html);
}

$this->addAttachments($mail);
Expand All @@ -116,37 +123,37 @@ public function perform(): ?ActionResponse
);
return $response;
} else {
$mail->send();
$this->mailerService->getMailer()->send($mail);
}

return null;
}

/**
* @param SwiftMailerMessage $mail
* @param Email $mail
*/
protected function addAttachments(SwiftMailerMessage $mail): void
protected function addAttachments(Email $mail): void
{
$attachments = $this->options['attachments'] ?? null;
if (is_array($attachments)) {
foreach ($attachments as $attachment) {
if (is_string($attachment)) {
$mail->attach(\Swift_Attachment::fromPath($attachment));
$mail->addPart(new DataPart(new File($attachment)));
} elseif (is_object($attachment) && ($attachment instanceof UploadedFileInterface)) {
$mail->attach(new \Swift_Attachment($attachment->getStream()->getContents(), $attachment->getClientFilename(), $attachment->getClientMediaType()));
$mail->addPart(new DataPart($attachment->getStream()->getContents(), $attachment->getClientFilename(), $attachment->getClientMediaType()));
} elseif (is_object($attachment) && ($attachment instanceof PersistentResource)) {
$stream = $attachment->getStream();
if (!is_bool($stream)) {
$content = stream_get_contents($stream);
if (!is_bool($content)) {
$mail->attach(new \Swift_Attachment($content, $attachment->getFilename(), $attachment->getMediaType()));
$mail->addPart(new DataPart($content, $attachment->getFilename(), $attachment->getMediaType()));
}
}
} elseif (is_array($attachment) && isset($attachment['content']) && isset($attachment['name'])) {
$content = $attachment['content'];
$name = $attachment['name'];
$type = $attachment['type'] ?? MediaTypes::getMediaTypeFromFilename($name);
$mail->attach(new \Swift_Attachment($content, $name, $type));
$type = $attachment['type'] ?? MediaTypes::getMediaTypeFromFilename($name);
$mail->addPart(new DataPart($content, $name, $type));
}
}
}
Expand Down
24 changes: 14 additions & 10 deletions Classes/Runtime/FusionObjects/ValidatorImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Neos\Error\Messages\Result;
use Neos\Flow\Validation\Validator\ValidatorInterface;
use Neos\Flow\Validation\ValidatorResolver;
use Neos\Fusion\Exception\RuntimeException;
use Neos\Fusion\FusionObjects\AbstractFusionObject;

class ValidatorImplementation extends AbstractFusionObject implements ValidatorInterface
Expand All @@ -27,15 +28,6 @@ class ValidatorImplementation extends AbstractFusionObject implements ValidatorI
*/
protected $validatorResolver;

/**
* Return reference to self during fusion evaluation
* @return $this
*/
public function evaluate()
{
return $this;
}

/**
* @param mixed $value
* @return Result
Expand All @@ -46,11 +38,23 @@ public function validate($value): Result
$this->fusionValue('type'),
$this->fusionValue('options')
);
if ($validator === null) {
throw new \RuntimeException('Validator could not get created.', 1744410020);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(how) is this change related?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phpstan was complaining.

return $validator->validate($value);
}

/**
* @return array[]
* Return reference to self during fusion evaluation
* @return $this
*/
public function evaluate()
{
return $this;
}

/**
* @return mixed[]
*/
public function getOptions(): array
{
Expand Down
3 changes: 3 additions & 0 deletions Classes/Runtime/Helper/SchemaDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ public function validate($data): Result
$validationConfiguration['type'],
$validationConfiguration['options'] ?? []
);
if ($validator === null) {
throw new \RuntimeException('Validator could not get created.', 1744410020);
}
$propertyValidationResult->merge($validator->validate($data));
}

Expand Down
4 changes: 2 additions & 2 deletions Documentation/RuntimeActionReference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ Example::
Neos.Fusion.Form.Runtime:Email
------------------------------

The email action uses swiftmailer to create and send an email. It supports
The email action uses symfonymailer to create and send an email. It supports
multipart emails and file attachments that can even be created on the fly from
form data.

.. note:: The neos/swiftmailer package must be installed separately.
.. note:: The neos/symfonymailer package must be installed separately.

Options:

Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
"GPL-3.0-or-later"
],
"require": {
"php" : ">7.2",
"neos/flow": "^6.0 || ^7.0 || ^8.0 || ^9.0 || dev-master",
"neos/fusion": "^5.0 || ^7.0 || ^8.0 || ^9.0 || dev-master",
"neos/fusion-afx": "^1.2 || ^7.0 || ^8.0 || ^9.0 || dev-master",
"php" : ">=8.2",
"neos/flow": "^8.0 || ^9.0",
"neos/fusion": "^8.0 || ^9.0",
"neos/fusion-afx": "^1.2 || ^7.0 || ^8.0 || ^9.0",
"neos/symfonymailer": "^0.1.0",
"neos/utility-arrays": "*",
"neos/utility-objecthandling": "*",
"psr/http-factory": "*"
},
"require-dev": {
"neos/swiftmailer": "*",
"phpunit/phpunit": "^7.1 || ^8.0 || ^9.0",
"phpstan/phpstan": "^0.12.78"
"phpstan/phpstan": "^2.1"
},
"suggest": {
"neos/swiftmailer": "Required for the Neos.Fusion.Form.Runtime:Email action to work"
"neos/symfonymailer": "Required for the Neos.Fusion.Form.Runtime:Email action to work"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ parameters:
level: 1
paths:
- Classes
treatPhpDocTypesAsCertain: false
reportUnmatchedIgnoredErrors: false
ignoreErrors:
- '#Unsafe usage of new static\(\).#'