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

Allow calling formatContent() on a CommentPost without passing a request #1840

Closed
matteocontrini opened this issue Aug 9, 2019 · 5 comments · Fixed by #1848
Closed

Allow calling formatContent() on a CommentPost without passing a request #1840

matteocontrini opened this issue Aug 9, 2019 · 5 comments · Fixed by #1848

Comments

@matteocontrini
Copy link
Contributor

matteocontrini commented Aug 9, 2019

When the Formatter was made dependent on the current HTTP request in 0ab9fac, the $request parameter on the render method on the formatter was made optional, but it wasn't on the formatContent($request) method in the CommentPost class.

As discussed here, there might be the need to generate the HTML content in contexts where the request is not available.

The proposal is to change, in the CommentPost class, this signature from:

public function formatContent(ServerRequestInterface $request)

to:

public function formatContent(ServerRequestInterface $request = null)
@matteocontrini matteocontrini changed the title Allow calling formatContent() on a CommentPost without a request Allow calling formatContent() on a CommentPost without passing a request Aug 9, 2019
@clarkwinkelmann
Copy link
Member

clarkwinkelmann commented Aug 9, 2019

Cross-linking the PR: #1721

Not sure if it's worth an additional issue, but IMO it would be more logical to pass the actor as parameter, assuming guest if no actor was given. That way the same method can also be useful in the context of sending emails for example, where there is no request, but definitely is an actor.

@franzliedke
Copy link
Contributor

Definitely 👍 for the proposal - please feel free to send a PR!

@clarkwinkelmann That was also my reaction, but Toby's response isn't completely without merit. Can you share example code where you are using the formatter in a non-request context, please?

@franzliedke
Copy link
Contributor

We could also consider passing in something like a FormattingContext or FormattingOptions that would be determined / retrieved by the calling site based on context.

@clarkwinkelmann
Copy link
Member

I have no example of my own but it could maybe be used here for example https://github.com/flarum/subscriptions/blob/v0.1.0-beta.9/views/emails/newPost.blade.php#L10

@matteocontrini
Copy link
Contributor Author

Is it still possible to have the PR merged for beta10, as a temporary solution? Thanks

@franzliedke franzliedke added this to the 0.1.0-beta.10 milestone Sep 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants