Firesphere /
silverstripe-fluent-solr
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Class FluentIndexExtension|Firesphere\SolrFluent\Extensions\FluentIndexExtension Add Fluent locales to the index |
||
| 4 | * |
||
| 5 | * @package Firesphere\Solr\Fluent |
||
| 6 | * @author Simon `Firesphere` Erkelens; Marco `Sheepy` Hermo |
||
| 7 | * @copyright Copyright (c) 2018 - now() Firesphere & Sheepy |
||
| 8 | */ |
||
| 9 | |||
| 10 | namespace Firesphere\SolrFluent\Extensions; |
||
| 11 | |||
| 12 | use Firesphere\SolrSearch\Indexes\BaseIndex; |
||
| 13 | use Firesphere\SolrSearch\Queries\BaseQuery; |
||
| 14 | use Firesphere\SolrSearch\States\SiteState; |
||
| 15 | use SilverStripe\Core\Extension; |
||
| 16 | use Solarium\QueryType\Select\Query\Query; |
||
| 17 | use TractorCow\Fluent\Model\Locale; |
||
| 18 | use TractorCow\Fluent\State\FluentState; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Support for Fluent translations in the index. |
||
| 22 | * |
||
| 23 | * |
||
| 24 | * @package Firesphere\Solr\Fluent |
||
| 25 | * @property BaseIndex|FluentIndexExtension $owner |
||
| 26 | */ |
||
| 27 | class FluentIndexExtension extends Extension |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * Add the fluent states |
||
| 31 | */ |
||
| 32 | 2 | public function onBeforeInit() |
|
| 33 | { |
||
| 34 | 2 | $locales = Locale::get(); |
|
| 35 | 2 | SiteState::addStates($locales->column('Locale')); |
|
| 36 | 2 | } |
|
| 37 | |||
| 38 | /** |
||
| 39 | * Add the needed language copy fields to Solr |
||
| 40 | */ |
||
| 41 | 2 | public function onAfterInit(): void |
|
| 42 | { |
||
| 43 | 2 | $locales = Locale::get(); |
|
| 44 | /** @var BaseIndex $owner */ |
||
| 45 | 2 | $owner = $this->owner; |
|
| 46 | 2 | $copyFields = $owner->getCopyFields(); |
|
| 47 | /** @var Locale $locale */ |
||
| 48 | 2 | foreach ($locales as $locale) { |
|
| 49 | 2 | foreach ($copyFields as $copyField => $values) { |
|
| 50 | 2 | $owner->addCopyField($locale->Locale . $copyField, $values); |
|
| 51 | } |
||
| 52 | } |
||
| 53 | 2 | } |
|
| 54 | |||
| 55 | /** |
||
| 56 | * Set to the correct language to search if needed |
||
| 57 | * |
||
| 58 | * @param BaseQuery $query |
||
| 59 | * @param Query $clientQuery |
||
| 60 | */ |
||
| 61 | 1 | public function onBeforeSearch($query, $clientQuery): void |
|
|
0 ignored issues
–
show
|
|||
| 62 | { |
||
| 63 | 1 | $locale = FluentState::singleton()->getLocale(); |
|
| 64 | 1 | $defaultField = $clientQuery->getQueryDefaultField() ?: '_text'; |
|
| 65 | 1 | $clientQuery->setQueryDefaultField($locale . $defaultField); |
|
| 66 | 1 | } |
|
| 67 | } |
||
| 68 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.