mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
73 lines
1.9 KiB
PHP
73 lines
1.9 KiB
PHP
<?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;
|
|
}
|
|
}
|