mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
private comment added to activity
This commit is contained in:
@@ -21,13 +21,12 @@ use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
class CommentType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* @var \Symfony\Component\Security\Core\User\UserInterface
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
protected UserInterface $user;
|
||||
|
||||
public function __construct(TokenStorageInterface $tokenStorage)
|
||||
{
|
||||
|
75
src/Bundle/ChillMainBundle/Form/Type/PrivateCommentType.php
Normal file
75
src/Bundle/ChillMainBundle/Form/Type/PrivateCommentType.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?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\Form\Type;
|
||||
|
||||
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
|
||||
use DateTime;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
class PrivateCommentType extends AbstractType
|
||||
{
|
||||
protected UserInterface $user;
|
||||
|
||||
public function __construct(TokenStorageInterface $tokenStorage)
|
||||
{
|
||||
$this->user = $tokenStorage->getToken()->getUser();
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('comment', ChillTextareaType::class, [
|
||||
'disable_editor' => $options['disable_editor'],
|
||||
'label' => $options['label'],
|
||||
]);
|
||||
|
||||
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
|
||||
$data = $event->getForm()->getData();
|
||||
$privateComment = $event->getData() ?? ['privateComment' => ''];
|
||||
|
||||
if (null !== $data && $data->getComment() !== $privateComment['comment']) {
|
||||
$data->setDate(new DateTime());
|
||||
$data->setUserId($this->user->getId());
|
||||
$event->getForm()->setData($data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view->vars = array_replace(
|
||||
$view->vars,
|
||||
[
|
||||
'hideLabel' => true,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
->setDefined('disable_editor')
|
||||
->setAllowedTypes('disable_editor', 'bool')
|
||||
->setDefaults([
|
||||
'data_class' => CommentEmbeddable::class,
|
||||
'disable_editor' => false,
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user