SolrDeleteCollectionForm.php in Search API Solr 4.x
File
modules/search_api_solr_admin/src/Form/SolrDeleteCollectionForm.php
View source
<?php
namespace Drupal\search_api_solr_admin\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\search_api\ServerInterface;
class SolrDeleteCollectionForm extends SolrAdminFormBase {
public function getFormId() {
return 'solr_delete_collection_form';
}
public function buildForm(array $form, FormStateInterface $form_state, ServerInterface $search_api_server = NULL) {
$this->search_api_server = $search_api_server;
$core = $this->search_api_server
->getBackendConfig()['connector_config']['core'];
$form['#title'] = $this
->t('Delete collection %core?', [
'%core' => $core,
]);
$form['actions'] = [
'submit' => [
'#type' => 'submit',
'#value' => $this
->t('Delete'),
],
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
try {
$this->commandHelper
->deleteCollection($this->search_api_server
->id());
$this->messenger
->addMessage($this
->t('Successfully deleted collection.'));
} catch (\Exception $e) {
$this->messenger
->addError($e
->getMessage());
$this
->logException($e);
}
$form_state
->setRedirect('entity.search_api_server.canonical', [
'search_api_server' => $this->search_api_server
->id(),
]);
}
}