| @@ 32-68 (lines=37) @@ | ||
| 29 | * |
|
| 30 | * @author Adam Kadlec <[email protected]> |
|
| 31 | */ |
|
| 32 | class EntityContainer extends Forms\Container |
|
| 33 | { |
|
| 34 | /** |
|
| 35 | * Implement entity handling in form |
|
| 36 | */ |
|
| 37 | use TEntityContainer; |
|
| 38 | ||
| 39 | /** |
|
| 40 | * @var ORM\EntityManager |
|
| 41 | */ |
|
| 42 | private $entityManager; |
|
| 43 | ||
| 44 | /** |
|
| 45 | * @param ORM\EntityManager $entityManager |
|
| 46 | */ |
|
| 47 | public function __construct(ORM\EntityManager $entityManager) |
|
| 48 | { |
|
| 49 | parent::__construct(); |
|
| 50 | ||
| 51 | $this->entityManager = $entityManager; |
|
| 52 | } |
|
| 53 | ||
| 54 | /** |
|
| 55 | * Adds naming container to the form |
|
| 56 | * |
|
| 57 | * @param string $name |
|
| 58 | * |
|
| 59 | * @return EntityContainer |
|
| 60 | */ |
|
| 61 | public function addContainer($name) : EntityContainer |
|
| 62 | { |
|
| 63 | $control = new self($this->entityManager); |
|
| 64 | $control->setCurrentGroup($this->currentGroup); |
|
| 65 | ||
| 66 | return $this[$name] = $control; |
|
| 67 | } |
|
| 68 | } |
|
| 69 | ||
| @@ 33-80 (lines=48) @@ | ||
| 30 | * |
|
| 31 | * @author Adam Kadlec <[email protected]> |
|
| 32 | */ |
|
| 33 | class EntityForm extends Application\UI\Form |
|
| 34 | { |
|
| 35 | /** |
|
| 36 | * Implement entity handling in form |
|
| 37 | */ |
|
| 38 | use TEntityContainer; |
|
| 39 | ||
| 40 | /** |
|
| 41 | * Implement form methods |
|
| 42 | */ |
|
| 43 | use TForm; |
|
| 44 | ||
| 45 | /** |
|
| 46 | * @var ORM\EntityManager |
|
| 47 | */ |
|
| 48 | private $entityManager; |
|
| 49 | ||
| 50 | /** |
|
| 51 | * @param ORM\EntityManager $entityManager |
|
| 52 | */ |
|
| 53 | public function injectEntityManager(ORM\EntityManager $entityManager) |
|
| 54 | { |
|
| 55 | $this->entityManager = $entityManager; |
|
| 56 | } |
|
| 57 | ||
| 58 | /** |
|
| 59 | * Adds naming container to the form |
|
| 60 | * |
|
| 61 | * @param string $name |
|
| 62 | * |
|
| 63 | * @return EntityContainer |
|
| 64 | */ |
|
| 65 | public function addContainer($name) : EntityContainer |
|
| 66 | { |
|
| 67 | $control = new EntityContainer($this->entityManager); |
|
| 68 | $control->setCurrentGroup($this->currentGroup); |
|
| 69 | ||
| 70 | return $this[$name] = $control; |
|
| 71 | } |
|
| 72 | ||
| 73 | /** |
|
| 74 | * @return ORM\EntityManager |
|
| 75 | */ |
|
| 76 | protected function getEntityManager() : ORM\EntityManager |
|
| 77 | { |
|
| 78 | return $this->entityManager; |
|
| 79 | } |
|
| 80 | } |
|
| 81 | ||