Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,14 @@ public function withValue($value): HasDynamicInputs
$this->checkArg("value", $this->isClientSideValueOk($value), "Display value does not match input type.");

$clone = clone $this;
foreach ($value as $data) {
$file_id = ($clone->hasMetadataInputs()) ? $data[0] : $data;
if (is_array($value)) {
foreach ($value as $data) {
$file_id = ($clone->hasMetadataInputs()) ? $data[0] : $data;

// that was not implicitly intended, but mapping dynamic inputs
// to the file-id is also a duplicate protection.
$clone->generated_dynamic_inputs[$file_id] = $clone->getTemplateForDynamicInputs()->withValue($data);
// that was not implicitly intended, but mapping dynamic inputs
// to the file-id is also a duplicate protection.
$clone->generated_dynamic_inputs[$file_id] = $clone->getTemplateForDynamicInputs()->withValue($data);
}
}

return $clone;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ public function withValue($value): self
$this->checkArg('value', $this->isClientSideValueOk($value), "Display value does not match input(-template) type.");
$clone = clone $this;

if (!is_array($value)) {
if (is_array($value)) {
foreach ($value as $input_name => $input_value) {
$clone->generated_dynamic_inputs[$input_name] = $clone->getTemplateForDynamicInputs()->withValue($input_value);
}
} elseif ($value !== null) {
$clone->generated_dynamic_inputs[] = $clone->getTemplateForDynamicInputs()->withValue($value);
return $clone;
}

foreach ($value as $input_name => $input_value) {
$clone->generated_dynamic_inputs[$input_name] = $clone->getTemplateForDynamicInputs()->withValue($input_value);
}

return $clone;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ public function testWithValueForValidArguments(string|int|null $value): void
$this->assertEquals([$value], $component->getValue());
}

public function testWithValueForEmptyValidArguments(): void
{
$node_retrieval = $this->getNodeRetrieval();
$component = $this->getFieldFactory()->treeSelect($node_retrieval, '');
$component = $component->withValue(null);
$this->assertEquals([], $component->getValue());
}

public function testRenderWithValue(): void
{
$node_id = 'some-existing-node-id';
Expand Down Expand Up @@ -332,7 +340,6 @@ public static function getValidArgumentsForWithValue(): array
['1'],
[''],
[' '],
[null],
];
}

Expand Down
Loading