AutocompletionConfigurationAddForm.php in Search Autocomplete 2.x
File
src/Form/AutocompletionConfigurationAddForm.php
View source
<?php
namespace Drupal\search_autocomplete\Form;
use Drupal\Core\Form\FormStateInterface;
class AutocompletionConfigurationAddForm extends AutocompletionConfigurationFormBase {
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$selector = '';
if (isset($_REQUEST['selector'])) {
$selector = urldecode($_REQUEST['selector']);
}
$form['selector'] = [
'#type' => 'textfield',
'#title' => $this
->t('ID selector this configuration should apply to'),
'#description' => 'Enter a valid query selector for this configuration. This should be an ID or a class targeting an input field.',
'#default_value' => $selector ? $selector : $this->entity
->getSelector(),
];
return $form;
}
public function save(array $form, FormStateInterface $form_state) {
parent::save($form, $form_state);
$this->entity
->setStatus(TRUE);
$this->entity
->setMinChar(3);
$this->entity
->setMaxSuggestions(10);
$this->entity
->setAutoSubmit(TRUE);
$this->entity
->setAutoRedirect(TRUE);
$this->entity
->setMoreResultsLabel($this
->t('View all results for [search-phrase].'));
$this->entity
->setMoreResultsValue($this
->t('[search-phrase]'));
$this->entity
->setMoreResultsLink('');
$this->entity
->setNoResultLabel($this
->t('No results found for [search-phrase]. Click to perform full search.'));
$this->entity
->setNoResultValue($this
->t('[search-phrase]'));
$this->entity
->setNoResultLink('');
$this->entity
->setSource('autocompletion_callbacks_nodes::nodes_autocompletion_callback');
$this->entity
->setTheme('basic-blue.css');
$this->entity
->setEditable(TRUE);
$this->entity
->setDeletable(TRUE);
$this->entity
->save();
$form_state
->setRedirectUrl($this->entity
->toUrl('edit-form'));
}
protected function actions(array $form, FormStateInterface $form_state) {
$actions = parent::actions($form, $form_state);
$actions['submit']['#value'] = $this
->t('Create Autocompletion Configuration');
return $actions;
}
}