Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix?: Allow mentions from non-post objects #79

Merged
merged 5 commits into from
Nov 28, 2021
Merged

Conversation

imorland
Copy link
Member

@imorland imorland commented Nov 26, 2021

Fixes #2902

Changes proposed in this pull request:
Extensions such as askvortsov/flarum-moderator-warnings, fof/pages and fof/moderator-notes allow for mentioning a user outside of a Post. This functionality was broken in the 1.0 release due to pulling the user directly from the post relationship.

This is an interim solution, first proposed by @datitisev in #2902, until the refactor of the Formatter API.

I added && $post->exists to the conditional proposed in the issue, as this maintains the current expectation of extensions using the formatter in this way (ie passing new Post() to the renderer.

Examples:
https://github.com/FriendsOfFlarum/moderator-notes/blob/7496beb5abcdec2c2a48505c1c05dc4343831548/src/Api/Serializer/ModeratorNotesSerializer.php#L49
https://github.com/askvortsov1/flarum-moderator-warnings/blob/5be9d5cf272c88262fb0161f3a0b80c7eb445bd2/src/Api/Serializer/WarningSerializer.php#L47

Screenshot
With this change:
image

Without this change:
image

Necessity

  • Has the problem that is being solved here been clearly explained?
  • If applicable, have various options for solving this problem been considered?
  • For core PRs, does this need to be in core, or could it be in an extension?
  • Are we willing to maintain this for years / potentially forever?

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).
  • Core developer confirmed locally this works as intended.
  • Tests have been added, or are not appropriate here.

Required changes:

  • Related documentation PR: (Remove if irrelevant)
  • Related core extension PRs: (Remove if irrelevant)

@davwheat davwheat requested a review from SychO9 November 26, 2021 21:10
@imorland imorland changed the title Allow mentions from non-post objects fix?: Allow mentions from non-post objects Nov 26, 2021
src/Formatter/FormatUserMentions.php Outdated Show resolved Hide resolved
Copy link
Sponsor Member

@askvortsov1 askvortsov1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me. I wonder if it might be worth separating out the common logic into a separate method.

@imorland imorland requested a review from SychO9 November 27, 2021 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Mentions] Unable to use Formatter with mentions on items other than Posts
6 participants