-
Notifications
You must be signed in to change notification settings - Fork 82
IBX-6878: Customize search sorting #2226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
78e5ed5
Draft "Customize search sorting"
adriendupuis f5c4f78
Custom Search Sorting: Renew example
adriendupuis 8e2e3e8
Custom Search Sorting: Document example
adriendupuis 122496a
Custom Search Sorting: Renew example
adriendupuis 31d6c7f
search_sorting.md: Custom Sort Clauses too
adriendupuis f516ebc
Apply suggestions from code review
adriendupuis d752586
search sorting code sample: move to messages.en.yaml
adriendupuis 7bfa063
Merge branch 'master' into sorting_search_php
adriendupuis 30067c0
search_sorting.md: move to messages.en.yaml
adriendupuis 688d659
Apply suggestions from code review
adriendupuis db33494
Update docs/administration/back_office/search_sorting.md
adriendupuis 5527c36
search_sorting.md → customize_search_sorting.md
adriendupuis 64a548b
Apply suggestions from code review
adriendupuis 59dbadb
Apply suggestions from code review
adriendupuis 33233a7
Merge branch 'master' into sorting_search_php
adriendupuis cc4a2df
customize_search_sorting.md: Fix include_file & hl_lines after merge
adriendupuis af6054c
customize_search_suggestion.md: Fix include_file lines
adriendupuis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
code_samples/back_office/search/config/append_to_services.yaml
This file contains hidden or 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,5 @@ | ||
| services: | ||
|
|
||
| App\Search\SortingDefinition\Provider\SectionNameSortingDefinitionProvider: | ||
| tags: | ||
| - name: ibexa.search.sorting_definition.provider | ||
51 changes: 51 additions & 0 deletions
51
...ice/search/src/Search/SortingDefinition/Provider/SectionNameSortingDefinitionProvider.php
This file contains hidden or 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,51 @@ | ||
| <?php declare(strict_types=1); | ||
|
|
||
| namespace App\Search\SortingDefinition\Provider; | ||
|
|
||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query; | ||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\SortClause; | ||
| use Ibexa\Contracts\Search\SortingDefinition\SortingDefinition; | ||
| use Ibexa\Contracts\Search\SortingDefinition\SortingDefinitionProviderInterface; | ||
| use JMS\TranslationBundle\Model\Message; | ||
| use JMS\TranslationBundle\Translation\TranslationContainerInterface; | ||
| use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
|
||
| final class SectionNameSortingDefinitionProvider implements SortingDefinitionProviderInterface, TranslationContainerInterface | ||
| { | ||
| private TranslatorInterface $translator; | ||
|
|
||
| public function __construct(TranslatorInterface $translator) | ||
| { | ||
| $this->translator = $translator; | ||
| } | ||
|
|
||
| public function getSortingDefinitions(): array | ||
| { | ||
| return [ | ||
| new SortingDefinition( | ||
| 'version_number_asc', | ||
adriendupuis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $this->translator->trans('sort_definition.section_name_asc.label'), | ||
| [ | ||
| new SortClause\SectionName(Query::SORT_ASC), | ||
| ], | ||
| 333 | ||
| ), | ||
| new SortingDefinition( | ||
| 'version_number_desc', | ||
adriendupuis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $this->translator->trans('sort_definition.section_name_desc.label'), | ||
| [ | ||
| new SortClause\SectionName(Query::SORT_DESC), | ||
| ], | ||
| 369 | ||
| ), | ||
| ]; | ||
| } | ||
|
|
||
| public static function getTranslationMessages(): array | ||
| { | ||
| return [ | ||
| (new Message('sort_definition.section_name_asc.label', 'ibexa_search'))->setDesc('Sort by section A-Z'), | ||
| (new Message('sort_definition.section_name_desc.label', 'ibexa_search'))->setDesc('Sort by section Z-A'), | ||
adriendupuis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ]; | ||
| } | ||
| } | ||
2 changes: 2 additions & 0 deletions
2
code_samples/back_office/search/translations/ibexa_search.en.yaml
adriendupuis marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,2 @@ | ||
| sort_definition.section_name_asc.label: 'Sort by section A-Z' | ||
| sort_definition.section_name_desc.label: 'Sort by section Z-A' |
This file contains hidden or 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,26 @@ | ||
| --- | ||
adriendupuis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| description: Add a "sort by" method to the Back Office search result page. | ||
| --- | ||
|
|
||
| # Customize search sorting | ||
|
|
||
| To add an entry to the "Sort by" to the Back Office search result page, create a service implementing the `SortingDefinitionProviderInterface` and tagged `ibexa.search.sorting_definition.provider`. | ||
adriendupuis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The following example class implements `SortingDefinitionProviderInterface::getSortingDefinitions`, and add two definitions to sort by section name. | ||
adriendupuis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| A sorting definition is an identifier, a menu label, a list of [Content Search's Sort Clauses](sort_clause_reference.md#sort-clauses), even [custom ones](create_custom_sort_clause.md), and a priority to position it in the menu. | ||
adriendupuis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| For the menu label, its also implements `TranslationContainerInterface::getTranslationMessages` to provide two default English translations in the `ibexa_search` namespace. | ||
adriendupuis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| This example is coded in `src/Search/SortingDefinition/Provider/SectionNameSortingDefinitionProvider.php`: | ||
adriendupuis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` php hl_lines="22" | ||
| [[= include_file('code_samples/back_office/search/src/Search/SortingDefinition/Provider/SectionNameSortingDefinitionProvider.php') =]] | ||
| ``` | ||
|
|
||
| Its service definition is appended to `config/services.yaml`: | ||
adriendupuis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` yaml hl_lines="5" | ||
| [[= include_file('code_samples/back_office/search/config/append_to_services.yaml') =]] | ||
| ``` | ||
|
|
||
| Translation file can be extracted with a `translation:extract` command, such as `php bin/console translation:extract en --domain=ibexa_search --dir=src --output-dir=translations` to obtain an `translations/ibexa_search.en.xlf` file. | ||
| Or translation file can be manually produced, like the following `translations/ibexa_search.en.yaml`: | ||
| ``` yaml | ||
| [[= include_file('code_samples/back_office/search/translations/ibexa_search.en.yaml') =]] | ||
| ``` | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.