namespace Drupal\Core\Mail;
+use Drupal\Component\Render\MarkupInterface;
use Drupal\Component\Render\PlainTextOutput;
+use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
+use Drupal\Core\Messenger\MessengerTrait;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
+use Drupal\Core\Render\Markup;
use Drupal\Core\Render\RenderContext;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
*/
class MailManager extends DefaultPluginManager implements MailManagerInterface {
+ use MessengerTrait;
use StringTranslationTrait;
/**
// Retrieve the responsible implementation for this message.
$system = $this->getInstance(['module' => $module, 'key' => $key]);
+ // Attempt to convert relative URLs to absolute.
+ foreach ($message['body'] as &$body_part) {
+ if ($body_part instanceof MarkupInterface) {
+ $body_part = Markup::create(Html::transformRootRelativeUrlsToAbsolute((string) $body_part, \Drupal::request()->getSchemeAndHttpHost()));
+ }
+ }
+
// Format the message body.
$message = $system->format($message);
'%to' => $message['to'],
'%reply' => $message['reply-to'] ? $message['reply-to'] : $this->t('not set'),
]);
- drupal_set_message($this->t('Unable to send email. Contact the site administrator if the problem persists.'), 'error');
+ $this->messenger()->addError($this->t('Unable to send email. Contact the site administrator if the problem persists.'));
}
}
}