Skip to content

Commit f14103d

Browse files
authored
Add view events to extend user preview and listing toolbars (#455)
Added view extension events that can be used to extend the toolbars on the user listing and preview page. This supersedes PR#391.
1 parent 3225543 commit f14103d

4 files changed

Lines changed: 43 additions & 4 deletions

File tree

Plugin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function register()
3434
$alias = AliasLoader::getInstance();
3535
$alias->alias('Auth', 'RainLab\User\Facades\Auth');
3636

37-
App::singleton('user.auth', function() {
37+
App::singleton('user.auth', function () {
3838
return \RainLab\User\Classes\AuthManager::instance();
3939
});
4040

@@ -56,7 +56,7 @@ public function register()
5656
/*
5757
* Apply user-based mail blocking
5858
*/
59-
Event::listen('mailer.prepareSend', function($mailer, $view, $message) {
59+
Event::listen('mailer.prepareSend', function ($mailer, $view, $message) {
6060
return MailBlocker::filterMessage($view, $message);
6161
});
6262

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

187-
Notifier::instance()->registerCallback(function($manager) {
187+
Notifier::instance()->registerCallback(function ($manager) {
188188
$manager->registerGlobalParams([
189189
'user' => Auth::getUser()
190190
]);

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ This plugin makes use of October's [`Flash API`](http://octobercms.com/docs/mark
164164
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:
165165

166166
<script>
167-
$(window).on('ajaxErrorMessage', function(event, message){
167+
$(window).on('ajaxErrorMessage', function (event, message){
168168

169169
// This can be any custom JavaScript you want
170170
alert('Something bad happened, mate, here it is: ' + message);
@@ -310,6 +310,8 @@ This plugin will fire some global events that can be useful for interacting with
310310
- **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.
311311
- **rainlab.user.reactivate**: The user has reactivated their own account by signing back in. This should revive the users content on the site.
312312
- **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.
313+
- **rainlab.user.view.extendListToolbar**: Fires when the user listing page's toolbar is rendered.
314+
- **rainlab.user.view.extendPreviewToolbar**: Fires when the user preview page's toolbar is rendered.
313315

314316
Here is an example of hooking an event:
315317

controllers/users/_list_toolbar.htm

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,21 @@
6464
</ul>
6565
</div>
6666

67+
<?=
68+
/**
69+
* @event rainlab.user.view.extendListToolbar
70+
* Fires when user list toolbar is rendered.
71+
*
72+
* Example usage:
73+
*
74+
* Event::listen('rainlab.user.view.extendListToolbar', function (
75+
* (RainLab\User\Controllers\Users) $controller
76+
* ) {
77+
* return $controller->makePartial('~/path/to/partial');
78+
* });
79+
*
80+
*/
81+
$this->fireViewEvent('rainlab.user.view.extendListToolbar');
82+
?>
83+
6784
</div>

controllers/users/_preview_toolbar.htm

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,23 @@
4949
</div>
5050
*/
5151
?>
52+
53+
<?=
54+
/**
55+
* @event rainlab.user.view.extendPreviewToolbar
56+
* Fires when preview user toolbar is rendered.
57+
*
58+
* Example usage:
59+
*
60+
* Event::listen('rainlab.user.view.extendPreviewToolbar', function (
61+
* (RainLab\User\Controllers\Users) $controller,
62+
* (RainLab\User\Models\User) $record
63+
* ) {
64+
* return $controller->makePartial('~/path/to/partial');
65+
* });
66+
*
67+
*/
68+
$this->fireViewEvent('rainlab.user.view.extendPreviewToolbar', [
69+
'record' => $formModel
70+
]);
71+
?>

0 commit comments

Comments
 (0)