Add bulk action factory to be able to use custom classes for actions [MAILPOET-1922]
This commit is contained in:
@ -4,10 +4,14 @@ namespace MailPoet\Listing;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
|
||||
class BulkActionController {
|
||||
/** @var BulkActionFactory */
|
||||
private $factory;
|
||||
|
||||
/** @var Handler */
|
||||
private $handler;
|
||||
|
||||
function __construct(Handler $handler) {
|
||||
function __construct(BulkActionFactory $factory, Handler $handler) {
|
||||
$this->factory = $factory;
|
||||
$this->handler = $handler;
|
||||
}
|
||||
|
||||
@ -15,14 +19,10 @@ class BulkActionController {
|
||||
$bulk_action_method = 'bulk'.ucfirst($data['action']);
|
||||
unset($data['action']);
|
||||
|
||||
if (!method_exists($model_class, $bulk_action_method)) {
|
||||
throw new \Exception(
|
||||
$model_class. ' has no method "'.$bulk_action_method.'"'
|
||||
);
|
||||
}
|
||||
$action_class = $this->factory->getActionClass($model_class, $bulk_action_method);
|
||||
|
||||
return call_user_func_array(
|
||||
array($model_class, $bulk_action_method),
|
||||
array($action_class, $bulk_action_method),
|
||||
array($this->handler->getSelection($model_class, $data['listing']), $data)
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user