Ich habs mal so in die Richtung versucht, aber so ist das noch sinnlos. Immer wenn ich die Seite lade werden an alle Mitglieder die Mails verschickt, ich will es aber nur onClick verschicken. Ich verstehe nur nicht wie ich da onClick eine PHP-Funktion im Backend aufrufe.
contao/dca/tl_member.php
PHP-Code:
<?php
use Contao\Image;
use Contao\StringUtil;
use Contao\System;
use Contao\CoreBundle\Security\ContaoCorePermissions;
$GLOBALS['TL_DCA']['tl_member']['list']['operations']['toggle']['button_callback'] = array('tl_member_sendmail', 'toggleIcon');
class tl_member_sendmail extends tl_member
{
public function toggleIcon($row, $href, $label, $title, $icon, $attributes)
{
// Check permissions AFTER checking the tid, so hacking attempts are logged
if (!System::getContainer()->get('security.helper')->isGranted(ContaoCorePermissions::USER_CAN_EDIT_FIELD_OF_TABLE, 'tl_user::disable'))
{
return '';
}
$href .= '&id=' . $row['id'];
if ($row['disable'])
{
$icon = 'invisible.svg';
$objNotification = \NotificationCenter\Model\Notification::findByPk('10');
} else {
$objNotification = \NotificationCenter\Model\Notification::findByPk('9');
}
if (null !== $objNotification) {
$objNotification->send(array());
}
// Protect admin accounts and own account
if ((!$this->User->isAdmin && $row['admin']) || $this->User->id == $row['id'])
{
return Image::getHtml($icon) . ' ';
}
return '<a href="' . $this->addToUrl($href) . '" title="' . StringUtil::specialchars($title) . '" onclick="Backend.getScrollOffset();return AjaxRequest.toggleField(this,true)">' . Image::getHtml($icon, $label, 'data-icon="' . Image::getPath('visible.svg') . '" data-icon-disabled="' . Image::getPath('invisible.svg') . '"data-state="' . ($row['disable'] ? 0 : 1) . '"') . '</a> ';
}
}
Lesezeichen