Skip to content

Commit f1b7548

Browse files
committed
Finalize mass actions
1 parent 52eb11a commit f1b7548

4 files changed

Lines changed: 43 additions & 13 deletions

File tree

Component/Grid/GridViewModel.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Loki\AdminComponents\Grid\Filter\Filter;
77
use Loki\AdminComponents\Grid\Filter\FilterFactory;
88
use Loki\AdminComponents\Grid\Filter\StaticFilterInterface;
9+
use Loki\AdminComponents\Grid\MassAction\MassActionFactory;
910
use Loki\AdminComponents\Grid\State\FilterState;
1011
use Magento\Framework\Data\OptionSourceInterface;
1112
use Magento\Framework\DataObject;
@@ -46,6 +47,7 @@ public function __construct(
4647
protected ButtonFactory $buttonFactory,
4748
protected FieldFactory $fieldFactory,
4849
protected FilterFactory $filterFactory,
50+
protected MassActionFactory $massActionFactory,
4951
) {
5052
}
5153

@@ -303,7 +305,23 @@ public function getButtons(): array
303305
*/
304306
public function getMassActions(): array
305307
{
306-
return (array)$this->getBlock()->getMassActions();
308+
$massActions = [];
309+
foreach ((array)$this->getBlock()->getMassActions() as $massActionId => $massAction) {
310+
if ($massAction instanceof MassActionInterface) {
311+
$massActions[$massActionId] = $massAction;
312+
continue;
313+
}
314+
315+
if (is_array($massAction)) {
316+
$massActions[$massActionId] = $this->massActionFactory->create(
317+
$massAction['label'],
318+
$massAction['url'],
319+
isset($massAction['url_parameters']) ? $massAction['url_parameters'] : [],
320+
);
321+
}
322+
}
323+
324+
return $massActions;
307325
}
308326

309327
public function getRowAction(DataObject $item): CellAction

Grid/MassAction/EnableMassAction.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

Grid/MassAction/MassAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ public function getUrl(): string
2626

2727
protected function getUrlParameters(): array
2828
{
29-
return $this->getUrlParameters();
29+
return $this->urlParameters;
3030
}
3131
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Loki\AdminComponents\Grid\MassAction;
4+
5+
use Magento\Framework\ObjectManagerInterface;
6+
7+
class MassActionFactory
8+
{
9+
public function __construct(
10+
private ObjectManagerInterface $objectManager
11+
) {
12+
}
13+
14+
15+
public function create(string $label, string $url, array $urlParameters = []): MassActionInterface
16+
{
17+
return $this->objectManager->create(MassAction::class, [
18+
'label' => $label,
19+
'url' => $url,
20+
'urlParameters' => $urlParameters,
21+
]);
22+
}
23+
}

0 commit comments

Comments
 (0)