-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[5.2][Events] Class for MailBeforeRendering event #43529
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
libraries/src/Event/Mail/BeforeRenderingMailTemplateEvent.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Joomla! Content Management System | ||
| * | ||
| * @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org> | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| namespace Joomla\CMS\Event\Mail; | ||
|
|
||
| /** | ||
| * Class for MailTemplate events | ||
| * Example: | ||
| * new BeforeRenderingMailTemplateEvent('onEventName', ['templateId' => 'com_example.template', 'subject' => $mailTemplateInstance]); | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| class BeforeRenderingMailTemplateEvent extends MailTemplateEvent | ||
| { | ||
| /** | ||
| * The argument names, in order expected by legacy plugins. | ||
| * | ||
| * @var array | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| * @deprecated __DEPLOY_VERSION__ will be removed in 6.0 | ||
| */ | ||
| protected $legacyArgumentsOrder = ['templateId', 'subject']; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Joomla! Content Management System | ||
| * | ||
| * @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org> | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| namespace Joomla\CMS\Event\Mail; | ||
|
|
||
| use Joomla\CMS\Event\AbstractImmutableEvent; | ||
| use Joomla\CMS\Event\ReshapeArgumentsAware; | ||
| use Joomla\CMS\Mail\MailTemplate; | ||
|
|
||
| // phpcs:disable PSR1.Files.SideEffects | ||
| \defined('_JEXEC') or die; | ||
| // phpcs:enable PSR1.Files.SideEffects | ||
|
|
||
| /** | ||
| * Base class for MailTemplate events | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| abstract class MailTemplateEvent extends AbstractImmutableEvent | ||
| { | ||
| use ReshapeArgumentsAware; | ||
|
|
||
| /** | ||
| * The argument names, in order expected by legacy plugins. | ||
| * | ||
| * @var array | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| * @deprecated __DEPLOY_VERSION__ will be removed in 6.0 | ||
| */ | ||
| protected $legacyArgumentsOrder = []; | ||
|
|
||
| /** | ||
| * Constructor. | ||
| * | ||
| * @param string $name The event name. | ||
| * @param array $arguments The event arguments. | ||
| * | ||
| * @throws \BadMethodCallException | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function __construct($name, array $arguments = []) | ||
| { | ||
| // Reshape the arguments array to preserve b/c with legacy listeners | ||
| if ($this->legacyArgumentsOrder) { | ||
| $arguments = $this->reshapeArguments($arguments, $this->legacyArgumentsOrder); | ||
| } | ||
|
|
||
| parent::__construct($name, $arguments); | ||
|
|
||
| if (!\array_key_exists('subject', $this->arguments)) { | ||
| throw new \BadMethodCallException("Argument 'subject' of event {$name} is required but has not been provided"); | ||
| } | ||
|
|
||
| if (!\array_key_exists('templateId', $this->arguments)) { | ||
| throw new \BadMethodCallException("Argument 'templateId' of event {$name} is required but has not been provided"); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Pre-Setter for the subject argument. | ||
| * | ||
| * @param MailTemplate $value The value to set | ||
| * | ||
| * @return MailTemplate | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| protected function onSetSubject(MailTemplate $value): MailTemplate | ||
| { | ||
| return $value; | ||
| } | ||
|
|
||
| /** | ||
| * Pre-getter for the subject argument. | ||
| * | ||
| * @param MailTemplate $value The value to set | ||
| * | ||
| * @return MailTemplate | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| protected function onGetSubject(MailTemplate $value): MailTemplate | ||
| { | ||
| return $value; | ||
| } | ||
|
|
||
| /** | ||
| * Pre-setter for the templateId argument. | ||
| * | ||
| * @param string $value The value to set | ||
| * | ||
| * @return string | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| protected function onSetTemplateId(string $value): string | ||
| { | ||
| return $value; | ||
| } | ||
|
|
||
| /** | ||
| * Pre-getter for the templateId argument. | ||
| * | ||
| * @param string $value The value to set | ||
| * | ||
| * @return string | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| protected function onGetTemplateId(string $value): string | ||
| { | ||
| return $value; | ||
| } | ||
|
|
||
| /** | ||
| * Getter for the subject argument. | ||
| * | ||
| * @return MailTemplate | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function getTemplate(): MailTemplate | ||
| { | ||
| return $this->getArgument('subject'); | ||
| } | ||
|
|
||
| /** | ||
| * Getter for the templateId argument. | ||
| * | ||
| * @return string | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function getTemplateId(): string | ||
| { | ||
| return $this->getArgument('templateId'); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.