[MODULES][Collection] Fixing mistakes

This commit is contained in:
Phablulo Joel 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 [ return [
'_template' => 'collections/collections.html.twig', '_template' => 'collections/collections.html.twig',
'page_title' => $this->page_title, 'page_title' => $this->page_title,
'list_title' => 'Your ' . $this->plural_slug,
'add_collection' => $create?->createView(), 'add_collection' => $create?->createView(),
'fn' => $fn, 'fn' => $fn,
'collections' => $collections, 'collections' => $collections,

View File

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

View File

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