FEATURE [datamapper][regroupment] moved datamapper to seperate class. Still not working

This commit is contained in:
2023-02-07 10:23:19 +01:00
parent 0ace1c1f6a
commit fb9b9b9226
3 changed files with 76 additions and 116 deletions

View File

@@ -0,0 +1,67 @@
<?php
declare(strict_types=1);
/*
* 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.
*/
namespace Chill\MainBundle\Form\DataMapper;
use Chill\MainBundle\Entity\Regroupment;
use Symfony\Component\Form\DataMapperInterface;
class RegroupmentDataMapper implements DataMapperInterface
{
private $regroupment;
public function __construct(?Regroupment $regroupment = null)
{
$this->regroupment = $regroupment;
}
public function mapDataToForms($data, $forms)
{
$forms = iterator_to_array($forms);
if ($this->regroupment instanceof Regroupment) {
$forms['regroupment']->setData($this->regroupment->getCenters());
dump($forms['regroupment']);
return;
}
if (null === $data) {
return;
}
if ($data instanceof Regroupment) {
$forms['regroupment']->setData($data);
}
}
public function mapFormsToData($forms, &$data)
{
$forms = iterator_to_array($forms);
if (isset($forms['regroupment'])) {
if ($this->regroupment instanceof Regroupment) {
$data = $this->regroupment;
} else {
$data = [];
foreach ($forms['regroupment']->getData() as $key => $regroupment)
{
dump($regroupment->getCenters());
$data[$key] = $regroupment->getCenters();
dump($data);
}
// $data = $forms['regroupment']->getData();
}
}
}
}