You are here

public function SearchApiFederatedSolrSearchAppSettingsForm::buildForm in Search API Federated Solr 8

Same name and namespace in other branches
  1. 8.3 src/Form/SearchApiFederatedSolrSearchAppSettingsForm.php \Drupal\search_api_federated_solr\Form\SearchApiFederatedSolrSearchAppSettingsForm::buildForm()
  2. 8.2 src/Form/SearchApiFederatedSolrSearchAppSettingsForm.php \Drupal\search_api_federated_solr\Form\SearchApiFederatedSolrSearchAppSettingsForm::buildForm()
  3. 4.x src/Form/SearchApiFederatedSolrSearchAppSettingsForm.php \Drupal\search_api_federated_solr\Form\SearchApiFederatedSolrSearchAppSettingsForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/SearchApiFederatedSolrSearchAppSettingsForm.php, line 39
Contains \Drupal\search_api_solr_federated\Form\SearchApiFederatedSolrSearchAppSettingsForm.

Class

SearchApiFederatedSolrSearchAppSettingsForm
Class SearchApiFederatedSolrSearchAppSettingsForm.

Namespace

Drupal\search_api_federated_solr\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['#validate'][] = [
    $this,
    'formValidationPathValidate',
  ];
  $config = $this
    ->config('search_api_federated_solr.search_app.settings');
  $index_options = [];
  $search_api_indexes = \Drupal::entityTypeManager()
    ->getStorage('search_api_index')
    ->loadMultiple();

  /* @var  $search_api_index \Drupal\search_api\IndexInterface */
  foreach ($search_api_indexes as $search_api_index) {
    $index_options[$search_api_index
      ->id()] = $search_api_index
      ->label();
  }
  $form['path'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Search app path'),
    '#default_value' => $config
      ->get('path'),
    '#description' => $this
      ->t('The path for the search app (Default: "/search-app").'),
  ];
  $form['page_title'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Search results page title'),
    '#default_value' => $config
      ->get('page_title'),
    '#description' => $this
      ->t('The title that will live in the header tag of the search results page (leave empty to hide completely).'),
  ];
  $form['search_index'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Search API index'),
    '#description' => $this
      ->t('Defines <a href="/admin/config/search/search-api">which search_api index and server</a> the search app should use.'),
    '#options' => $index_options,
    '#default_value' => $config
      ->get('index.id'),
    '#required' => TRUE,
    '#ajax' => [
      'callback' => [
        $this,
        'getSiteName',
      ],
      'event' => 'change',
      'wrapper' => 'site-name-property',
    ],
  ];
  $form['site_name_property'] = [
    '#type' => 'hidden',
    '#attributes' => [
      'id' => [
        'site-name-property',
      ],
    ],
    '#value' => $config
      ->get('index.has_site_name_property') ? 'true' : '',
  ];
  $form['search_index_basic_auth'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Search Index Basic Authentication'),
    '#description' => $this
      ->t('If your Solr server is protected by basic HTTP authentication, enter the login data here. This will be accessible to the client in an obscured, but non-secure method. It should, therefore, only provide read access to the index AND be different from that provided when configuring the server in Search API. The Password field is intentionally not obscured to emphasize this distinction.'),
  ];
  $form['search_index_basic_auth']['username'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Username'),
    '#default_value' => $config
      ->get('index.username'),
  ];
  $form['search_index_basic_auth']['password'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Password'),
    '#default_value' => $config
      ->get('index.password'),
  ];
  $form['set_search_site'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Set the "Site name" facet to this site'),
    '#default_value' => $config
      ->get('facet.site_name.set_default'),
    '#description' => $this
      ->t('When checked, only search results from this site will be shown, by default, until this site\'s checkbox is unchecked in the search app\'s "Site name" facet.'),
    '#states' => [
      'visible' => [
        ':input[name="site_name_property"]' => [
          'value' => "true",
        ],
      ],
    ],
  ];
  $form['show_empty_search_results'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show results for empty search'),
    '#default_value' => $config
      ->get('content.show_empty_search_results'),
    '#description' => $this
      ->t(' When checked, this option allows users to see all results when no search term is entered. By default, empty searches are disabled and yield no results.'),
  ];
  $form['no_results_text'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('No results text'),
    '#default_value' => $config
      ->get('content.no_results'),
    '#description' => $this
      ->t('This text is shown when a query returns no results. (Default: "Your search yielded no results.")'),
  ];
  $form['search_prompt_text'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Search prompt text'),
    '#default_value' => $config
      ->get('content.search_prompt'),
    '#description' => $this
      ->t('This text is shown when no query term has been entered. (Default: "Please enter a search term.")'),
  ];
  $form['rows'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Number of search results per page'),
    '#default_value' => $config
      ->get('results.rows'),
    '#description' => $this
      ->t('The max number of results to render per search results page. (Default: 20)'),
  ];
  $form['page_buttons'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Number of pagination buttons'),
    '#default_value' => $config
      ->get('pagination.buttons'),
    '#description' => $this
      ->t('The max number of numbered pagination buttons to show at a given time. (Default: 5)'),
  ];
  $form['#cache'] = [
    'max-age' => 0,
  ];
  return parent::buildForm($form, $form_state);
}