Use "state snapshot" for repeaters and builders

This commit is contained in:
Dan Harrin
2025-09-14 12:11:05 +01:00
parent ba778dab5a
commit 7d3721c8f8
4 changed files with 32 additions and 4 deletions
+1 -1
View File
@@ -1135,7 +1135,7 @@ class Builder extends Field implements CanConcealComponents, HasExtraItemActions
*/
public function getRawItemState(string $key): array
{
return $this->getChildSchema($key)->getRawState();
return $this->getChildSchema($key)->getStateSnapshot();
}
public function getHeadingsCount(): int
+2 -2
View File
@@ -1163,7 +1163,7 @@ class Repeater extends Field implements CanConcealComponents, HasExtraItemAction
'item' => $container,
'key' => $key,
'schema' => $container,
'state' => $container->getRawState(),
'state' => $container->getStateSnapshot(),
'uuid' => $key,
]);
}
@@ -1350,7 +1350,7 @@ class Repeater extends Field implements CanConcealComponents, HasExtraItemAction
*/
public function getRawItemState(string $key): array
{
return $this->getChildSchema($key)->getRawState();
return $this->getChildSchema($key)->getStateSnapshot();
}
public function getHeadingsCount(): int
@@ -448,6 +448,34 @@ trait HasState
});
}
/**
* @internal Do not use this method outside the internals of Filament. It is subject to breaking changes in minor and patch releases.
*
* @return array<string, mixed>
*/
public function getStateSnapshot(): array
{
return Component::withVisibilityCache(function (): array {
$statePath = $this->getStatePath();
if (filled($statePath)) {
$state = [];
data_set($state, $statePath, $this->getRawState());
} else {
$state = $this->getRawState();
}
$this->dehydrateState($state);
$this->mutateDehydratedState($state);
if ($statePath) {
$state = data_get($state, $statePath) ?? [];
}
return $state;
});
}
/**
* @return array<string, mixed> | Arrayable
*/
@@ -90,7 +90,7 @@ class RuleBuilder extends Builder
throw new LogicException('No block component found.');
}
return $block->getLabel($schema->getRawState(), $blockUuid);
return $block->getLabel($schema->getStateSnapshot(), $blockUuid);
});
if ($blockLabels->isEmpty()) {