Skip to content
Merged
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
5 changes: 0 additions & 5 deletions src/Http/Resources/Comments/CommentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,6 @@ private function buildParentSummary(Comment $comment): ?array
];
}

protected function shouldPreProcessIndex(string $key): bool
{
return ! in_array($key, ['thread_id', 'author_id'], true);
}

private function snippet(?string $text, int $length = 80): string
{
$text = trim((string) $text);
Expand Down
9 changes: 6 additions & 3 deletions src/Http/Resources/ListedResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ abstract public function values(Request $request): array;
public function toArray(Request $request): array|Arrayable
{
return [
$this->merge($this->values($request)),
$this->merge($this->resourceValues()),
$this->merge($this->values($request)),
];
}

Expand All @@ -68,8 +68,11 @@ protected function resourceValues(): Collection

$field->setValue($value);
$field->setParent($this->resource);
$field->preProcessIndex();
$value = $field->value();
$preProcessed = $field->preProcessIndex();

$value = $preProcessed instanceof Field
? $preProcessed->value()
: $preProcessed;

return [$key => $value];
});
Expand Down
38 changes: 38 additions & 0 deletions tests/Feature/ControlPanel/CommentsHttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,44 @@ public function index_returns_a_compact_thread_summary(): void
$this->assertArrayNotHasKey('content', $thread);
}

#[Test]
public function index_preprocesses_relationship_columns_for_statamics_listing_fieldtypes(): void
{
$this->actAsAdmin();

$entry = $this->createEntry([
'id' => '0198f017-f627-71dd-bef7-18f90a749f36',
'slug' => 'relationship-column-entry',
'title' => 'Relationship column entry',
]);
$authorId = 'relationship-column-author';
$author = $this->makeStatamicUser();
$author->id($authorId);
$author->email('relationship-column-author@example.com');
$author->data(['name' => 'Relationship Column Author']);
$author->save();

$comment = CommentFactory::new()
->threadId($entry->id())
->collection('blog')
->authenticatedAuthor($authorId)
->text('Relationship column body')
->data(['comment' => 'Relationship column body'])
->published()
->create();

$row = $this->requireObject($this->getJson(
cp_route('meerkat.cp.comments.index').'?columns=thread_id,author_id,collection,site',
)->assertOk()->json('data.0'));

$this->assertSame($comment->id, $row['id']);
$this->assertSame([$entry->id()], array_column($this->requireRows($row['thread_id']), 'id'));
$this->assertSame([$authorId], array_column($this->requireRows($row['author_id']), 'id'));
$this->assertSame(['blog'], array_column($this->requireRows($row['collection']), 'id'));
$this->assertIsString($row['site']);
$this->assertNotSame('default', $row['site']);
}

#[Test]
public function thread_endpoint_hides_recoverable_tombstones(): void
{
Expand Down
Loading