Add email delivery for testing purposes
In order to demonstrate mailhog integration into codeception. Also refactor logic into signal / slot to not bloat controller.
This commit is contained in:
parent
0f56c2a93b
commit
e88fcf02b1
3 changed files with 70 additions and 7 deletions
|
@ -55,13 +55,11 @@ class AddressController extends ActionController
|
||||||
{
|
{
|
||||||
$this->addressRepository->update($address);
|
$this->addressRepository->update($address);
|
||||||
|
|
||||||
$this->addFlashMessage(
|
$this->signalSlotDispatcher->dispatch(__CLASS__, 'addressUpdated', [
|
||||||
LocalizationUtility::translate('flashSuccess', 'ExampleExtension', [
|
$address,
|
||||||
'companyName' => $address->getCompanyName(),
|
$this,
|
||||||
'street' => $address->getStreet(),
|
]);
|
||||||
]),
|
|
||||||
'Update successfully'
|
|
||||||
);
|
|
||||||
$this->redirect('index');
|
$this->redirect('index');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Workshop\ExampleExtension\Domain\Event;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2019 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use TYPO3\CMS\Core\Mail\MailMessage;
|
||||||
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||||
|
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
|
||||||
|
use Workshop\ExampleExtension\Controller\AddressController;
|
||||||
|
use Workshop\ExampleExtension\Domain\Model\Address as AddressModel;
|
||||||
|
|
||||||
|
class Address
|
||||||
|
{
|
||||||
|
public function updated(AddressModel $address, AddressController $controller)
|
||||||
|
{
|
||||||
|
$this->sendUpdateEMail($address);
|
||||||
|
$this->addUpdateFlashMessage($address, $controller);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sendUpdateEmail(AddressModel $address)
|
||||||
|
{
|
||||||
|
$mail = GeneralUtility::makeInstance(MailMessage::class);
|
||||||
|
|
||||||
|
$mail->setSubject('Address ' . $address->getCompanyName() . ' was updated');
|
||||||
|
$mail->setTo(array('coding@daniel-siepmann.de'));
|
||||||
|
$mail->setBody('The address ' . $address->getCompanyName() . ' was successfully updated.');
|
||||||
|
$mail->send();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function addUpdateFlashMessage(AddressModel $address, AddressController $controller)
|
||||||
|
{
|
||||||
|
$controller->addFlashMessage(
|
||||||
|
LocalizationUtility::translate('flashSuccess', 'ExampleExtension', [
|
||||||
|
'companyName' => $address->getCompanyName(),
|
||||||
|
'street' => $address->getStreet(),
|
||||||
|
]),
|
||||||
|
'Update successfully'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -41,4 +41,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
');
|
');
|
||||||
|
|
||||||
|
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class)->connect(
|
||||||
|
\Workshop\ExampleExtension\Controller\AddressController::class,
|
||||||
|
'addressUpdated',
|
||||||
|
\Workshop\ExampleExtension\Domain\Event\Address::class,
|
||||||
|
'updated'
|
||||||
|
);
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in a new issue