22
33namespace Drupal \os2loop_mail_notifications \Plugin \Mail ;
44
5+ use Drupal \Component \Utility \Html ;
56use Drupal \Core \Mail \MailInterface ;
67use Drupal \Core \Mail \Plugin \Mail \PhpMail as PhpMailBase ;
7- use Drupal \Core \Url ;
88
99/**
1010 * Copy of the default Drupal mail backend, using PHP's native mail() function.
@@ -29,7 +29,7 @@ class PhpMail extends PhpMailBase implements MailInterface {
2929 public function format (array $ message ) {
3030 $ message ['body ' ] = implode (PHP_EOL . PHP_EOL , $ message ['body ' ]);
3131 $ message ['body ' ] = nl2br ($ message ['body ' ]);
32- $ message ['body ' ] = $ this -> makeUrlsAbsolute ($ message ['body ' ]);
32+ $ message ['body ' ] = Html:: transformRootRelativeUrlsToAbsolute ($ message ['body ' ], \Drupal:: request ()-> getSchemeAndHttpHost () );
3333
3434 return $ message ;
3535 }
@@ -51,29 +51,4 @@ public function mail(array $message) {
5151 return parent ::mail ($ message );
5252 }
5353
54- /**
55- * Convert relative urls (paths) in html to absolute urls.
56- */
57- private function makeUrlsAbsolute (string $ html ) {
58- return preg_replace_callback (
59- '/\s(href|src)\s*=\s*(?: \'([^ \']+) \'|"([^"]+)")/ ' ,
60- static function ($ matches ) {
61- $ name = $ matches [1 ];
62- $ value = $ matches [2 ] ?: $ matches [3 ];
63- $ scheme = parse_url ($ value , PHP_URL_SCHEME );
64- if (NULL === $ scheme ) {
65- // We have a local path.
66- try {
67- $ value = Url::fromUri ('internal:/ ' . ltrim ($ value , '/ ' ), ['absolute ' => TRUE ])->toString ();
68- }
69- catch (\InvalidArgumentException $ exception ) {
70- }
71- }
72-
73- return sprintf (' %s="%s" ' , $ name , htmlspecialchars ($ value ));
74- },
75- $ html
76- );
77- }
78-
7954}
0 commit comments