Documentation

OnBeforeEventMessageDelete

bool
handler function(
 int template_id
);
The event OnBeforeEventMessageDelete fires before mail template is deleted. Usually, the purpose of this event handler is to allow or deny mail template deletion.

Parameters

ParameterDescription
template_id ID of the template to be deleted.

Returned value

To cancel user deletion and terminate the CEventMessage::Delete method execution, throw an exception in the handler function via the method$APPLICATION->ThrowException() and return false.

See Also

Example of handler function:

<?
// file /bitrix/modules/my_module_id/include.php
class MyClass
{
    // create the event handler "OnBeforeEventMessageDelete"
    function OnBeforeEventMessageDeleteHandler($template_id)
    {
        // check if records, associated with the deleted template are available 
        $strSql = "SEL ECT * FR OM my_table WHERE EMAIL_TEMPLATE_ID=".intval($template_id);
        $rs = $DB->Query($strSql, false, "FILE: ".__FILE__."<br>LINE: ".__LINE__);

        // if associated records are available
        if ($ar = $rs->Fetch()) 
        {
            // deny the mail template deletion 
            global $APPLICATION;
            $APPLICATION->throwException("My table has the associated records.");
            return false;
        }
    }
}
?>

Example of handler function registration:

<?
// register the event handler "OnBeforeEventMessageDelete"
RegisterModuleDependences("main", "OnBeforeEventMessageDelete", 
             "my_module_id", "MyClass", "OnBeforeEventMessageDeleteHandler");
?>


© «Bitrix24», 2001-2022
Up