Skip to content

Commit 90c6228

Browse files
authored
Merge pull request #58 from Setono/position-to-facet
Add position property to facets to make it easy to change the order in which they are rendered
2 parents 78d8d2b + 66d0028 commit 90c6228

File tree

7 files changed

+7
-2
lines changed

7 files changed

+7
-2
lines changed

src/Document/Attribute/Facetable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class Facetable extends Filterable
1616
*
1717
* @param class-string<FilterValuesSorterInterface>|null $sorter
1818
*/
19-
public function __construct(public readonly ?string $sorter = null)
19+
public function __construct(public readonly int $position = 0, public readonly ?string $sorter = null)
2020
{
2121
if ($this->sorter === null) {
2222
return;

src/Document/Metadata/Facet.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ final class Facet
1212
public function __construct(
1313
public readonly string $name,
1414
public readonly string $type,
15+
public readonly int $position = 0,
1516
public readonly ?string $sorter = null,
1617
) {
1718
}

src/Document/Metadata/Metadata.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ private function loadAttributes(\ReflectionProperty|\ReflectionMethod $attribute
8989
$this->facetableAttributes[$name] = new Facet(
9090
$name,
9191
self::getFacetType($attributesAware),
92+
$attribute->position,
9293
$attribute->sorter ?? null,
9394
);
9495
}

src/Form/Builder/CheckboxFilterFormBuilder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function build(FormBuilderInterface $builder, Facet $facet, array $values
2020
],
2121
'required' => false,
2222
'block_prefix' => 'setono_sylius_meilisearch_facet_checkbox',
23+
'priority' => -1 * $facet->position,
2324
]);
2425
}
2526

src/Form/Builder/ChoiceFilterFormBuilder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function build(FormBuilderInterface $builder, Facet $facet, array $values
3232
'multiple' => true,
3333
'required' => false,
3434
'block_prefix' => 'setono_sylius_meilisearch_facet_choice',
35+
'priority' => -1 * $facet->position,
3536
]);
3637
}
3738

src/Form/Builder/RangeFilterFormBuilder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function build(FormBuilderInterface $builder, Facet $facet, array $values
1717
'label' => sprintf('setono_sylius_meilisearch.form.search.facet.%s', u($facet->name)->snake()),
1818
'required' => false,
1919
'block_prefix' => 'setono_sylius_meilisearch_facet_range',
20+
'priority' => -1 * $facet->position,
2021
]);
2122
}
2223

tests/Application/Document/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
final class Product extends BaseProduct
1414
{
1515
/** @var list<string> */
16-
#[Facetable(sorter: SizeSorter::class)]
16+
#[Facetable(position: -1, sorter: SizeSorter::class)]
1717
#[MapProductOption(['t_shirt_size', 'dress_size', 'jeans_size'])]
1818
public array $size = [];
1919

0 commit comments

Comments
 (0)