3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
11 namespace Civi\FlexMailer
;
13 use Civi\FlexMailer\Event\CheckSendableEvent
;
14 use Symfony\Component\EventDispatcher\EventDispatcherInterface
;
18 * @package Civi\FlexMailer
20 * The *validator* determines whether a mailing is completely specified
21 * (sendable). If not, delivery should be blocked.
25 const EVENT_CHECK_SENDABLE
= 'civi.flexmailer.checkSendable';
28 * @param \CRM_Mailing_DAO_Mailing $mailing
29 * The mailing which may or may not be sendable.
31 * List of error messages.
33 public static function createAndRun($mailing) {
34 $validator = new \Civi\FlexMailer\
Validator();
35 return $validator->run(array(
36 'mailing' => $mailing,
37 'attachments' => \CRM_Core_BAO_File
::getEntityFile('civicrm_mailing', $mailing->id
),
42 * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
47 * FlexMailer constructor.
48 * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
50 public function __construct(EventDispatcherInterface
$dispatcher = NULL) {
51 $this->dispatcher
= $dispatcher ?
$dispatcher : \Civi
::service('dispatcher');
55 * @param array $context
56 * An array which must define options:
57 * - mailing: \CRM_Mailing_BAO_Mailing
58 * - attachments: array
60 * List of error messages.
61 * Ex: array('subject' => 'The Subject field is blank').
62 * Example keys: 'subject', 'name', 'from_name', 'from_email', 'body', 'body_html:unsubscribeUrl'.
64 public function run($context) {
65 $checkSendable = new CheckSendableEvent($context);
66 $this->dispatcher
->dispatch(static::EVENT_CHECK_SENDABLE
, $checkSendable);
67 return $checkSendable->getErrors();