mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
renderbox for private comments (not working yet)
This commit is contained in:
parent
27ce146aa0
commit
b2003c74a6
@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\MainBundle\Templating\Entity;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\Embeddable\PrivateCommentEmbeddable;
|
||||||
|
use Symfony\Component\Security\Core\Security;
|
||||||
|
use Symfony\Component\Templating\EngineInterface;
|
||||||
|
|
||||||
|
use function array_merge;
|
||||||
|
|
||||||
|
class PrivateCommentRender extends AbstractChillEntityRender
|
||||||
|
{
|
||||||
|
private EngineInterface $engine;
|
||||||
|
|
||||||
|
private Security $security;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
EngineInterface $engine,
|
||||||
|
Security $security
|
||||||
|
) {
|
||||||
|
$this->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;
|
||||||
|
}
|
||||||
|
}
|
@ -41,6 +41,10 @@ services:
|
|||||||
tags:
|
tags:
|
||||||
- { name: 'chill.render_entity' }
|
- { name: 'chill.render_entity' }
|
||||||
|
|
||||||
|
Chill\MainBundle\Templating\Entity\PrivateCommentRender:
|
||||||
|
tags:
|
||||||
|
- { name: 'chill.render_entity' }
|
||||||
|
|
||||||
Chill\MainBundle\Templating\ChillMarkdownRenderExtension:
|
Chill\MainBundle\Templating\ChillMarkdownRenderExtension:
|
||||||
tags:
|
tags:
|
||||||
- { name: twig.extension }
|
- { name: twig.extension }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user