mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Merge remote-tracking branch 'origin/master' into issue577_user_admin
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?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\DataMapper;
|
||||
|
||||
use Chill\MainBundle\Entity\Embeddable\PrivateCommentEmbeddable;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\DataMapperInterface;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
final class PrivateCommentDataMapper extends AbstractType implements DataMapperInterface
|
||||
{
|
||||
private Security $security;
|
||||
|
||||
public function __construct(Security $security)
|
||||
{
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
public function mapDataToForms($viewData, $forms)
|
||||
{
|
||||
if (null === $viewData) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$viewData instanceof PrivateCommentEmbeddable) {
|
||||
throw new UnexpectedTypeException($viewData, PrivateCommentEmbeddable::class);
|
||||
}
|
||||
|
||||
$forms = iterator_to_array($forms);
|
||||
|
||||
$forms['comments']->setData($viewData->getCommentForUser($this->security->getUser()));
|
||||
}
|
||||
|
||||
public function mapFormsToData($forms, &$viewData)
|
||||
{
|
||||
$forms = iterator_to_array($forms);
|
||||
|
||||
$viewData->setCommentForUser($this->security->getUser(), $forms['comments']->getData());
|
||||
}
|
||||
}
|
62
src/Bundle/ChillMainBundle/Form/Type/PrivateCommentType.php
Normal file
62
src/Bundle/ChillMainBundle/Form/Type/PrivateCommentType.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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\PrivateCommentEmbeddable;
|
||||
use Chill\MainBundle\Form\DataMapper\PrivateCommentDataMapper;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
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 PrivateCommentDataMapper $dataMapper;
|
||||
|
||||
protected UserInterface $user;
|
||||
|
||||
public function __construct(TokenStorageInterface $tokenStorage, PrivateCommentDataMapper $dataMapper)
|
||||
{
|
||||
$this->user = $tokenStorage->getToken()->getUser();
|
||||
$this->dataMapper = $dataMapper;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('comments', ChillTextareaType::class, [
|
||||
'disable_editor' => $options['disable_editor'],
|
||||
'label' => false,
|
||||
])
|
||||
->setDataMapper($this->dataMapper);
|
||||
}
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
$view->vars['hideLabel'] = true;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver
|
||||
->setDefined('disable_editor')
|
||||
->setAllowedTypes('disable_editor', 'bool')
|
||||
->setDefaults([
|
||||
'data_class' => PrivateCommentEmbeddable::class,
|
||||
'disable_editor' => false,
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user