Skip to content

Commit e1ace4b

Browse files
committed
Add dropdowns to subscription form
1 parent 8d8aba4 commit e1ace4b

File tree

6 files changed

+160
-11
lines changed

6 files changed

+160
-11
lines changed

Model/Config.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace MageOS\AsyncEventsAdminUi\Model;
5+
6+
use Magento\Framework\Config\DataInterface;
7+
8+
class Config
9+
{
10+
private DataInterface $dataStorage;
11+
12+
public function __construct(
13+
DataInterface $dataStorage
14+
) {
15+
$this->dataStorage = $dataStorage;
16+
}
17+
18+
/**
19+
* Retrieve the content of all async_events.xml files
20+
*/
21+
public function get(?string $key = null): array
22+
{
23+
return $this->dataStorage->get($key, []);
24+
}
25+
}

Ui/Source/EventNames.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace MageOS\AsyncEventsAdminUi\Ui\Source;
5+
6+
use MageOS\AsyncEventsAdminUi\Model\Config;
7+
8+
class EventNames implements \Magento\Framework\Option\ArrayInterface
9+
{
10+
private Config $config;
11+
12+
public function __construct(
13+
Config $config
14+
) {
15+
$this->config = $config;
16+
}
17+
18+
public function toOptionArray()
19+
{
20+
$asyncEvents = array_keys($this->config->get());
21+
sort($asyncEvents);
22+
return array_map(
23+
function (string $eventName): array {
24+
return [
25+
'value' => $eventName,
26+
'label' => $eventName,
27+
];
28+
},
29+
$asyncEvents
30+
);
31+
}
32+
}

Ui/Source/Notifiers.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace MageOS\AsyncEventsAdminUi\Ui\Source;
5+
6+
class Notifiers implements \Magento\Framework\Option\ArrayInterface
7+
{
8+
/**
9+
* Options are hard coded since this module only support HTTP
10+
*
11+
* @return array[]
12+
*/
13+
public function toOptionArray()
14+
{
15+
return [
16+
[
17+
'value' => 'http',
18+
'label' => 'HTTP',
19+
]
20+
];
21+
}
22+
}

Ui/Source/Stores.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace MageOS\AsyncEventsAdminUi\Ui\Source;
5+
6+
use Magento\Store\Api\Data\StoreInterface;
7+
use Magento\Store\Model\StoreManagerInterface;
8+
9+
class Stores implements \Magento\Framework\Option\ArrayInterface
10+
{
11+
private StoreManagerInterface $storeManager;
12+
13+
public function __construct(
14+
StoreManagerInterface $storeManager
15+
) {
16+
$this->storeManager = $storeManager;
17+
}
18+
19+
public function toOptionArray()
20+
{
21+
$stores = $this->storeManager->getStores();
22+
$options = array_map(
23+
function (StoreInterface $store): array {
24+
return [
25+
'value' => $store->getId(),
26+
'label' => $store->getName(),
27+
];
28+
},
29+
$stores
30+
);
31+
array_unshift($options, ['value' => '0', 'label' => __('All Stores')]);
32+
return $options;
33+
}
34+
}

etc/adminhtml/di.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
4+
<type name="MageOS\AsyncEventsAdminUi\Model\Config">
5+
<arguments>
6+
<argument name="dataStorage" xsi:type="object">asyncEventDataStorage</argument>
7+
</arguments>
8+
</type>
9+
</config>

view/adminhtml/ui_component/async_events_events_form.xml

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,23 @@
4848
<dataScope>subscription_id</dataScope>
4949
</settings>
5050
</field>
51-
<field name="event_name" sortOrder="00" formElement="input">
52-
<argument name="data" xsi:type="array">
53-
<item name="config" xsi:type="array">
54-
<item name="source" xsi:type="string">event_name</item>
55-
</item>
56-
</argument>
51+
<field name="event_name" sortOrder="0" formElement="select">
5752
<settings>
58-
<dataType>string</dataType>
59-
<label translate="true">Event Name</label>
53+
<validation>
54+
<rule name="required-entry" xsi:type="boolean">true</rule>
55+
</validation>
56+
<showFallbackReset>false</showFallbackReset>
57+
<dataType>text</dataType>
58+
<label>Event Name</label>
6059
<dataScope>event_name</dataScope>
6160
</settings>
61+
<formElements>
62+
<select>
63+
<settings>
64+
<options class="MageOS\AsyncEventsAdminUi\Ui\Source\EventNames"/>
65+
</settings>
66+
</select>
67+
</formElements>
6268
</field>
6369
<field name="recipient_url" sortOrder="10" formElement="input">
6470
<argument name="data" xsi:type="array">
@@ -67,15 +73,19 @@
6773
</item>
6874
</argument>
6975
<settings>
76+
<validation>
77+
<rule name="required-entry" xsi:type="boolean">true</rule>
78+
</validation>
7079
<dataType>string</dataType>
71-
<label translate="true">Recipient Url</label>
80+
<label translate="true">Recipient URL</label>
7281
<dataScope>recipient_url</dataScope>
7382
</settings>
7483
</field>
7584
<field name="status" sortOrder="30" formElement="checkbox">
7685
<argument name="data" xsi:type="array">
7786
<item name="config" xsi:type="array">
7887
<item name="source" xsi:type="string">status</item>
88+
<item name="default" xsi:type="number">1</item>
7989
</item>
8090
</argument>
8191
<settings>
@@ -95,19 +105,29 @@
95105
</checkbox>
96106
</formElements>
97107
</field>
98-
<field name="metadata" sortOrder="40" formElement="input">
108+
<field name="metadata" sortOrder="40" formElement="select">
99109
<argument name="data" xsi:type="array">
100110
<item name="config" xsi:type="array">
101111
<item name="source" xsi:type="string">metadata</item>
102112
</item>
103113
</argument>
104114
<settings>
115+
<validation>
116+
<rule name="required-entry" xsi:type="boolean">true</rule>
117+
</validation>
105118
<dataType>string</dataType>
106119
<label translate="true">Notifier</label>
107120
<dataScope>metadata</dataScope>
108121
</settings>
122+
<formElements>
123+
<select>
124+
<settings>
125+
<options class="MageOS\AsyncEventsAdminUi\Ui\Source\Notifiers"/>
126+
</settings>
127+
</select>
128+
</formElements>
109129
</field>
110-
<field name="store_id" sortOrder="50" formElement="input">
130+
<field name="store_id" sortOrder="50" formElement="select">
111131
<argument name="data" xsi:type="array">
112132
<item name="config" xsi:type="array">
113133
<item name="source" xsi:type="string">store_id</item>
@@ -118,6 +138,13 @@
118138
<label translate="true">Store</label>
119139
<dataScope>store_id</dataScope>
120140
</settings>
141+
<formElements>
142+
<select>
143+
<settings>
144+
<options class="MageOS\AsyncEventsAdminUi\Ui\Source\Stores"/>
145+
</settings>
146+
</select>
147+
</formElements>
121148
</field>
122149
</fieldset>
123150
</form>

0 commit comments

Comments
 (0)