[MODULES][Collection] Fixing mistakes

This commit is contained in:
2021-12-30 12:16:29 -03:00
parent bdd8cbf36d
commit 85e31c684d
3 changed files with 8 additions and 4 deletions

View File

@@ -76,6 +76,9 @@ abstract class Collection extends Plugin
foreach ($collections as $col) {
$choices[$col->getName()] = $col->getId();
}
$collections = array_map(fn ($x) => $x->getId(), $collections);
$already_selected = $this->getCollectionsBy($user, $vars, true);
$add_form = Form::create([
['collections', ChoiceType::class, [
@@ -98,9 +101,9 @@ abstract class Collection extends Plugin
]);
$add_form->handleRequest($request);
if ($add_form->isSubmitted() && $add_form->isValid()) {
$collections = $add_form->getData()['collections'];
$removed = array_filter($already_selected, fn ($x) => !\in_array($x, $collections));
$added = array_filter($collections, fn ($x) => !\in_array($x, $already_selected));
$selected = $add_form->getData()['collections'];
$removed = array_filter($already_selected, fn ($x) => !\in_array($x, $selected));
$added = array_filter($selected, fn ($x) => !\in_array($x, $already_selected));
if (\count($removed) > 0) {
$this->removeItems($user, $vars, $removed, $collections);
}