File tree Expand file tree Collapse file tree
view/adminhtml/templates/form/field_type Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,7 +58,8 @@ public function getAlpineSetter(): string
5858
5959 public function getFieldType (): FieldTypeInterface
6060 {
61- $ fieldType = $ this ->getData ('field_type ' );
61+ $ fieldType = $ this ->getData ('field_type ' )->setField ($ this );
62+
6263 if (false === $ fieldType instanceof FieldTypeInterface) {
6364 throw new RuntimeException ('Field type must be an instance of ' .FieldTypeInterface::class);
6465 }
Original file line number Diff line number Diff line change 44
55use Loki \AdminComponents \Form \Field \FieldTypeInterface ;
66
7- class Editor implements FieldTypeInterface
7+ class Editor extends FieldTypeAbstract implements FieldTypeInterface
88{
99 public function getTemplate (): string
1010 {
Original file line number Diff line number Diff line change 55
66use Loki \AdminComponents \Form \Field \FieldTypeInterface ;
77
8- class EntitySelect implements FieldTypeInterface
8+ class EntitySelect extends FieldTypeAbstract implements FieldTypeInterface
99{
1010 public function getInputType (): string
1111 {
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types = 1 );
4+
5+ namespace Loki \AdminComponents \Form \Field \FieldType ;
6+
7+ use Loki \AdminComponents \Form \Field \Field ;
8+
9+ abstract class FieldTypeAbstract
10+ {
11+ protected ?Field $ field = null ;
12+
13+ public function setField (Field $ field ): self
14+ {
15+ $ this ->field = $ field ;
16+ return $ this ;
17+ }
18+
19+ public function getField (): ?Field
20+ {
21+ return $ this ->field ;
22+ }
23+ }
Original file line number Diff line number Diff line change 55
66use Loki \AdminComponents \Form \Field \FieldTypeInterface ;
77
8- class FromTo implements FieldTypeInterface
8+ class FromTo extends FieldTypeAbstract implements FieldTypeInterface
99{
1010 public function __construct (
1111 private int $ maximumLength = 255 ,
Original file line number Diff line number Diff line change 44
55use Loki \AdminComponents \Form \Field \FieldTypeInterface ;
66
7- class Input implements FieldTypeInterface
7+ class Input extends FieldTypeAbstract implements FieldTypeInterface
88{
99 public function getTemplate (): string
1010 {
Original file line number Diff line number Diff line change 44
55use Loki \AdminComponents \Form \Field \FieldTypeInterface ;
66
7- class Pagebuilder implements FieldTypeInterface
7+ class Pagebuilder extends FieldTypeAbstract implements FieldTypeInterface
88{
99 public function getTemplate (): string
1010 {
Original file line number Diff line number Diff line change 66use Loki \AdminComponents \Form \Field \FieldTypeInterface ;
77use Loki \AdminComponents \ViewModel \Options \ProductOptions ;
88
9- class ProductId implements FieldTypeInterface
9+ class ProductId extends FieldTypeAbstract implements FieldTypeInterface
1010{
1111 public function __construct (
1212 private ProductOptions $ productOptions
Original file line number Diff line number Diff line change 22
33namespace Loki \AdminComponents \Form \Field \FieldType ;
44
5+ use Loki \AdminComponents \Form \Field \Field ;
56use Loki \AdminComponents \Form \Field \FieldTypeInterface ;
7+ use Magento \Framework \Data \OptionSourceInterface ;
8+ use Magento \Framework \ObjectManagerInterface ;
69
7- class Select implements FieldTypeInterface
10+ class Select extends FieldTypeAbstract implements FieldTypeInterface
811{
12+ public function __construct (
13+ private readonly ObjectManagerInterface $ objectManager ,
14+ ) {
15+ }
16+
917 public function getTemplate (): string
1018 {
1119 return 'Loki_AdminComponents::form/field_type/select.phtml ' ;
1220 }
21+
22+ public function getOptions (): array
23+ {
24+ if (!$ this ->field ) {
25+ return [];
26+ }
27+
28+ $ options = $ this ->field ->getOptions ();
29+
30+ if (!$ options ) {
31+ return [];
32+ }
33+
34+ $ options = $ this ->objectManager ->get ($ options );
35+
36+ if (!$ options instanceof OptionSourceInterface) {
37+ return [];
38+ }
39+
40+ return $ options ->toOptionArray ();
41+ }
1342}
Original file line number Diff line number Diff line change 44
55use Loki \AdminComponents \Form \Field \FieldTypeInterface ;
66
7- class Switcher implements FieldTypeInterface
7+ class Switcher extends FieldTypeAbstract implements FieldTypeInterface
88{
99 public function getTemplate (): string
1010 {
You can’t perform that action at this time.
0 commit comments