Skip to content

Commit e922901

Browse files
committed
Allow to change the managed departments directly from the confirmers page
1 parent b6e2d7b commit e922901

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Controller/Admin/ConfirmerCrudController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public function configureFields(string $pageName): iterable
5858
->setEmptyData('')
5959
->hideOnIndex(),
6060
AssociationField::new('departments', new TM('confirmer.departments'))
61+
->setFormTypeOption('by_reference', false)
6162
->autocomplete()
6263

6364
];

src/Entity/Confirmer.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,28 @@ public function getDepartments(): Collection
131131
return $this->departments;
132132
}
133133

134+
public function addDepartment(Department $department): Confirmer
135+
{
136+
if (!$this->departments->contains($department)) {
137+
$this->departments->add($department);
138+
if (!$department->getConfirmers()->contains($this)) {
139+
$department->getConfirmers()->add($this);
140+
}
141+
}
142+
return $this;
143+
}
144+
145+
public function removeDepartment(Department $department): Confirmer
146+
{
147+
if ($this->departments->contains($department)) {
148+
$this->departments->removeElement($department);
149+
if ($department->getConfirmers()->contains($this)) {
150+
$department->getConfirmers()->removeElement($this);
151+
}
152+
}
153+
return $this;
154+
}
155+
134156
public function __toString()
135157
{
136158
return $this->name . ' (' . $this->email . ')';

0 commit comments

Comments
 (0)