mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
fix: Table relationship rich editor attributes
This commit is contained in:
@@ -103,6 +103,44 @@ trait HasCellState
|
||||
public function getStateFromRecord(): mixed
|
||||
{
|
||||
$record = $this->getRecord();
|
||||
|
||||
if ($record instanceof Model) {
|
||||
$relationship = $this->getRelationship($record);
|
||||
|
||||
if ($relationship) {
|
||||
$relationshipAttribute = $this->getFullAttributeName($record);
|
||||
|
||||
$state = collect($this->getRelationshipResults($record))
|
||||
->reduce(
|
||||
function (Collection $carry, Model $record) use ($relationshipAttribute): Collection {
|
||||
if (
|
||||
($record instanceof HasRichContent) &&
|
||||
$record->hasRichContentAttribute($relationshipAttribute)
|
||||
) {
|
||||
$state = $record->getRichContentAttribute($relationshipAttribute);
|
||||
} else {
|
||||
$state = data_get($record, $relationshipAttribute);
|
||||
}
|
||||
|
||||
if (blank($state)) {
|
||||
return $carry;
|
||||
}
|
||||
|
||||
return $carry->push($state);
|
||||
},
|
||||
initial: collect(),
|
||||
)
|
||||
->when($this->isDistinctList(), fn (Collection $state) => $state->unique())
|
||||
->values();
|
||||
|
||||
if (! $state->count()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $state->all();
|
||||
}
|
||||
}
|
||||
|
||||
$name = $this->getName();
|
||||
|
||||
if (
|
||||
@@ -114,39 +152,7 @@ trait HasCellState
|
||||
$state = data_get($record, $name);
|
||||
}
|
||||
|
||||
if ($state !== null) {
|
||||
return $state;
|
||||
}
|
||||
|
||||
if (($this instanceof Column) && is_array($record)) { /** @phpstan-ignore function.impossibleType, booleanAnd.alwaysFalse */
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $this->hasRelationship($record)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$relationship = $this->getRelationship($record);
|
||||
|
||||
if (! $relationship) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$attributeName = $this->getAttributeName($record);
|
||||
$fullAttributeName = $this->getFullAttributeName($record);
|
||||
|
||||
$state = collect($this->getRelationshipResults($record))
|
||||
->filter(fn (Model $record): bool => array_key_exists($attributeName, $record->attributesToArray()))
|
||||
->pluck($fullAttributeName)
|
||||
->filter(fn ($state): bool => filled($state))
|
||||
->when($this->isDistinctList(), fn (Collection $state) => $state->unique())
|
||||
->values();
|
||||
|
||||
if (! $state->count()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $state->all();
|
||||
return $state;
|
||||
}
|
||||
|
||||
public function clearCachedState(): void
|
||||
|
||||
Reference in New Issue
Block a user