Submitted by moezbelaiba on
Bonjour
Je suis débutant et j'ai un problème avec ce module qui envoie une notification lorsque la création d'une nouveaux type de contenue bulletin de soin ou bulletin d'incapacité !
<?php
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Entity\EntityInterface;
/**
* Implements hook_mail().
* @param $key
* @param $message
* @param $params
*/
function send_email_mail($key, & $message, $params)
{
$options = array(
'langcode' => $message['langcode'],
);
switch ($key) {
case 'send_email':
$message['from'] = \Drupal::config('system.site')->get('mail');
$message['subject'] = t('Node created: @title', array('@title' => $params['node_title']), $options);
break;
}
}
/**
* Implements hook_entity_insert().
* @param EntityInterface $entity
*/
function send_email_entity_insert(Drupal\Core\Entity\EntityInterface $entity)
{
if (($entity->getEntityTypeId() === 'node' && $entity->bundle() == 'disability_bulletin') || ($entity->getEntityTypeId() === 'node' && $entity->bundle() == 'care_bulletin')) {
$mailManager = \Drupal::service('plugin.manager.mail');
$module = 'send_email';
$key = 'node_insert';
$to = \Drupal::currentUser()->getEmail();
$params['node_title'] = $entity->label();
$langcode = \Drupal::currentUser()->getPreferredLangcode();
$send = true;
$result = $mailManager->mail($module, $key, $to, $langcode, $params,NULL, $send);
if ($result['result'] == true) {
$message = t('There was a problem sending your email notification to @email for creating node @id.', array('@email' => $to, '@id' => $entity->id()));
\Drupal::logger('send_email')->error($message);
return;
}
$message = t('An email notification has been sent to @email for creating node @id.', array('@email' => $to, '@id' => $entity->id()));
drupal_set_message($message);
\Drupal::logger('send_email')->notice($message);
}
}
Fichier attaché | Taille |
---|---|
capture_du_2019-08-20_151637.png | 108.83 Ko |