Skip to content

Commit

Permalink
Add view events to extend user preview and listing toolbars (#455)
Browse files Browse the repository at this point in the history
Added view extension events that can be used to extend the toolbars on the user listing and preview page. This supersedes PR#391.
  • Loading branch information
mohsin authored Oct 7, 2020
1 parent 3225543 commit f14103d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function register()
$alias = AliasLoader::getInstance();
$alias->alias('Auth', 'RainLab\User\Facades\Auth');

App::singleton('user.auth', function() {
App::singleton('user.auth', function () {
return \RainLab\User\Classes\AuthManager::instance();
});

Expand All @@ -56,7 +56,7 @@ public function register()
/*
* Apply user-based mail blocking
*/
Event::listen('mailer.prepareSend', function($mailer, $view, $message) {
Event::listen('mailer.prepareSend', function ($mailer, $view, $message) {
return MailBlocker::filterMessage($view, $message);
});

Expand Down Expand Up @@ -184,7 +184,7 @@ protected function bindNotificationEvents()
'rainlab.user.register' => \RainLab\User\NotifyRules\UserRegisteredEvent::class
]);

Notifier::instance()->registerCallback(function($manager) {
Notifier::instance()->registerCallback(function ($manager) {
$manager->registerGlobalParams([
'user' => Auth::getUser()
]);
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ This plugin makes use of October's [`Flash API`](http://octobercms.com/docs/mark
The User plugin displays AJAX error messages in a simple ``alert()``-box by default. However, this might scare non-technical users. You can change the default behavior of an AJAX error from displaying an ``alert()`` message, like this:

<script>
$(window).on('ajaxErrorMessage', function(event, message){
$(window).on('ajaxErrorMessage', function (event, message){

// This can be any custom JavaScript you want
alert('Something bad happened, mate, here it is: ' + message);
Expand Down Expand Up @@ -310,6 +310,8 @@ This plugin will fire some global events that can be useful for interacting with
- **rainlab.user.deactivate**: The user has opted-out of the site by deactivating their account. This should be used to disable any content the user may want removed.
- **rainlab.user.reactivate**: The user has reactivated their own account by signing back in. This should revive the users content on the site.
- **rainlab.user.getNotificationVars**: Fires when sending a user notification to enable passing more variables to the email templates. Passes the `$user` model the template will be for.
- **rainlab.user.view.extendListToolbar**: Fires when the user listing page's toolbar is rendered.
- **rainlab.user.view.extendPreviewToolbar**: Fires when the user preview page's toolbar is rendered.

Here is an example of hooking an event:

Expand Down
17 changes: 17 additions & 0 deletions controllers/users/_list_toolbar.htm
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,21 @@
</ul>
</div>

<?=
/**
* @event rainlab.user.view.extendListToolbar
* Fires when user list toolbar is rendered.
*
* Example usage:
*
* Event::listen('rainlab.user.view.extendListToolbar', function (
* (RainLab\User\Controllers\Users) $controller
* ) {
* return $controller->makePartial('~/path/to/partial');
* });
*
*/
$this->fireViewEvent('rainlab.user.view.extendListToolbar');
?>

</div>
20 changes: 20 additions & 0 deletions controllers/users/_preview_toolbar.htm
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,23 @@
</div>
*/
?>

<?=
/**
* @event rainlab.user.view.extendPreviewToolbar
* Fires when preview user toolbar is rendered.
*
* Example usage:
*
* Event::listen('rainlab.user.view.extendPreviewToolbar', function (
* (RainLab\User\Controllers\Users) $controller,
* (RainLab\User\Models\User) $record
* ) {
* return $controller->makePartial('~/path/to/partial');
* });
*
*/
$this->fireViewEvent('rainlab.user.view.extendPreviewToolbar', [
'record' => $formModel
]);
?>

0 comments on commit f14103d

Please sign in to comment.