-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
81 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusMeilisearchPlugin\Form\Builder; | ||
|
||
use Setono\SyliusMeilisearchPlugin\Document\Attribute\Sortable as SortableAttribute; | ||
use Setono\SyliusMeilisearchPlugin\Document\Metadata\MetadataInterface; | ||
use Setono\SyliusMeilisearchPlugin\Document\Metadata\Sortable; | ||
use Setono\SyliusMeilisearchPlugin\Engine\SearchRequest; | ||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
final class SortingFormBuilder implements SortingFormBuilderInterface | ||
{ | ||
public function build(FormBuilderInterface $searchFormBuilder, MetadataInterface $metadata): void | ||
{ | ||
$choices = []; | ||
foreach ($metadata->getSortableAttributes() as $sortable) { | ||
foreach (self::resolveDirections($sortable) as $direction) { | ||
$choices[sprintf('setono_sylius_meilisearch.form.search.sorting.%s.%s', $sortable->name, $direction)] = sprintf('%s:%s', $sortable->name, $direction); | ||
} | ||
} | ||
$searchFormBuilder->add(SearchRequest::QUERY_PARAMETER_SORT, ChoiceType::class, [ | ||
'choices' => $choices, | ||
'required' => false, | ||
'placeholder' => 'setono_sylius_meilisearch.form.search.sorting.placeholder', | ||
]); | ||
} | ||
|
||
/** | ||
* @return list<string> | ||
*/ | ||
private static function resolveDirections(Sortable $sortable): array | ||
{ | ||
if (null === $sortable->direction) { | ||
return [SortableAttribute::ASC, SortableAttribute::DESC]; | ||
} | ||
|
||
return [$sortable->direction]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusMeilisearchPlugin\Form\Builder; | ||
|
||
use Setono\SyliusMeilisearchPlugin\Document\Metadata\MetadataInterface; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
interface SortingFormBuilderInterface | ||
{ | ||
public function build(FormBuilderInterface $searchFormBuilder, MetadataInterface $metadata): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,9 +89,5 @@ | |
margin: 0 !important; | ||
text-align-last: right; | ||
} | ||
.ssm-sort option { | ||
direction: rtl; | ||
} | ||
</style> | ||
{% endblock %} |