This question has been answered by Bruno17. See the first response.
<?php
if (empty($scriptProperties['object_id'])) {
$updateerror = true;
$errormsg = $modx->lexicon('quip.thread_err_ns');
return;
}
$config = $modx->migx->customconfigs;
$includeTVList = $modx->getOption('includeTVList', $config, '');
$includeTVList = !empty($includeTVList) ? explode(',', $includeTVList) : array();
$includeTVs = $modx->getOption('includeTVs', $config, false);
$classname = 'modResource';
$newstemplate = $modx->getOption('newstemplate', $config, '');
$newsparent = $modx->getOption('newsparent', $config, '');
//$saveTVs = false;
/*
if ($modx->lexicon) {
$modx->lexicon->load($packageName . ':default');
}
*/
if (isset($scriptProperties['data'])) {
//$scriptProperties = array_merge($scriptProperties, $modx->fromJson($scriptProperties['data']));
$data = $modx->fromJson($scriptProperties['data']);
}
$data['id'] = $modx->getOption('object_id', $scriptProperties, null);
//$parent = $modx->getOption('resource_id', $scriptProperties, false);
$checkresponse = true;
$task = $modx->getOption('task', $scriptProperties, '');
switch ($task) {
case 'publish':
if ($modx->hasPermission('publish_document')) {
$response = $modx->runProcessor('resource/publish', $data);
} else {
$updateerror = true;
$errormsg = 'Fehlende Berechtigung, News zu veröffentlichen';
return;
}
break;
case 'unpublish':
$response = $modx->runProcessor('resource/unpublish', $data);
break;
case 'delete':
$response = $modx->runProcessor('resource/delete', $data);
break;
case 'recall':
$object = $modx->getObject($classname, $scriptProperties['object_id']);
$object->set('deleted', '0');
$object->save();
$checkresponse = false;
break;
default:
//$modx->migx->loadConfigs();
//$tabs = $modx->migx->getTabs();
$freigabe = $modx->getOption('tv_news_freigabe_erwartet', $data, '');
if (is_array($freigabe)) {
$data['tv_news_freigabe_erwartet'] = array();
foreach ($freigabe as $value) {
if ($value == '2') {
$send_mail = true;
} else {
$data['tv_news_freigabe_erwartet'][] = $value;
}
}
} elseif ($freigabe == '2') {
$send_mail = true;
unset($data['tv_news_freigabe_erwartet']);
}
$data['context_key'] = 'web';
//$data['context_key'] = $modx->getOption('context_key', $data, $scriptProperties['wctx']);
$date = $modx->getOption('tv_News_Datum', $data, strftime('%Y-%m-%d %H:%M:%S'));
$title = $modx->getOption('pagetitle', $data, '');
if ($includeTVs) {
$c = $modx->newQuery('modTemplateVar');
$collection = $modx->getCollection('modTemplateVar', $c);
foreach ($collection as $tv) {
$tvname = $tv->get('name');
if (isset($data[$tvname])) {
$value = $data[$tvname];
$data['tv' . $tv->get('id')] = $value;
unset($data[$tvname]);
}
}
$data['tvs'] = 1;
}
//get/create news-parent (year-directory)
if ($resource = $modx->getObject('modResource', array('parent' => $newsparent, 'pagetitle' => strftime('%Y', strtotime($date))))) {
$parent = $resource->get('id');
} else {
//todo: set all fields correctly
$resource = $modx->newObject('modResource');
$resource->set('pagetitle', strftime('%Y', strtotime($date)));
$resource->set('longtitle', strftime('%Y', strtotime($date)));
$resource->set('parent', $newsparent);
$resource->set('class_key', 'modWebLink');
$resource->set('content', '1');
$resource->save();
$parent = $resource->get('id');
}
if ($scriptProperties['object_id'] == 'new') {
//$object = $modx->newObject($classname);
$resource = $modx->newObject('modResource');
if (empty($title)) {
$updateerror = true;
$errormsg = 'Das Feld Titel muß ausgefüllt werden';
return;
}
//$data['pagetitle'] = strftime('%y-%m-%d', strtotime($date)) . '_' . $resource->cleanAlias($title);
if (!empty($parent)) {
$data['parent'] = $parent;
}
$data['template'] = $newstemplate;
$data['hidemenu'] = 1;
$data['published'] = 0;
$response = $modx->runProcessor('resource/create', $data);
} else {
//$object = $modx->getObject($classname, $scriptProperties['object_id']);
//if (empty($object)) return $modx->error->failure($modx->lexicon('quip.thread_err_nf'));
if (!empty($parent)) {
$data['parent'] = $parent;
}
$response = $modx->runProcessor('resource/update', $data);
}
}
if ($checkresponse) {
if ($response->isError()) {
$updateerror = true;
$errormsg = $response->getMessage();
}
$object = $response->getObject();
}
if ($send_mail) {
$mailTo = '[email protected]';
//$mailTo = '[email protected]';
$ph = $object;
$ph['message'] = $modx->getOption('freigabe_text', $data);
$message = $modx->getChunk('ch_News_Freischalt_Benachrichtigungs_Mail', $ph);
$parts = explode('<--subject-->', $message);
if (count($parts) > 1) {
$subject = $parts[0];
$message = nl2br($parts[1]);
}
$emailFromAddress = $modx->getOption('emailsender');
$emailFromName = $modx->getOption('site_name');
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY, $message);
$modx->mail->set(modMail::MAIL_FROM, $emailFromAddress);
$modx->mail->set(modMail::MAIL_FROM_NAME, $emailFromName);
$modx->mail->set(modMail::MAIL_SENDER, $emailFromAddress);
$modx->mail->set(modMail::MAIL_SUBJECT, $subject);
$mailTo = explode(',', $mailTo);
if (is_array($mailTo)) {
foreach ($mailTo as $email) {
$modx->mail->address('to', $email);
}
}
$modx->mail->address('reply-to', $emailFromAddress);
$modx->mail->setHTML(true);
$success = $modx->mail->send();
if (!$success) {
$modx->log(modX::LOG_LEVEL_ERROR, 'An error occurred while trying to send the email: Freischalt Benachrichtigung');
}
$modx->mail->reset();
}
Here's a custom-update-processor, which I've used recently for a project, which does that:
<?php
$mailTo = 'myemail';
$message = 'test';
$emailFromAddress = $modx->getOption('emailsender');
$emailFromName = $modx->getOption('site_name');
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY, $message);
$modx->mail->set(modMail::MAIL_FROM, $emailFromAddress);
$modx->mail->set(modMail::MAIL_FROM_NAME, $emailFromName);
$modx->mail->set(modMail::MAIL_SENDER, $emailFromAddress);
$modx->mail->set(modMail::MAIL_SUBJECT, $subject);
$mailTo = explode(',', $mailTo);
if (is_array($mailTo)) {
foreach ($mailTo as $email) {
$modx->mail->address('to', $email);
}
}
$modx->mail->address('reply-to', $emailFromAddress);
$modx->mail->setHTML(true);
$success = $modx->mail->send();
if (!$success) {
$modx->log(modX::LOG_LEVEL_ERROR, 'An error occurred while trying
to send the email');
}
$modx->mail->reset();
?>if(field confirmed == 'yes') { email code } and also pull in the emailfield for the toemail.
<?php
include $modx->getOption('core_path') . 'components/migx/processors/mgr/default/update.php';
$confirmed = $modx->getOption('confirmed', $postvalues, '');
if ($confirmed == 'yes') {
$mailTo = $modx->getOption('email', $postvalues, '');
$message = 'test';
$emailFromAddress = $modx->getOption('emailsender');
$emailFromName = $modx->getOption('site_name');
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY, $message);
$modx->mail->set(modMail::MAIL_FROM, $emailFromAddress);
$modx->mail->set(modMail::MAIL_FROM_NAME, $emailFromName);
$modx->mail->set(modMail::MAIL_SENDER, $emailFromAddress);
$modx->mail->set(modMail::MAIL_SUBJECT, $subject);
$mailTo = explode(',', $mailTo);
if (is_array($mailTo)) {
foreach ($mailTo as $email) {
$modx->mail->address('to', $email);
}
}
$modx->mail->address('reply-to', $emailFromAddress);
$modx->mail->setHTML(true);
$success = $modx->mail->send();
if (!$success) {
$modx->log(modX::LOG_LEVEL_ERROR, 'An error occurred while trying to send the email');
}
$modx->mail->reset();
}
?>
if you was using the default update-processor before, try something like this: