Before Delete
public function onBeforeDelete{$type}( array $ids, JTable $table ) : bool
Fires before deleting a record.
Description
Trigger hook to allow the plugins to make something before deleting one or more records from the database.
The dynamic portion of the hook name, $type, refers to the name of the table calling the hook. This means that, for example, the room table will trigger an hook called onBeforeDeleteRoom. The name of the table is always equals to the base name of the file that declares the $table instance.
It is possible to read a list of supported types by looking at the files stored within the following directory:
/administrator/components/com_vikrestaurants/tables/
TIP: in order to prevent the system from deleting the records, it is possible to throw an exception to abort the cancellation process and return a readable error message. The same can be accomplished by registering an error to the table and returning false.
// throw an exception
throw new Exception('You are not allowed to delete this record', 403);
// or register the error
$table->setError('You are not allowed to delete this record');
return false;
Parameters
- $ids
-
(array) An array of IDs to delete.
- $table
-
(JTable) The table instance that handles the cancellation process.
Return Value
Boolean. Use false to abort the cancellation process.
Example
/**
* Trigger hook to allow the plugins to make something before deleting
* one or more records from the database.
*
* @param array $ids An array of IDs to delete.
* @param JTable $table The table instance.
*
* @return bool False to abort the cancellation process.
*/
public function onBeforeDeleteReservation($ids, $table)
{
/**
* @todo it is possible to apply further conditions here
*/
return true;
}
Changelog
| Version | Description |
|---|---|
| 1.9 | Introduced. |