diff --git a/src/Bundle/ChillMainBundle/Templating/Entity/PrivateCommentRender.php b/src/Bundle/ChillMainBundle/Templating/Entity/PrivateCommentRender.php new file mode 100644 index 000000000..d47cb2296 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Templating/Entity/PrivateCommentRender.php @@ -0,0 +1,72 @@ +engine = $engine; + $this->sercurity = $security; + } + + /** + * @param PrivateCommentEmbeddable $entity + */ + public function renderBox($entity, array $options): string + { + // default options + $options = array_merge([ + 'user' => [], + 'disable_markdown' => false, + 'limit_lines' => null, + 'metadata' => true, + ], $options); + + return $this->engine + ->render( + '@ChillMain/Entity/CommentEmbeddable.html.twig', + [ + 'opening_box' => $this->getDefaultOpeningBox('comment-embeddable'), + 'closing_box' => $this->getDefaultClosingBox(), + 'user' => $this->security->getUser() ?? null, + 'comment' => $entity->getCommentForUser($this->security->getUser()), + 'options' => $options, + ] + ); + } + + /** + * @param PrivateCommentEmbeddable $entity + */ + public function renderString($entity, array $options): string + { + return $entity->getCommentForUser($this->security->getUser()); + } + + public function supports($entity, array $options): bool + { + return $entity instanceof PrivateCommentEmbeddable; + } +} diff --git a/src/Bundle/ChillMainBundle/config/services/templating.yaml b/src/Bundle/ChillMainBundle/config/services/templating.yaml index e69700732..bd8d99786 100644 --- a/src/Bundle/ChillMainBundle/config/services/templating.yaml +++ b/src/Bundle/ChillMainBundle/config/services/templating.yaml @@ -41,6 +41,10 @@ services: tags: - { name: 'chill.render_entity' } + Chill\MainBundle\Templating\Entity\PrivateCommentRender: + tags: + - { name: 'chill.render_entity' } + Chill\MainBundle\Templating\ChillMarkdownRenderExtension: tags: - { name: twig.extension }