mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-10 11:33:17 +00:00
Add Form for ElasticSearch Configuration.
Also changed type from array to Options object.
This commit is contained in:
@@ -10,37 +10,62 @@
|
||||
|
||||
namespace Alchemy\Phrasea\Controller\Admin;
|
||||
|
||||
use Alchemy\Phrasea\SearchEngine\ConfigurationPanelInterface;
|
||||
use Alchemy\Phrasea\Controller\Controller;
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\ElasticSearchSettingFormType;
|
||||
use Alchemy\Phrasea\SearchEngine\Elastic\GlobalElasticOptions;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class SearchEngineController
|
||||
class SearchEngineController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var ConfigurationPanelInterface
|
||||
*/
|
||||
private $configurationPanel;
|
||||
|
||||
public function __construct(ConfigurationPanelInterface $configurationPanel)
|
||||
{
|
||||
$this->configurationPanel = $configurationPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function getConfigurationPanelAction(Request $request)
|
||||
public function formConfigurationPanelAction(Request $request)
|
||||
{
|
||||
return $this->configurationPanel->get($request);
|
||||
$options = $this->getElasticSearchOptions();
|
||||
$form = $this->getConfigurationForm($options);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
$this->saveElasticSearchOptions($form->getData());
|
||||
|
||||
return $this->app->redirectPath('admin_searchengine_form');
|
||||
}
|
||||
|
||||
return $this->render('admin/search-engine/elastic-search.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
* @return GlobalElasticOptions
|
||||
*/
|
||||
public function postConfigurationPanelAction(Request $request)
|
||||
private function getElasticSearchOptions()
|
||||
{
|
||||
return $this->configurationPanel->post($request);
|
||||
return $this->app['elasticsearch.options'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GlobalElasticOptions $configuration
|
||||
* @return void
|
||||
*/
|
||||
private function saveElasticSearchOptions(GlobalElasticOptions $configuration)
|
||||
{
|
||||
$this->getConf()->set(['main', 'search-engine', 'options'], $configuration->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GlobalElasticOptions $options
|
||||
* @return FormInterface
|
||||
*/
|
||||
private function getConfigurationForm(GlobalElasticOptions $options)
|
||||
{
|
||||
return $this->app->form(new ElasticSearchSettingFormType(), $options, [
|
||||
'action' => $this->app->url('admin_searchengine_form'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user