diff --git a/extensions/mentions/src/Formatter/FormatGroupMentions.php b/extensions/mentions/src/Formatter/FormatGroupMentions.php index e9398f58e1..b6ad163170 100644 --- a/extensions/mentions/src/Formatter/FormatGroupMentions.php +++ b/extensions/mentions/src/Formatter/FormatGroupMentions.php @@ -25,9 +25,13 @@ public function __construct( public function __invoke(Renderer $renderer, mixed $context, string $xml): string { return Utils::replaceAttributes($xml, 'GROUPMENTION', function ($attributes) use ($context) { - $group = ($context instanceof AbstractModel && $context->isRelation('mentionsGroups')) - ? $context->mentionsGroups->find($attributes['id']) // @phpstan-ignore-line - : Group::find($attributes['id']); + /** @var Group|null $group */ + $group = match (true) { + $context instanceof AbstractModel && $context->isRelation('mentionsGroups') => $context->relationLoaded('mentionsGroups') + ? $context->mentionsGroups->find($attributes['id']) // @phpstan-ignore-line + : $context->mentionsGroups()->find($attributes['id']), // @phpstan-ignore-line + default => Group::query()->find($attributes['id']), + }; if ($group) { $attributes['groupname'] = $group->name_plural; diff --git a/extensions/mentions/src/Formatter/FormatPostMentions.php b/extensions/mentions/src/Formatter/FormatPostMentions.php index f020f7f5ff..75a20ba368 100644 --- a/extensions/mentions/src/Formatter/FormatPostMentions.php +++ b/extensions/mentions/src/Formatter/FormatPostMentions.php @@ -31,9 +31,13 @@ public function __construct( public function __invoke(Renderer $renderer, mixed $context, string $xml): string { return Utils::replaceAttributes($xml, 'POSTMENTION', function ($attributes) use ($context) { - $post = ($context instanceof AbstractModel && $context->isRelation('mentionsPosts')) - ? $context->mentionsPosts->find($attributes['id']) // @phpstan-ignore-line - : Post::find($attributes['id']); + /** @var Post|null $post */ + $post = match (true) { + $context instanceof AbstractModel && $context->isRelation('mentionsPosts') => $context->relationLoaded('mentionsPosts') + ? $context->mentionsPosts->find($attributes['id']) // @phpstan-ignore-line + : $context->mentionsPosts()->find($attributes['id']), // @phpstan-ignore-line + default => Post::query()->find($attributes['id']), + }; if ($post && $post->user) { $attributes['displayname'] = $post->user->display_name; diff --git a/extensions/mentions/src/Formatter/FormatTagMentions.php b/extensions/mentions/src/Formatter/FormatTagMentions.php index 5a0a0f1b32..6cad73ca6c 100644 --- a/extensions/mentions/src/Formatter/FormatTagMentions.php +++ b/extensions/mentions/src/Formatter/FormatTagMentions.php @@ -21,9 +21,12 @@ public function __invoke(Renderer $renderer, mixed $context, string $xml, ?Reque { return Utils::replaceAttributes($xml, 'TAGMENTION', function ($attributes) use ($context) { /** @var Tag|null $tag */ - $tag = ($context instanceof AbstractModel && $context->isRelation('mentionsTags')) - ? $context->mentionsTags->find($attributes['id']) // @phpstan-ignore-line - : Tag::query()->find($attributes['id']); + $tag = match (true) { + $context instanceof AbstractModel && $context->isRelation('mentionsTags') => $context->relationLoaded('mentionsTags') + ? $context->mentionsTags->find($attributes['id']) // @phpstan-ignore-line + : $context->mentionsTags()->find($attributes['id']), // @phpstan-ignore-line + default => Tag::query()->find($attributes['id']), + }; if ($tag) { $attributes['deleted'] = false; diff --git a/extensions/mentions/src/Formatter/FormatUserMentions.php b/extensions/mentions/src/Formatter/FormatUserMentions.php index 74d002940f..fbbbe28f73 100644 --- a/extensions/mentions/src/Formatter/FormatUserMentions.php +++ b/extensions/mentions/src/Formatter/FormatUserMentions.php @@ -27,9 +27,13 @@ public function __construct( public function __invoke(Renderer $renderer, mixed $context, string $xml): string { return Utils::replaceAttributes($xml, 'USERMENTION', function ($attributes) use ($context) { - $user = ($context instanceof AbstractModel && $context->isRelation('mentionsUsers')) - ? $context->mentionsUsers->find($attributes['id']) // @phpstan-ignore-line - : User::find($attributes['id']); + /** @var User|null $user */ + $user = match (true) { + $context instanceof AbstractModel && $context->isRelation('mentionsUsers') => $context->relationLoaded('mentionsUsers') + ? $context->mentionsUsers->find($attributes['id']) // @phpstan-ignore-line + : $context->mentionsUsers()->find($attributes['id']), // @phpstan-ignore-line + default => User::query()->find($attributes['id']), + }; $attributes['deleted'] = false; diff --git a/extensions/mentions/src/Formatter/UnparsePostMentions.php b/extensions/mentions/src/Formatter/UnparsePostMentions.php index c0e138846d..cd5dd5c2a5 100644 --- a/extensions/mentions/src/Formatter/UnparsePostMentions.php +++ b/extensions/mentions/src/Formatter/UnparsePostMentions.php @@ -34,9 +34,13 @@ public function __invoke(mixed $context, string $xml): string protected function updatePostMentionTags(mixed $context, string $xml): string { return Utils::replaceAttributes($xml, 'POSTMENTION', function ($attributes) use ($context) { - $post = ($context instanceof AbstractModel && $context->isRelation('mentionsPosts')) - ? $context->mentionsPosts->find($attributes['id']) // @phpstan-ignore-line - : Post::find($attributes['id']); + /** @var Post|null $post */ + $post = match (true) { + $context instanceof AbstractModel && $context->isRelation('mentionsPosts') => $context->relationLoaded('mentionsPosts') + ? $context->mentionsPosts->find($attributes['id']) // @phpstan-ignore-line + : $context->mentionsPosts()->find($attributes['id']), // @phpstan-ignore-line + default => Post::query()->find($attributes['id']), + }; if ($post && $post->user) { $attributes['displayname'] = $post->user->display_name; diff --git a/extensions/mentions/src/Formatter/UnparseTagMentions.php b/extensions/mentions/src/Formatter/UnparseTagMentions.php index 06eb0f3735..a25800c92f 100644 --- a/extensions/mentions/src/Formatter/UnparseTagMentions.php +++ b/extensions/mentions/src/Formatter/UnparseTagMentions.php @@ -29,9 +29,12 @@ protected function updateTagMentionTags(mixed $context, string $xml): string { return Utils::replaceAttributes($xml, 'TAGMENTION', function (array $attributes) use ($context) { /** @var Tag|null $tag */ - $tag = ($context instanceof AbstractModel && $context->isRelation('mentionsTags')) - ? $context->mentionsTags->find($attributes['id']) // @phpstan-ignore-line - : Tag::query()->find($attributes['id']); + $tag = match (true) { + $context instanceof AbstractModel && $context->isRelation('mentionsTags') => $context->relationLoaded('mentionsTags') + ? $context->mentionsTags->find($attributes['id']) // @phpstan-ignore-line + : $context->mentionsTags()->find($attributes['id']), // @phpstan-ignore-line + default => Tag::query()->find($attributes['id']), + }; if ($tag) { $attributes['tagname'] = $tag->name; diff --git a/extensions/mentions/src/Formatter/UnparseUserMentions.php b/extensions/mentions/src/Formatter/UnparseUserMentions.php index a278166f9a..a45d8dfa2a 100644 --- a/extensions/mentions/src/Formatter/UnparseUserMentions.php +++ b/extensions/mentions/src/Formatter/UnparseUserMentions.php @@ -34,9 +34,13 @@ public function __invoke(mixed $context, string $xml): string protected function updateUserMentionTags(mixed $context, string $xml): string { return Utils::replaceAttributes($xml, 'USERMENTION', function ($attributes) use ($context) { - $user = ($context instanceof AbstractModel && $context->isRelation('mentionsUsers')) - ? $context->mentionsUsers->find($attributes['id']) // @phpstan-ignore-line - : User::find($attributes['id']); + /** @var User|null $user */ + $user = match (true) { + $context instanceof AbstractModel && $context->isRelation('mentionsUsers') => $context->relationLoaded('mentionsUsers') + ? $context->mentionsUsers->find($attributes['id']) // @phpstan-ignore-line + : $context->mentionsUsers()->find($attributes['id']), // @phpstan-ignore-line + default => User::query()->find($attributes['id']), + }; $attributes['displayname'] = $user?->display_name ?? $this->translator->trans('core.lib.username.deleted_text');