use Wallabag\CoreBundle\Event\EntrySavedEvent;
use Wallabag\CoreBundle\Form\Type\EditEntryType;
use Wallabag\CoreBundle\Form\Type\EntryFilterType;
+use Wallabag\CoreBundle\Form\Type\EntrySortType;
use Wallabag\CoreBundle\Form\Type\NewEntryType;
use Wallabag\CoreBundle\Form\Type\SearchEntryType;
// defined as null by default because each repository method have the right field as default value too
// like `getBuilderForStarredByUser` will have `starredAt` sort by default
$sortBy = null;
- if (\in_array($request->get('sort', 'createdAt'), ['id', 'title', 'createdAt', 'updatedAt', 'starredAt', 'archivedAt'], true)) {
- $sortBy = $request->get('sort', null);
+ if (\in_array($request->get('entry_sort')['sortType'], ['id', 'title', 'createdAt', 'updatedAt', 'starredAt', 'archivedAt'], true)) {
+ $sortBy = $request->get('entry_sort')['sortType'];
}
- $direction = 'DESC' === $request->get('direction') ? 'DESC' : 'ASC';
+ $direction = isset($request->get('entry_sort')['sortOrder']) ? 'DESC' : 'ASC';
switch ($type) {
case 'search':
}
$form = $this->createForm(EntryFilterType::class);
+ $sortForm = $this->createForm(EntrySortType::class);
if ($request->query->has($form->getName())) {
// manually bind values from the request
$this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($form, $qb);
}
+ if ($request->query->has($sortForm->getName())) {
+ // manually bind values from the request
+ $sortForm->submit($request->query->get($sortForm->getName()));
+ }
+
$pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false);
$entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')->prepare($pagerAdapter);
return $this->render(
'WallabagCoreBundle:Entry:entries.html.twig', [
'form' => $form->createView(),
+ 'sortForm' => $sortForm->createView(),
'entries' => $entries,
'currentPage' => $page,
'searchTerm' => $searchTerm,
--- /dev/null
+<?php
+
+namespace Wallabag\CoreBundle\Form\Type;
+
+use Doctrine\ORM\EntityRepository;
+use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\CheckboxFilterType;
+use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\ChoiceFilterType;
+use Symfony\Component\Form\AbstractType;
+use Symfony\Component\Form\FormBuilderInterface;
+use Symfony\Component\OptionsResolver\OptionsResolver;
+use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
+
+class EntrySortType extends AbstractType
+{
+ private $user;
+
+ public function __construct(TokenStorageInterface $tokenStorage)
+ {
+ $this->user = $tokenStorage->getToken() ? $tokenStorage->getToken()->getUser() : null;
+
+ if (null === $this->user || !\is_object($this->user)) {
+ return;
+ }
+ }
+
+ public function buildForm(FormBuilderInterface $builder, array $options)
+ {
+ $builder
+ ->add('sortOrder', CheckboxFilterType::class)
+ ->add('sortType', ChoiceFilterType::class, [
+ 'choices' => [
+ 'createdAt' => 'createdAt',
+ 'title' => 'title',
+ 'updatedAt' => 'updatedAt',
+ ],
+ 'label' => 'entry.sort.status_label',
+ ])
+ ;
+ }
+
+ public function getBlockPrefix()
+ {
+ return 'entry_sort';
+ }
+
+ public function configureOptions(OptionsResolver $resolver)
+ {
+ $resolver->setDefaults([
+ 'csrf_protection' => false,
+ 'validation_groups' => ['sortering'],
+ ]);
+ }
+}
tags:
- { name: form.type }
+ wallabag_core.sort.type.entry:
+ class: Wallabag\CoreBundle\Form\Type\EntrySortType
+ arguments:
+ - "@security.token_storage"
+ tags:
+ - { name: form.type }
+
wallabag_core.param_converter.username_feed_token_converter:
class: Wallabag\CoreBundle\ParamConverter\UsernameFeedTokenConverter
tags:
{% endif %}
<!-- Sort -->
+ {% if sortForm is not null %}
<div id="sort" class="side-nav right-aligned">
+ <form action="{{ path('all') }}">
<h4 class="center">{{ 'entry.sort.title'|trans }}</h4>
- <div class="row">
- <div class="col s12">
- <label>{{ 'entry.sort.status_label'|trans }}</label>
- </div>
+ <div class="row">
+ <div class="input-field col s6 with-checkbox">
+ {{ form_widget(sortForm.sortType) }}
+ {{ form_label(sortForm.sortType) }}
+ </div>
- <div class="input-field col s12 with-checkbox">
- <select>
- <option value="" disabled selected>Creation date</option>
- <option value="createdAt">{{ 'entry.sort.by.creation_date' | trans }}</option>
- <option value="title">{{ 'entry.sort.by.title' | trans }}</option>
- <option value="updatedAt">{{ 'entry.sort.by.last_updated' | trans }}</option>
- </select>
- </div>
+ <div class="col s12">
+ <div class="switch">
+ <label>Ascendant
+ {{ form_widget(sortForm.sortOrder) }} <span class="lever"></span>
+ Descendant
+ </label>
+ </div>
+ </div>
- <div class="col s12">
- <div class="switch">
- <label>
- Ascendant
- <input type="checkbox">
- <span class="lever"></span>
- Descendant
- </label>
+ <div class="col s12">
+ <button class="btn waves-effect waves-light" type="submit" id="submit-filter" value="filter">{{ 'entry.filters.action.filter'|trans }}</button>
</div>
</div>
- </div>
+ </form>
</div>
-
- {# {% include "WallabagCoreBundle:Entry:pager.html.twig" with {'entries': entries} %} #}
+ {% endif %}
{% endblock %}