public function AddMailchimpEventWebformHandler::postSave in Mailchimp 2.x
Acts on a saved webform submission before the insert or update hook is invoked.
Parameters
\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.
bool $update: TRUE if the entity has been updated, or FALSE if it has been inserted.
Overrides WebformHandlerBase::postSave
File
- modules/
mailchimp_events/ src/ Plugin/ WebformHandler/ AddMailchimpEventWebformHandler.php, line 303
Class
- AddMailchimpEventWebformHandler
- Webform submission Event handler.
Namespace
Drupal\mailchimp_events\Plugin\WebformHandlerCode
public function postSave(WebformSubmissionInterface $webform_submission, $update = TRUE) {
$email = $this
->getEmail();
$list = $this->configuration['list'];
$properties = $this->configuration['properties'];
$send_properties = [];
if ($properties) {
foreach ($properties as $key => $value) {
$send_properties[$key] = $this
->replaceTokens($value, $this
->getWebformSubmission(), [], [
'clear' => TRUE,
]);
}
}
$event_name = $this
->getEventName($this->configuration['event_name']);
$is_syncing = $this->configuration['is_syncing'];
$result = mailchimp_events_add_member_event($list, $email, $event_name, $send_properties, $is_syncing);
if ($this->configuration['debug']) {
$debug = $this
->t("Called function: mailchimp_events_add_member_event(%list, %email, %event_name, %properties, %is_syncing).", [
'%list' => $list,
'%email' => $email,
'%event_name' => $event_name,
'%properties' => print_r($send_properties, TRUE),
'%is_syncing' => $is_syncing,
]);
if ($result !== FALSE) {
$this
->messenger()
->addStatus($debug);
}
else {
$this
->messenger()
->addError($debug);
$this
->messenger()
->addError($this
->t('Member event add failed. Check the <a href=":watchdog">logs for Mailchimp</a>', [
':watchdog' => Url::fromRoute('dblog.overview')
->toString(),
]));
}
}
}