Skip to content

Commit 6cbef24

Browse files
committed
wip: Make block optional in Field class
1 parent 6145669 commit 6cbef24

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

Form/Field/Field.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class Field extends DataObject
1313
{
1414
public function __construct(
15-
private AbstractBlock $block,
15+
private ?AbstractBlock $block = null,
1616
array $data = [],
1717
) {
1818
parent::__construct($data);
@@ -80,7 +80,12 @@ public function getFieldType(): FieldTypeInterface
8080
return $fieldType;
8181
}
8282

83-
public function getBlock(): AbstractBlock
83+
public function setBlock(AbstractBlock $block): self
84+
{
85+
$this->block = $block;
86+
}
87+
88+
public function getBlock(): ?AbstractBlock
8489
{
8590
return $this->block;
8691
}

Form/Field/FieldFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Magento\Framework\View\Element\AbstractBlock;
88
use Magento\Framework\View\Element\Template;
99
use Magento\Framework\View\LayoutInterface;
10+
use RuntimeException;
1011

1112
class FieldFactory
1213
{
@@ -29,7 +30,7 @@ public function createWithBlock(
2930
}
3031

3132
public function create(
32-
AbstractBlock $block,
33+
?AbstractBlock $block = null,
3334
array $data = [],
3435
): Field {
3536
if (!isset($data['code']) && !empty($data['name'])) {
@@ -50,7 +51,7 @@ public function create(
5051
}
5152

5253
if (false === $data['field_type'] instanceof FieldTypeInterface) {
53-
throw new \RuntimeException((string)__('Field type "%1" could not be resolved', $data['field_type']));
54+
throw new RuntimeException((string)__('Field type "%1" could not be resolved', $data['field_type']));
5455
}
5556

5657
if (!isset($data['scope'])) {

0 commit comments

Comments
 (0)