1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WellCommerce\Bundle\SearchBundle\Service\System\Configuration; |
4
|
|
|
|
5
|
|
|
use WellCommerce\Bundle\AppBundle\Service\System\Configuration\AbstractSystemConfigurator; |
6
|
|
|
use WellCommerce\Component\Form\Elements\FormInterface; |
7
|
|
|
use WellCommerce\Component\Form\FormBuilderInterface; |
8
|
|
|
use WellCommerce\Component\Search\Adapter\Algolia\AlgoliaQueryBuilder; |
9
|
|
|
use WellCommerce\Component\Search\Adapter\SearchAdapterConfiguratorInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class AlgoliaConfigurator |
13
|
|
|
* |
14
|
|
|
* @author Adam Piotrowski <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class AlgoliaConfigurator extends AbstractSystemConfigurator implements SearchAdapterConfiguratorInterface |
17
|
|
|
{ |
18
|
|
|
public function getAlias(): string |
19
|
|
|
{ |
20
|
|
|
return 'algolia'; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function addFormFields(FormBuilderInterface $builder, FormInterface $form) |
24
|
|
|
{ |
25
|
|
|
$algoliaSettings = $form->addChild($builder->getElement('nested_fieldset', [ |
26
|
|
|
'name' => 'algolia', |
27
|
|
|
'label' => 'algolia.fieldset.settings', |
28
|
|
|
])); |
29
|
|
|
|
30
|
|
|
$algoliaSettings->addChild($builder->getElement('tip', [ |
31
|
|
|
'tip' => 'algolia.tip.about', |
32
|
|
|
])); |
33
|
|
|
|
34
|
|
|
$algoliaSettings->addChild($builder->getElement('text_field', [ |
35
|
|
|
'name' => 'appId', |
36
|
|
|
'label' => 'algolia.label.application_id', |
37
|
|
|
]))->setValue($this->getParameter('appId')); |
38
|
|
|
|
39
|
|
|
$algoliaSettings->addChild($builder->getElement('text_field', [ |
40
|
|
|
'name' => 'apiKey', |
41
|
|
|
'label' => 'algolia.label.api_key', |
42
|
|
|
]))->setValue($this->getParameter('apiKey')); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getDefaults(): array |
46
|
|
|
{ |
47
|
|
|
return [ |
48
|
|
|
'appId' => 'C2VGT4PGWH', |
49
|
|
|
'apiKey' => 'b48fb9f6a4eee57f10e3079af095533b', |
50
|
|
|
]; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getSearchAdapterOptions(): array |
54
|
|
|
{ |
55
|
|
|
return [ |
56
|
|
|
'appId' => $this->getParameter('appId'), |
57
|
|
|
'apiKey' => $this->getParameter('apiKey'), |
58
|
|
|
'indexPrefix' => $this->kernel->getContainer()->getParameter('search_index_prefix'), |
59
|
|
|
'termMinLength' => 3, |
60
|
|
|
'maxResults' => 100, |
61
|
|
|
'builderClass' => AlgoliaQueryBuilder::class, |
62
|
|
|
]; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|