Skip to content

TASK: Make neos/symfonymailer an optional dependency #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 15, 2025
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
16 changes: 14 additions & 2 deletions Classes/Runtime/Action/EmailAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\ActionResponse;
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
use Neos\Flow\ResourceManagement\PersistentResource;
use Neos\Fusion\Form\Runtime\Domain\Exception\ActionException;
use Neos\SymfonyMailer\Service\MailerService;
Expand All @@ -28,14 +29,18 @@
class EmailAction extends AbstractAction
{
#[Flow\Inject]
protected MailerService $mailerService;
protected ObjectManagerInterface $objectManager;

/**
* @return ActionResponse|null
* @throws ActionException
*/
public function perform(): ?ActionResponse
{
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;
$text = $this->options['text'] ?? null;
$html = $this->options['html'] ?? null;
Expand Down Expand Up @@ -119,7 +124,7 @@ public function perform(): ?ActionResponse
);
return $response;
} else {
$this->mailerService->getMailer()->send($mail);
$this->getMailerService()->getMailer()->send($mail);
}

return null;
Expand Down Expand Up @@ -154,4 +159,11 @@ protected function addAttachments(Email $mail): void
}
}
}

private function getMailerService(): MailerService
{
/** @var MailerService $mailerService */
$mailerService = $this->objectManager->get(MailerService::class);
return $mailerService;
}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
"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": {
"phpunit/phpunit": "^7.1 || ^8.0 || ^9.0",
"phpstan/phpstan": "^2.1"
"phpstan/phpstan": "^2.1",
"neos/symfonymailer": "^0.1.0"
},
"suggest": {
"neos/symfonymailer": "Required for the Neos.Fusion.Form.Runtime:Email action to work"
Expand Down