Skip to Main Content
Drupal 8 Module Development - Second Edition
book

Drupal 8 Module Development - Second Edition

by Daniel Sipos
March 2019
Intermediate to advanced content levelIntermediate to advanced
580 pages
15h 3m
English
Packt Publishing
Content preview from Drupal 8 Module Development - Second Edition

Sending emails

We wanted to use our MailLogger to send out an email whenever we are logging an error. So let's go back to our class and add this logic.

This is what our log() method can look like now:

/** * {@inheritdoc} */public function log($level, $message, array $context = array()) {  if ($level !== RfcLogLevel::ERROR) {    return;  }  $to = $this->configFactory->get('system.site')->get('mail');  $langcode = $this->configFactory->get('system.site')->get('langcode');  $variables = $this->parser->parseMessagePlaceholders($message, $context);  $markup = new FormattableMarkup($message, $variables);  \Drupal::service('plugin.manager.mail')->mail('hello_world', 'hello_world_log', $to, $langcode, ['message' => $markup]);}

First of all, we said that we ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Drupal 8 Module Development

Drupal 8 Module Development

Daniel Sipos
Learning Drupal 8

Learning Drupal 8

Rain Michaels
Mastering Drupal 8

Mastering Drupal 8

Chaz Chumley, William Hurley

Publisher Resources

ISBN: 9781789612363Supplemental Content