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(), 'indexer' => $this->app['elasticsearch.indexer'] ]); } public function dropIndexAction(Request $request) { $indexer = $this->app['elasticsearch.indexer']; if ($indexer->indexExists()) { $indexer->deleteIndex(); } return $this->app->redirectPath('admin_searchengine_form'); } public function createIndexAction(Request $request) { $indexer = $this->app['elasticsearch.indexer']; if (!$indexer->indexExists()) { $indexer->createIndex(); } return $this->app->redirectPath('admin_searchengine_form'); } /** * @return ElasticsearchOptions */ private function getElasticsearchOptions() { return $this->app['elasticsearch.options']; } /** * @param ElasticsearchOptions $configuration * @return void */ private function saveElasticSearchOptions(ElasticsearchOptions $configuration) { $this->getConf()->set(['main', 'search-engine', 'options'], $configuration->toArray()); } /** * @param ElasticsearchOptions $options * @return FormInterface */ private function getConfigurationForm(ElasticsearchOptions $options) { return $this->app->form(new ElasticsearchSettingsFormType(), $options, [ 'action' => $this->app->url('admin_searchengine_form'), ]); } }