[FEATURE] Add signal for mailer initialization 76/34176/8
authorMathias Brodala <mbrodala@pagemachine.de>
Fri, 14 Nov 2014 16:11:52 +0000 (17:11 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 13 Dec 2014 17:23:52 +0000 (18:23 +0100)
This signal allows for additional processing upon initialization
of a mailer object, e.g. registering a Swift mailer plugin.

Resolves: #62960
Releases: master
Change-Id: I048de8ef422911d5863ab2a05312dc7f8c7d195f
Reviewed-on: http://review.typo3.org/34176
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/core/Classes/Mail/Mailer.php
typo3/sysext/core/Documentation/Changelog/master/Feature-62960-SignalForMailerInitialization.rst [new file with mode: 0644]

index a7ec245..1b38016 100644 (file)
@@ -17,6 +17,10 @@ namespace TYPO3\CMS\Core\Mail;
 // Make sure Swift's auto-loader is registered
 require_once PATH_typo3 . 'contrib/swiftmailer/lib/swift_required.php';
 
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Object\ObjectManager;
+use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
+
 /**
  * Adapter for Swift_Mailer to be used by TYPO3 extensions.
  *
@@ -57,6 +61,8 @@ class Mailer extends \Swift_Mailer {
                        }
                }
                parent::__construct($this->transport);
+
+               $this->emitPostInitializeMailerSignal();
        }
 
        /**
@@ -146,4 +152,30 @@ class Mailer extends \Swift_Mailer {
                }
        }
 
+       /**
+        * Get the object manager
+        *
+        * @return \TYPO3\CMS\Extbase\Object\ObjectManager
+        */
+       protected function getObjectManager() {
+               return GeneralUtility::makeInstance(ObjectManager::class);
+       }
+
+       /**
+        * Get the SignalSlot dispatcher
+        *
+        * @return \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
+        */
+       protected function getSignalSlotDispatcher() {
+               return $this->getObjectManager()->get(Dispatcher::class);
+       }
+
+       /**
+        * Emits a signal after mailer initialization
+        *
+        * @return void
+        */
+       protected function emitPostInitializeMailerSignal() {
+               $this->getSignalSlotDispatcher()->dispatch('TYPO3\\CMS\\Core\\Mail\\Mailer', 'postInitializeMailer', array($this));
+       }
 }
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-62960-SignalForMailerInitialization.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-62960-SignalForMailerInitialization.rst
new file mode 100644 (file)
index 0000000..2451d35
--- /dev/null
@@ -0,0 +1,49 @@
+==================================================
+Feature: #62960 - Signal for mailer initialization
+==================================================
+
+Description
+===========
+
+This signal allows for additional processing upon initialization of a mailer object,
+e.g. registering a Swift mailer plugin.
+
+Registering the signal:
+
+::
+
+       $signalSlotDispatcher = \\TYPO3\\CMS\\Core\\Utility\\GeneralUtility::makeInstance(\\TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher::class);
+       $signalSlotDispatcher->connect(
+               \\TYPO3\\CMS\\Core\\Mail\\Mailer::class,
+               'postInitializeMailer',
+               \\Vendor\\Package\\Slots\\MailerSlot::class,
+               'registerPlugin'
+       );
+
+..
+
+The slot class:
+
+::
+
+       <?php
+       namespace Vendor\\Package\\Slots;
+
+       use TYPO3\\CMS\\Core\\Mail\\Mailer;
+
+       class MailerSlot {
+               /**
+                * @param Mailer $mailer
+                * @return void
+                */
+               public function registerPlugin(Mailer $mailer) {
+                       // Processing here
+               }
+       }
+
+..
+
+Impact
+======
+
+Extensions may now perform arbitrary processing for every mail.