This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
In my plugin I need to extend the update function of the User plugin. This is what I've tried so far:
public function boot()
{
\RainLab\User\Controllers\Users::extend( function($controller) {
$controller->addDynamicMethod('update', function($recordId = null, $context = null) use ($controller) {
// do stuff
return $controller->asExtension('FormController')->update($recordId, $context);
});
});
}
But it doesn't work. The function is not called when an admin enters the update form on backend.
Can someone helps me ?
Last updated
This won't work since the method already exists in the class hierarchy.
What exactly are you trying to do?
Look at using a handler for the model.beforeUpdate
event maybe?
Actually, looking at the source code, addDynamicMethod() can add a new method even if one already exists with the same name, but the behavior is uncertain. I confused with addDynamicProperty()
Last updated
What exactly are you trying to do?
Well, actually what I'd like to do is to check some data when an admin
clicks on the Update button then, according to the data, let the admin edit the user form as usual or redirect him to the user list.
The model.beforeUpdate event won't work in this case as the admin is already in the user form.
I was thinking about using routes but I'm not sure it's the proper way to do it.
Any suggestions ?
You should be able to use the page.beforeDisplay
event to do what you want.
ref. https://octobercms.com/docs/api/backend/page/beforedisplay
Event::listen('backend.page.beforeDisplay', function ($controller, $action, $params) {
if (! ($controller instanceof 'RainLab\User\Controllers\Users' && $action === 'update') {
return;
}
$user_id = $params['id'];
$model = $controller->formFindModelObject($user_id);
[do verifications with model]
});
1-12 of 12