[MODULES][Collection] Fixing mistakes

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

View File

@ -192,6 +192,7 @@ abstract class CollectionController extends FeedController
return [
'_template' => 'collections/collections.html.twig',
'page_title' => $this->page_title,
'list_title' => 'Your ' . $this->plural_slug,
'add_collection' => $create?->createView(),
'fn' => $fn,
'collections' => $collections,

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);
}

View File

@ -19,7 +19,7 @@
</div>
{% endif %}
<div class="h-entry hentry note collections-list">
<h3>{{ 'Your collections' | trans }}</h3>
<h3>{{ list_title | trans }}</h3>
{% for col in collections %}
<div class="collection-item">
<a class="name" href="{{ fn.getUrl(col.id) }}">{{ col.name }}</a>