Skip to content

Commit 62fdf9b

Browse files
committed
Implement form with save and delete functionality for the Asynchronous Event Subscriber entity
1 parent a8be822 commit 62fdf9b

29 files changed

+88
-867
lines changed

Api/Data/AsyncEventInterface.php

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

Block/Form/AsyncEvent/Back.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ class Back extends GenericButton implements ButtonProviderInterface
1212
{
1313
/**
1414
* Retrieve Back To Grid button settings.
15-
*
16-
* @return array
1715
*/
1816
public function getButtonData(): array
1917
{

Block/Form/AsyncEvent/Delete.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ class Delete extends GenericButton implements ButtonProviderInterface
1313
{
1414
/**
1515
* Retrieve Delete button settings.
16-
*
17-
* @return array
1816
*/
1917
public function getButtonData(): array
2018
{
@@ -25,11 +23,12 @@ public function getButtonData(): array
2523
return $this->wrapButtonSettings(
2624
__('Delete')->getText(),
2725
'delete',
28-
sprintf("deleteConfirm('%s', '%s')",
29-
__('Are you sure you want to delete this asyncevent?'),
26+
sprintf(
27+
"deleteConfirm('%s', '%s')",
28+
__('Are you sure you want to delete this Asynchronous Event Subscriber?'),
3029
$this->getUrl(
3130
'*/*/delete',
32-
[AsyncEventInterface::SUBSCRIPTION_ID => $this->getSubscriptionId()]
31+
['subscription_id' => $this->getSubscriptionId()]
3332
)
3433
),
3534
[],

Block/Form/AsyncEvent/GenericButton.php

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,39 @@
33

44
namespace MageOS\AsyncEventsAdminUi\Block\Form\AsyncEvent;
55

6-
use MageOS\AsyncEventsAdminUi\Api\Data\AsyncEventInterface;
76
use Magento\Backend\Block\Widget\Context;
87
use Magento\Framework\UrlInterface;
98

109
/**
11-
* Generic (form) button for AsyncEvent entity.
10+
* Generic (form) button for Asynchronous Event Subscriber entity.
1211
*/
1312
class GenericButton
1413
{
15-
/**
16-
* @var Context
17-
*/
1814
private Context $context;
19-
20-
/**
21-
* @var UrlInterface
22-
*/
2315
private UrlInterface $urlBuilder;
2416

25-
/**
26-
* @param Context $context
27-
*/
2817
public function __construct(
2918
Context $context
30-
)
31-
{
19+
) {
3220
$this->context = $context;
3321
$this->urlBuilder = $context->getUrlBuilder();
3422
}
3523

36-
/**
37-
* Get AsyncEvent entity id.
38-
*
39-
* @return int
40-
*/
4124
public function getSubscriptionId(): int
4225
{
43-
return (int)$this->context->getRequest()->getParam(AsyncEventInterface::SUBSCRIPTION_ID);
26+
return (int)$this->context->getRequest()->getParam('subscription_id');
4427
}
4528

4629
/**
47-
* Wrap button specific options to settings array.
48-
*
49-
* @param string $label
50-
* @param string $class
51-
* @param string $onclick
52-
* @param array $dataAttribute
53-
* @param int $sortOrder
54-
*
55-
* @return array
30+
* Wrap button specific options to settings array
5631
*/
5732
protected function wrapButtonSettings(
5833
string $label,
5934
string $class,
6035
string $onclick = '',
6136
array $dataAttribute = [],
6237
int $sortOrder = 0
63-
): array
64-
{
38+
): array {
6539
return [
6640
'label' => $label,
6741
'on_click' => $onclick,
@@ -71,14 +45,6 @@ protected function wrapButtonSettings(
7145
];
7246
}
7347

74-
/**
75-
* Get url.
76-
*
77-
* @param string $route
78-
* @param array $params
79-
*
80-
* @return string
81-
*/
8248
protected function getUrl(string $route, array $params = []): string
8349
{
8450
return $this->urlBuilder->getUrl($route, $params);

Block/Form/AsyncEvent/Save.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ class Save extends GenericButton implements ButtonProviderInterface
1212
{
1313
/**
1414
* Retrieve Save button settings.
15-
*
16-
* @return array
1715
*/
1816
public function getButtonData(): array
1917
{

Command/AsyncEvent/DeleteByIdCommand.php

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
namespace MageOS\AsyncEventsAdminUi\Command\AsyncEvent;
55

66
use Exception;
7-
use MageOS\AsyncEventsAdminUi\Api\Data\AsyncEventInterface;
8-
use MageOS\AsyncEventsAdminUi\Model\AsyncEventModel;
9-
use MageOS\AsyncEventsAdminUi\Model\AsyncEventModelFactory;
10-
use MageOS\AsyncEventsAdminUi\Model\ResourceModel\AsyncEventResource;
7+
use MageOS\AsyncEvents\Model\AsyncEvent as AsyncEventModel;
8+
use MageOS\AsyncEvents\Model\AsyncEventFactory as AsyncEventModelFactory;
9+
use MageOS\AsyncEvents\Model\ResourceModel\AsyncEvent as AsyncEventResource;
1110
use Magento\Framework\Exception\CouldNotDeleteException;
1211
use Magento\Framework\Exception\NoSuchEntityException;
1312
use Psr\Log\LoggerInterface;
@@ -17,32 +16,15 @@
1716
*/
1817
class DeleteByIdCommand
1918
{
20-
/**
21-
* @var LoggerInterface
22-
*/
2319
private LoggerInterface $logger;
24-
25-
/**
26-
* @var AsyncEventModelFactory
27-
*/
2820
private AsyncEventModelFactory $modelFactory;
29-
30-
/**
31-
* @var AsyncEventResource
32-
*/
3321
private AsyncEventResource $resource;
3422

35-
/**
36-
* @param LoggerInterface $logger
37-
* @param AsyncEventModelFactory $modelFactory
38-
* @param AsyncEventResource $resource
39-
*/
4023
public function __construct(
4124
LoggerInterface $logger,
4225
AsyncEventModelFactory $modelFactory,
4326
AsyncEventResource $resource
44-
)
45-
{
27+
) {
4628
$this->logger = $logger;
4729
$this->modelFactory = $modelFactory;
4830
$this->resource = $resource;
@@ -51,23 +33,21 @@ public function __construct(
5133
/**
5234
* Delete AsyncEvent.
5335
*
54-
* @param int $entityId
55-
*
56-
* @return void
5736
* @throws CouldNotDeleteException
5837
*/
5938
public function execute(int $entityId): void
6039
{
6140
try {
6241
/** @var AsyncEventModel $model */
6342
$model = $this->modelFactory->create();
64-
$this->resource->load($model, $entityId, AsyncEventInterface::SUBSCRIPTION_ID);
43+
$this->resource->load($model, $entityId);
6544

66-
if (!$model->getData(AsyncEventInterface::SUBSCRIPTION_ID)) {
45+
if (!$model->getSubscriptionId()) {
6746
throw new NoSuchEntityException(
68-
__('Could not find AsyncEvent with id: `%id`',
47+
__(
48+
'Could not find Asynchronous Event Subscriber with id: `%subscription_id`',
6949
[
70-
'id' => $entityId
50+
'subscription_id' => $entityId
7151
]
7252
)
7353
);
@@ -76,13 +56,13 @@ public function execute(int $entityId): void
7656
$this->resource->delete($model);
7757
} catch (Exception $exception) {
7858
$this->logger->error(
79-
__('Could not delete AsyncEvent. Original message: {message}'),
59+
__('Could not delete Asynchronous Event Subscriber. Original message: {message}'),
8060
[
8161
'message' => $exception->getMessage(),
8262
'exception' => $exception
8363
]
8464
);
85-
throw new CouldNotDeleteException(__('Could not delete AsyncEvent.'));
65+
throw new CouldNotDeleteException(__('Could not delete Asynchronous Event Subscriber.'));
8666
}
8767
}
8868
}

0 commit comments

Comments
 (0)