mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-23 08:03:49 +00:00
PrivateCommentEmbeddable created and added to entities + datamapper
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?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());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user