mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
79 lines
2.1 KiB
PHP
79 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* 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.
|
|
*/
|
|
|
|
namespace Chill\MainBundle\Templating\Entity;
|
|
|
|
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
|
|
use Chill\MainBundle\Repository\UserRepository;
|
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
|
use Symfony\Component\Templating\EngineInterface;
|
|
|
|
use function array_merge;
|
|
|
|
/**
|
|
* @implements ChillEntityRenderInterface<CommentEmbeddable>
|
|
*/
|
|
class CommentRender implements ChillEntityRenderInterface
|
|
{
|
|
use BoxUtilsChillEntityRenderTrait;
|
|
/**
|
|
* @var EngineInterface
|
|
*/
|
|
private $engine;
|
|
|
|
private UserRepositoryInterface $userRepository;
|
|
|
|
public function __construct(
|
|
UserRepositoryInterface $userRepository,
|
|
EngineInterface $engine
|
|
) {
|
|
$this->userRepository = $userRepository;
|
|
$this->engine = $engine;
|
|
}
|
|
|
|
public function renderBox($entity, array $options): string
|
|
{
|
|
// default options
|
|
$options = array_merge([
|
|
'user' => [],
|
|
'disable_markdown' => false,
|
|
'limit_lines' => null,
|
|
'metadata' => true,
|
|
], $options);
|
|
|
|
if (null !== $entity->getUserId()) {
|
|
$user = $this->userRepository->find($entity->getUserId());
|
|
}
|
|
|
|
return $this->engine
|
|
->render(
|
|
'@ChillMain/Entity/CommentEmbeddable.html.twig',
|
|
[
|
|
'opening_box' => $this->getDefaultOpeningBox('comment-embeddable'),
|
|
'closing_box' => $this->getDefaultClosingBox(),
|
|
'user' => $user ?? null,
|
|
'comment' => $entity,
|
|
'options' => $options,
|
|
]
|
|
);
|
|
}
|
|
|
|
public function renderString($entity, array $options): string
|
|
{
|
|
return $entity->getComment();
|
|
}
|
|
|
|
public function supports($entity, array $options): bool
|
|
{
|
|
return $entity instanceof CommentEmbeddable;
|
|
}
|
|
}
|