Halting Execution Based on Events

Certain events will let you control whether further execution occurs within Concrete CMS. You can control this by setting properties within the event objects themselves. For example, check out the on_before_user_add event. This event fires when an add request occurs in Concrete, but before the user is actually added. You can halt the add process here.

The $event object in the example below is that of the Concrete\Core\User\Event\AddUser object.

Events::addListener('on_before_user_add', function($event) {
    $data = $event->getData();
    if ($data['uName'] == 'andrew') {
        // We don't want to allow any users named andrew.
        $event->cancelAdd();
    }
});

The AddUser event object has a cancelAdd() method, which sets an internal boolean named $proceed to false. This boolean is then checked within the Concrete core code prior to continuing. If it has been cancelled, the add operation will not continue.