mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-04 22:04:59 +00:00
Improve Embeddable Comment Render
* render embeddable comment into twig template; * add some style
This commit is contained in:
@@ -24,6 +24,7 @@ use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Repository\UserRepository;
|
||||
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
|
||||
class CommentRender extends AbstractChillEntityRender
|
||||
{
|
||||
@@ -31,10 +32,19 @@ class CommentRender extends AbstractChillEntityRender
|
||||
* @var \Chill\MainBundle\Repository\UserRepository
|
||||
*/
|
||||
private $userRepository;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var EngineInterface
|
||||
*/
|
||||
private $engine;
|
||||
|
||||
public function __construct(UserRepository $userRepository)
|
||||
{
|
||||
public function __construct(
|
||||
UserRepository $userRepository,
|
||||
EngineInterface $engine
|
||||
) {
|
||||
$this->userRepository = $userRepository;
|
||||
$this->engine = $engine;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,35 +55,29 @@ class CommentRender extends AbstractChillEntityRender
|
||||
*/
|
||||
public function renderBox($entity, array $options): string
|
||||
{
|
||||
$username = '';
|
||||
|
||||
// default options
|
||||
$options = \array_merge([
|
||||
'user' => [],
|
||||
'disable_markdown' => false,
|
||||
'limit_lines' => null,
|
||||
'metadata' => true
|
||||
], $options);
|
||||
|
||||
if ($entity->getUserId()) {
|
||||
$user = $this->userRepository->find($entity->getUserId());
|
||||
if ($user instanceof User) {
|
||||
$username = $user->getUsername();
|
||||
}
|
||||
}
|
||||
|
||||
$str = $this->getDefaultOpeningBox('comment-embeddable').
|
||||
'<span class="comment_comment">'.
|
||||
nl2br($entity->getComment()).
|
||||
'</span>';
|
||||
|
||||
if ($entity->getDate() instanceof \DateTime) {
|
||||
$str .= '<span class="comment_date">'.
|
||||
$entity->getDate()->format('d/m/Y H:i');
|
||||
'</span>';
|
||||
}
|
||||
|
||||
if (strlen($username) > 0) {
|
||||
$str .= '<span class="comment_user">'.
|
||||
$username.
|
||||
'</span>';
|
||||
}
|
||||
|
||||
$str .= $this->getDefaultClosingBox();
|
||||
|
||||
return $str;
|
||||
|
||||
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
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user