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 array $params
29 * The mailing which may or may not be sendable.
31 * List of error messages.
33 public static function createAndRun(array $params): array {
34 $mailing = new \
CRM_Mailing_BAO_Mailing();
35 $mailing->id
= $params['id'] ??
NULL;
39 $mailing->copyValues($params);
41 return (new Validator())->run(array(
42 'mailing' => $mailing,
43 'attachments' => \CRM_Core_BAO_File
::getEntityFile('civicrm_mailing', $mailing->id
),
48 * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
53 * FlexMailer constructor.
54 * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
56 public function __construct(EventDispatcherInterface
$dispatcher = NULL) {
57 $this->dispatcher
= $dispatcher ?
$dispatcher : \Civi
::service('dispatcher');
61 * @param array $context
62 * An array which must define options:
63 * - mailing: \CRM_Mailing_BAO_Mailing
64 * - attachments: array
66 * List of error messages.
67 * Ex: array('subject' => 'The Subject field is blank').
68 * Example keys: 'subject', 'name', 'from_name', 'from_email', 'body', 'body_html:unsubscribeUrl'.
70 public function run($context) {
71 $checkSendable = new CheckSendableEvent($context);
72 $this->dispatcher
->dispatch(static::EVENT_CHECK_SENDABLE
, $checkSendable);
73 return $checkSendable->getErrors();