Skip to content

Commit

Permalink
Merge pull request #2 from UCBoulder/713
Browse files Browse the repository at this point in the history
Service Alert titles
  • Loading branch information
protitude authored Oct 23, 2024
2 parents bbe67a6 + f1b7fc8 commit e2604d7
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions sympa.module
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ function sympa_mail($key, &$message, $params) {
switch ($key) {
case 'subscriptions':
$message['from'] = \Drupal::config('system.site')->get('mail');
$message['headers'] = [
'reply-To' => '[email protected]',
];
$message['body'][] = $params['action'] . ' ' . $params['type'] . ' ' . $params['email'] . ' ' . $params['name'];
break;

case 'node-update':
$message['from'] = \Drupal::config('system.site')->get('mail');
$message['headers'] = [
'reply-To' => '[email protected]',
];
$message['subject'] = $params['title'];
$message['body'][] = $params['body'];
break;
Expand All @@ -34,17 +40,7 @@ function sympa_mail($key, &$message, $params) {
function sympa_entity_presave(EntityInterface $entity) {
$type = $entity->bundle();
if ((!$entity->isNew()) && ($entity->getEntityType()->id() == 'node') && ($type == 'news' || $type == 'service_alert')) {
$get_fields = $entity->getFields();
$sympa_send = $get_fields['field_sympa_send']->getValue();
if ($sympa_send[0]['value'] == 1) {
$sympa_body = $get_fields['body']->getValue();
$sympa_nid = $entity->id();
$sympa_title = Xss::filter($entity->gettitle());
sympa_build_email($type, $sympa_nid, $sympa_title, $sympa_body, 'sympa');
sympa_build_email($type, $sympa_nid, $sympa_title, $sympa_body, 'distribution_list');
// See if checked set to the default of 0 below.
$entity->set('field_sympa_send', 0);
}
sympa_node_email_send($entity);
}
}

Expand All @@ -54,18 +50,23 @@ function sympa_entity_presave(EntityInterface $entity) {
function sympa_node_insert(EntityInterface $entity) {
$type = $entity->bundle();
if ($type == 'news' || $type == 'service_alert') {
sympa_node_email_send($entity);
}
}

function sympa_node_email_send($entity) {
$type = $entity->bundle();
$get_fields = $entity->getFields();
$sympa_send = $get_fields['field_sympa_send']->getValue();
if ($sympa_send[0]['value'] == 1) {
$sympa_body = $get_fields['body']->getValue();
$sympa_nid = $entity->id();
$sympa_title = Xss::filter($entity->gettitle());
$sympa_title = $entity->get('field_service_alert_status')->getValue()[0]['value'] . ": " . $entity->gettitle();
sympa_build_email($type, $sympa_nid, $sympa_title, $sympa_body, 'sympa');
sympa_build_email($type, $sympa_nid, $sympa_title, $sympa_body, 'distribution_list');
// See if checked set to the default of 0 below.
$entity->set('field_sympa_send', 0);
}
}
}

/**
Expand Down

0 comments on commit e2604d7

Please sign in to comment.