1
0
mirror of https://github.com/flarum/core.git synced 2025-08-16 05:14:20 +02:00

Make the Request available to the Formatter\Rendering event (#1721)

This is important because extensions may wish to render post content
differently depending on Request factors such as the actor. For example,
an attachments extension might wish to hide attachments from guests.

This solution is a bit of a hack-job for now, but soon when we refactor
the API layer to use tobscure/json-api-server, and also refactor the
Formatter layer, it can be revised.
This commit is contained in:
Toby Zerner
2019-01-23 09:03:49 +10:30
committed by Franz Liedke
parent 9b68bbe44e
commit 0ab9facc4b
7 changed files with 43 additions and 19 deletions

View File

@@ -11,6 +11,7 @@
namespace Flarum\Formatter\Event;
use Psr\Http\Message\ServerRequestInterface;
use s9e\TextFormatter\Renderer;
class Rendering
@@ -30,15 +31,22 @@ class Rendering
*/
public $xml;
/**
* @var ServerRequestInterface
*/
public $request;
/**
* @param Renderer $renderer
* @param mixed $context
* @param string $xml
* @param ServerRequestInterface|null $request
*/
public function __construct(Renderer $renderer, $context, &$xml)
public function __construct(Renderer $renderer, $context, &$xml, ServerRequestInterface $request = null)
{
$this->renderer = $renderer;
$this->context = $context;
$this->xml = &$xml;
$this->request = $request;
}
}

View File

@@ -16,6 +16,7 @@ use Flarum\Formatter\Event\Parsing;
use Flarum\Formatter\Event\Rendering;
use Illuminate\Contracts\Cache\Repository;
use Illuminate\Contracts\Events\Dispatcher;
use Psr\Http\Message\ServerRequestInterface;
use s9e\TextFormatter\Configurator;
use s9e\TextFormatter\Unparser;
@@ -69,13 +70,14 @@ class Formatter
*
* @param string $xml
* @param mixed $context
* @param ServerRequestInterface|null $request
* @return string
*/
public function render($xml, $context = null)
public function render($xml, $context = null, ServerRequestInterface $request = null)
{
$renderer = $this->getRenderer();
$this->events->dispatch(new Rendering($renderer, $context, $xml));
$this->events->dispatch(new Rendering($renderer, $context, $xml, $request));
return $renderer->render($xml);
}