mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Improve Embeddable Comment Render
* render embeddable comment into twig template; * add some style
This commit is contained in:
parent
3ca5018e45
commit
66e590972a
@ -36,6 +36,7 @@ require('./modules/breadcrumb/index.js');
|
|||||||
require('./modules/download-report/index.js');
|
require('./modules/download-report/index.js');
|
||||||
require('./modules/select_interactive_loading/index.js');
|
require('./modules/select_interactive_loading/index.js');
|
||||||
require('./modules/export-list/export-list.scss');
|
require('./modules/export-list/export-list.scss');
|
||||||
|
require('./modules/entity/index.js');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* load img
|
* load img
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
.chill-entity__comment-embeddable {
|
||||||
|
.chill-entity__comment-embeddable__metadata {
|
||||||
|
font-size: smaller;
|
||||||
|
color: var(--chill-light-gray);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
// css classes to render entities
|
||||||
|
require('./comment_embeddable.scss');
|
@ -0,0 +1,36 @@
|
|||||||
|
{{ opening_box|raw }}
|
||||||
|
<div class="">
|
||||||
|
<div class="comment-embeddable_comment">
|
||||||
|
|
||||||
|
{%- if options['limit_lines'] is not null -%}
|
||||||
|
{% set content = comment.comment|split('\n')|slice(0, options['limit_lines'])|join('\n') %}
|
||||||
|
{%- else -%}
|
||||||
|
{% set content = comment.comment %}
|
||||||
|
{%- endif -%}
|
||||||
|
|
||||||
|
<blockquote class="chill-user-quote">
|
||||||
|
{% if options['disable_markdown'] %}
|
||||||
|
{{ content|nl2br }}
|
||||||
|
{% else %}
|
||||||
|
{{ content|chill_markdown_to_html }}
|
||||||
|
{% endif %}
|
||||||
|
</blockquote>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% if options['metadata'] %}
|
||||||
|
<div class="chill-entity__comment-embeddable__metadata">
|
||||||
|
{% if user is not empty %}
|
||||||
|
<span class="chill-entity__comment-embeddable__user">
|
||||||
|
{{ 'Last updated by'| trans }} {{ user|chill_entity_render_box(options['user']) }}
|
||||||
|
</span>';
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if comment.date is not empty %}
|
||||||
|
<span class="chill-entity__comment-embeddable__date">
|
||||||
|
{% if user is empty %}{{ 'Last updated on'|trans ~ ' ' }}{% else %}{{ 'on'|trans ~ ' ' }}{% endif %}
|
||||||
|
{{ comment.date|format_datetime("medium", "short") }}
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{{ closing_box|raw }}
|
@ -24,6 +24,7 @@ use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
|
|||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\MainBundle\Repository\UserRepository;
|
use Chill\MainBundle\Repository\UserRepository;
|
||||||
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
|
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
|
||||||
|
use Symfony\Component\Templating\EngineInterface;
|
||||||
|
|
||||||
class CommentRender extends AbstractChillEntityRender
|
class CommentRender extends AbstractChillEntityRender
|
||||||
{
|
{
|
||||||
@ -31,10 +32,19 @@ class CommentRender extends AbstractChillEntityRender
|
|||||||
* @var \Chill\MainBundle\Repository\UserRepository
|
* @var \Chill\MainBundle\Repository\UserRepository
|
||||||
*/
|
*/
|
||||||
private $userRepository;
|
private $userRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var EngineInterface
|
||||||
|
*/
|
||||||
|
private $engine;
|
||||||
|
|
||||||
public function __construct(UserRepository $userRepository)
|
public function __construct(
|
||||||
{
|
UserRepository $userRepository,
|
||||||
|
EngineInterface $engine
|
||||||
|
) {
|
||||||
$this->userRepository = $userRepository;
|
$this->userRepository = $userRepository;
|
||||||
|
$this->engine = $engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,35 +55,29 @@ class CommentRender extends AbstractChillEntityRender
|
|||||||
*/
|
*/
|
||||||
public function renderBox($entity, array $options): string
|
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()) {
|
if ($entity->getUserId()) {
|
||||||
$user = $this->userRepository->find($entity->getUserId());
|
$user = $this->userRepository->find($entity->getUserId());
|
||||||
if ($user instanceof User) {
|
|
||||||
$username = $user->getUsername();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$str = $this->getDefaultOpeningBox('comment-embeddable').
|
return $this->engine
|
||||||
'<span class="comment_comment">'.
|
->render(
|
||||||
nl2br($entity->getComment()).
|
'@ChillMain/Entity/CommentEmbeddable.html.twig',
|
||||||
'</span>';
|
[
|
||||||
|
'opening_box' => $this->getDefaultOpeningBox('comment-embeddable'),
|
||||||
if ($entity->getDate() instanceof \DateTime) {
|
'closing_box' => $this->getDefaultClosingBox(),
|
||||||
$str .= '<span class="comment_date">'.
|
'user' => $user ?? NULL,
|
||||||
$entity->getDate()->format('d/m/Y H:i');
|
'comment' => $entity,
|
||||||
'</span>';
|
'options' => $options
|
||||||
}
|
]
|
||||||
|
);
|
||||||
if (strlen($username) > 0) {
|
|
||||||
$str .= '<span class="comment_user">'.
|
|
||||||
$username.
|
|
||||||
'</span>';
|
|
||||||
}
|
|
||||||
|
|
||||||
$str .= $this->getDefaultClosingBox();
|
|
||||||
|
|
||||||
return $str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,6 +34,7 @@ services:
|
|||||||
Chill\MainBundle\Templating\Entity\CommentRender:
|
Chill\MainBundle\Templating\Entity\CommentRender:
|
||||||
arguments:
|
arguments:
|
||||||
- '@chill.main.user_repository'
|
- '@chill.main.user_repository'
|
||||||
|
- '@Symfony\Component\Templating\EngineInterface'
|
||||||
tags:
|
tags:
|
||||||
- { name: 'chill.render_entity' }
|
- { name: 'chill.render_entity' }
|
||||||
|
|
||||||
|
@ -35,6 +35,9 @@ This form contains errors: Ce formulaire contient des erreurs
|
|||||||
Choose an user: Choisir un utilisateur
|
Choose an user: Choisir un utilisateur
|
||||||
'You are going to leave a page with unsubmitted data. Are you sure you want to leave ?': "Vous allez quitter la page alors que des données n'ont pas été enregistrées. Êtes vous sûr de vouloir partir ?"
|
'You are going to leave a page with unsubmitted data. Are you sure you want to leave ?': "Vous allez quitter la page alors que des données n'ont pas été enregistrées. Êtes vous sûr de vouloir partir ?"
|
||||||
No value: Aucune information
|
No value: Aucune information
|
||||||
|
Last updated by: Dernière mise à jour par
|
||||||
|
Last updated on: Dernière mise à jour le
|
||||||
|
on: le
|
||||||
|
|
||||||
Edit: Modifier
|
Edit: Modifier
|
||||||
Update: Mettre à jour
|
Update: Mettre à jour
|
||||||
|
Loading…
x
Reference in New Issue
Block a user