chill-bundles/Form/DataMapper/ScopePickerDataMapper.php

52 lines
1.1 KiB
PHP

<?php
namespace Chill\MainBundle\Form\DataMapper;
use Chill\MainBundle\Entity\Scope;
use Symfony\Component\Form\DataMapperInterface;
use Symfony\Component\Form\FormInterface;
class ScopePickerDataMapper implements DataMapperInterface
{
/**
* @var \Chill\MainBundle\Entity\Scope
*/
private $scope;
public function __construct(Scope $scope = null)
{
$this->scope = $scope;
}
public function mapDataToForms($data, $forms)
{
$forms = iterator_to_array($forms);
if ($this->scope instanceof Scope) {
$forms['scope']->setData($this->scope);
return;
}
if (null === $data) {
return;
}
if ($data instanceof Scope) {
$forms['scope']->setData($data);
}
}
public function mapFormsToData($forms, &$data)
{
$forms = iterator_to_array($forms);
if (isset($forms['scope'])) {
if ($this->scope instanceof Scope) {
$data = $this->scope;
} else {
$data = $forms['scope']->getData();
}
}
}
}