Skip to content

Commit 0938050

Browse files
committed
Finalize entity select
1 parent dfc126b commit 0938050

4 files changed

Lines changed: 46 additions & 8 deletions

File tree

Form/FormBuilder.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Loki\AdminComponents\Form\Fieldset\FieldsetFactory;
99
use Loki\AdminComponents\Ui\Button\Button;
1010
use Loki\AdminComponents\Ui\Button\ButtonFactory;
11+
use Magento\Framework\Data\OptionSourceInterface;
1112
use Magento\Framework\View\Element\Template;
1213
use Magento\Framework\View\LayoutInterface;
1314

@@ -27,16 +28,33 @@ public function createForm(string $code): Form
2728
return $this->formFactory->create($code);
2829
}
2930

30-
public function createField(array $data = []): Field
31-
{
32-
$block = $this->layout->createBlock(Template::class);
31+
public function createField(
32+
string $name,
33+
string $label = '',
34+
bool $required = false,
35+
string $fieldType = 'input',
36+
array $fieldAttributes = [],
37+
?OptionSourceInterface $options = null
38+
): Field {
39+
$data = [
40+
'name' => $name,
41+
'label' => $label,
42+
'required' => $required,
43+
'field_type' => $fieldType,
44+
'field_attributes' => $fieldAttributes,
45+
'options' => $options,
46+
];
3347

48+
$block = $this->layout->createBlock(Template::class);
3449
return $this->fieldFactory->create($block, $data);
3550
}
3651

37-
public function createFieldset(string $code, string $label = '', array $fields = []): Fieldset
38-
{
39-
return $this->fieldsetFactory->create($code, $label, $fields);
52+
public function createFieldset(
53+
string $name,
54+
string $label = '',
55+
array $fields = []
56+
): Fieldset {
57+
return $this->fieldsetFactory->create($name, $label, $fields);
4058
}
4159

4260
public function createButton(

Form/FormFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ class FormFactory
88
{
99
public function __construct(
1010
private ObjectManagerInterface $objectManager,
11-
) {}
11+
) {
12+
}
1213

1314
public function create(string $code): Form
1415
{

Form/Item/ItemFactory.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Loki\AdminComponents\Form\Item;
5+
6+
use Magento\Framework\DataObject;
7+
use Magento\Framework\ObjectManagerInterface;
8+
9+
class ItemFactory
10+
{
11+
public function __construct(
12+
private ObjectManagerInterface $objectManager,
13+
) {
14+
}
15+
16+
public function create(array $data): DataObject
17+
{
18+
return $this->objectManager->create(DataObject::class, ['data' => $data]);
19+
}
20+
}

view/adminhtml/layout/loki_admin_components_entity.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
name="loki_admin_components.entity_select"
1414
template="Loki_AdminComponents::grid.phtml">
1515
<arguments>
16-
<argument name="provider" xsi:type="string">Magento\Customer\Model\ResourceModel\Customer\Collection</argument>
1716
<argument name="row_actions" xsi:type="array">
1817
<item name="select" xsi:type="array">
1918
<item name="label" xsi:type="string">Select</item>

0 commit comments

Comments
 (0)