Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment thread
adriendupuis marked this conversation as resolved.
Outdated
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',
Comment thread
adriendupuis marked this conversation as resolved.
Outdated
$this->translator->trans('sort_definition.section_name_asc.label'),
[
new SortClause\SectionName(Query::SORT_ASC),
],
333
),
new SortingDefinition(
'version_number_desc',
Comment thread
adriendupuis marked this conversation as resolved.
Outdated
$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'),
Comment thread
adriendupuis marked this conversation as resolved.
Outdated
];
}
}
Comment thread
adriendupuis marked this conversation as resolved.
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'
26 changes: 26 additions & 0 deletions docs/administration/back_office/search_sorting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
Comment thread
adriendupuis marked this conversation as resolved.
Outdated
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`.
Comment thread
adriendupuis marked this conversation as resolved.
Outdated

The following example class implements `SortingDefinitionProviderInterface::getSortingDefinitions`, and add two definitions to sort by section name.
Comment thread
adriendupuis marked this conversation as resolved.
Outdated
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.
Comment thread
adriendupuis marked this conversation as resolved.
Outdated
For the menu label, its also implements `TranslationContainerInterface::getTranslationMessages` to provide two default English translations in the `ibexa_search` namespace.
Comment thread
adriendupuis marked this conversation as resolved.
Outdated
This example is coded in `src/Search/SortingDefinition/Provider/SectionNameSortingDefinitionProvider.php`:
Comment thread
adriendupuis marked this conversation as resolved.
Outdated
``` 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`:
Comment thread
adriendupuis marked this conversation as resolved.
Outdated
``` 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') =]]
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ nav:
- Multi-file upload: administration/back_office/multifile_upload.md
- Sub-items list: administration/back_office/subitems_list.md
- Notifications: administration/back_office/notifications.md
- Customize search sorting: administration/back_office/search_sorting.md
Comment thread
adriendupuis marked this conversation as resolved.
Outdated
- Content management:
- Content management: content_management/content_management.md
- Content management guide: content_management/content_management_guide.md
Expand Down