This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

lucas.sanner54070
lucas.sanner54070

I'm trying to extend/override the listInjectRowClass and listOverrideColumnValue methods from my plugin which extends the User plugin.
I've tried this in my Plugin.php file:

 public function boot()
 {
    ...

     Event::listen('backend.list.listInjectRowClass', function($record) {
         return 'safe disabled nolink';
     });

    ...
 }

but it doesn't work.
Is such extending possible ?

lucas.sanner54070
lucas.sanner54070

For those who are interested here's the solution:

 public function boot()
 {
    ...

     \RainLab\User\Controllers\Users::extend( function($controller) {
         Event::listen('backend.list.injectRowClass', function ($listWidget, $record, &$value) {
            $value .= 'safe disabled nolink';
         });

         Event::listen('backend.list.overrideColumnValueRaw', function ($listWidget, $record, $column, &$value) {
               $value .= '-modified';
         }); 

     });

    ...
 }

Hope it helps.

mjauvin
mjauvin

There is no need to extend the controller here, those are global events... it didn't work in your previous example because you had the wrong event name (backend.list.listInjectRowClass)

mjauvin
mjauvin

just this will work:

public function boot()
{
      Event::listen('backend.list.injectRowClass', function ($listWidget, $record, &$value) {
            $value .= 'safe disabled nolink';
      });
      ... 
} 
lucas.sanner54070
lucas.sanner54070

There is no need to extend the controller here
Actually it does or the $value will apply to the list of all the plugins.

Last updated

mjauvin
mjauvin

The event will trigger no matter what the list is. In order to handle the event for the right controller/model you need to check this within the handler.

mjauvin
mjauvin
if ($listWidget->getController() !== \RainLab\User\Controllers\Users) {
   return;
} 
lucas.sanner54070
lucas.sanner54070

Good to know. Thanks.

lucas.sanner54070
lucas.sanner54070

There were 2 errors in your code snippet. Here's the corrected version:

if (!$listWidget->getController() instanceof \RainLab\User\Controllers\Users) {  
    return;
}
Mennax
Mennax

lucas.sanner54070 said:

if (!$listWidget->getController() instanceof \RainLab\User\Controllers\Users) {
return; }

Thanks! This works for me.

Last updated

1-10 of 10

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.