83 lines
2.0 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 Symfony\Component\Templating\EngineInterface;
use function array_merge;
class CommentRender extends AbstractChillEntityRender
{
/**
* @var EngineInterface
*/
private $engine;
/**
* @var \Chill\MainBundle\Repository\UserRepository
*/
private $userRepository;
public function __construct(
UserRepository $userRepository,
EngineInterface $engine
) {
$this->userRepository = $userRepository;
$this->engine = $engine;
}
/**
* @param CommentEmbeddable $entity
*/
public function renderBox($entity, array $options): string
{
// default options
$options = array_merge([
'user' => [],
'disable_markdown' => false,
'limit_lines' => null,
'metadata' => true,
], $options);
if ($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,
]
);
}
/**
* @param CommentEmbeddable $entity
*/
public function renderString($entity, array $options): string
{
return $entity->getComment();
}
public function supports($entity, array $options): bool
{
return $entity instanceof CommentEmbeddable;
}
}