mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
51 lines
1.4 KiB
PHP
51 lines
1.4 KiB
PHP
<?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());
|
|
}
|
|
}
|