Override Action on Plugin


#1

Hi,

I have tried to override an action from a plugin but what I have done doesn’t work.

Here the code, i have tried on plugin.php file on initialize method:

...
use Kanboard\Plugin\TimeMachine\Action\SubtaskTimerMoveTaskColumn;
...
class Plugin extends Base
{
    public function initialize() {
        ...
        // Override SubTaskTimerMoveTaskColumn to create subTask with user connected (User who move card)
        $this->actionManager->register(new SubtaskTimerMoveTaskColumn($this->container));
        ...
    }
}
namespace Kanboard\Plugin\TimeMachine\Action;
...
class SubtaskTimerMoveTaskColumn extends \Kanboard\Action\SubtaskTimerMoveTaskColumn

Anyone have an idea to override an action from a plugin ?


#2

I’ve never had to do this, so I don’t know. Was hoping Fred was gonna answer you in the PR.

I’ll see if I can figure it out, when I get a chance.


#3

Thanks for you reply.

For know, I have a fork of the project (with the original git repository on upstream). And I have update the original file manually.

# Original file
Kanboard/app/Action/SubtaskTimerMoveTaskColumn.php

#4

Maybe someone else has a better understanding than me, but I don’t believe you can override the action.

Actions are registered and saved in the actions array, which is private, so there is no way to unset it, and I believe it saves it with namespace, so registering it with the same name won’t override it.

You can however, add it, separately. You’ll need more than just the doAction() though, and I’d recommend changing the description so that you can tell them apart.

This is why, I was hoping @fred was gonna answer it :slight_smile:

my only solution would be to add the ability to unset actions in the core, via a PR.