Unter contao 4.10 habe ich das Thema für mich gelöst durch einen einfachen Hook - mittlerweile muss man dazu nur noch eine Datei erstellen - mehr nicht!
Für den Vergleich nutze ich die Contao Version Klasse. Das meiste in dem Code ist der Versuch, ein Styling hinzubekommen - funktioniert aber nicht wirklich.
PHP-Code:
<?php
// src/EventListener/UpdatePersonalDataListener.php
namespace App\EventListener;
use Contao\CoreBundle\ServiceAnnotation\Hook;
use Contao\Module;
use Contao\FrontendUser;
use Contao\Email;
use Contao\Versions;
/**
* @Hook("updatePersonalData")
*/
class UpdatePersonalDataListener
{
public function __invoke(FrontendUser $member, array $data, Module $module): void
{
//Objekt für den Versionsvergleich
$strTable = $member->getTable();
$objVersions = new Versions($strTable, $member->id);
//Verschicken einer Email:
//Allgemeine Vorbereitung
$objEmail = new Email();
$objEmail->from = $GLOBALS['TL_ADMIN_EMAIL'];
$objEmail->fromName = 'Contao mailer';
//Betreff
$objEmail->subject = "Änderung Mitglied Nr. " . $member->id . " (" . implode(', ', $member->groups) . ")";
//Text - Einleitung
$strText = "<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>" . $objEmail->subject . "</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<style type="text/css">
#outlook a{padding:0;} /* Force Outlook to provide a "view in browser" message */
.ReadMsgBody{width:100%;} .ExternalClass{width:100%;} /* Force Hotmail to display emails at full width */
.ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div {line-height: 100%;} /* Force Hotmail to display normal line spacing */
body, table, td, a{-webkit-text-size-adjust:100%; -ms-text-size-adjust:100%;} /* Prevent WebKit and Windows mobile changing default text sizes */
table, td{mso-table-lspace:0pt; mso-table-rspace:0pt;} /* Remove spacing between tables in Outlook 2007 and up */
img{-ms-interpolation-mode:bicubic;} /* Allow smoother rendering of resized image in Internet Explorer */
body {
background:#fff;
padding:12px;
}
/* Elements */
h2 {
margin:0;
padding:4px 6px;
background:#eee;
border-bottom:1px solid #ddd;
font-size:.875rem;
}
.formbody {
margin:12px 0 18px;
text-align:right;
}
.formbody .tl_select {
width:42%;
max-width:280px;
}
.formbody .tl_submit {
padding-top:5px;
padding-bottom:6px;
}
.formbody .arrow {
vertical-align:middle;
}
.formbody .static-version {
margin-right:3px;
}
.tl_info {
padding:6px 6px 6px 28px;
border-radius:2px;
color:#006494;
line-height:1.2;
}
#diff .change {
margin-bottom:1em;
border:1px solid #ddd;
background:#fcfcfc;
border-radius:2px;
}
#diff .replace.left,#diff .delete.left {
background: #fdd;
}
#diff .replace.right,#diff .insert.right {
background: #dfd;
}
#diff .replace ins {
color:#060;
background: #bfb;
}
#diff .replace del {
color:#a00;
background: #fbb;
}
#diff ins,#diff del {
text-decoration: none;
}
#diff dl {
margin:0;
padding:0;
font:.75rem "Roboto Mono",monospace;
}
#diff dt,#diff dd {
margin:0;
padding:0 6px;
line-height:1.25;
}
#diff dl dt:first-of-type,#diff dl dd:first-of-type {
padding-top:3px;
}
#diff dl dt:last-of-type,#diff dl dd:last-of-type {
padding-bottom:3px;
}
</style>
</head>
<body style="margin: 0; padding: 0;" dir="ltr">";
$strText .= "<p>Guten Tag, <br><br>" .
"einige Informationen zu Mitglied " . $member->id. " (" . $member->lastname . ", " . $member->firstname . ") haben sich geändert.<br>" .
"Im Folgenden finden Sie die aktuellen Daten: </p>";
//Tabelle mit aktuellen Daten:
$strText .= "<table cellpadding="2" cellspacing="2" border="0" bordercolor="white" width="100%">";
foreach($data as $key => $value){
$strText .= "<tr><td bgcolor="#f4f4f4"><b>" . $GLOBALS['TL_DCA']['tl_member']['fields'][$key]['label'][0] ."</b></td><td> ".$value ."</td></tr>\n";
}
$strText .= "</table><br><br>";
//Contao Compare ausgeben
$strText .= "<p>Die letzten Änderungen sind hier beschrieben: </p>";
$strText .= "<div id="diff">" . $objVersions->compare(true) . "</div>";
//Grußformel
$strText .= "<p>Viele Grüße,<br><b>Webmaster</b></p></body></html>";
//Verschicken der Email
$objEmail->html = $strText;
$objEmail->sendTo($GLOBALS['TL_ADMIN_EMAIL']);
$_SESSION['TL_EMAIL_SENT'] = true;
}
}
Lesezeichen