You are here

function search_api_solr_form_search_api_index_form_validate_server in Search API Solr 8.2

Same name and namespace in other branches
  1. 8.3 search_api_solr.module \search_api_solr_form_search_api_index_form_validate_server()
  2. 8 search_api_solr.module \search_api_solr_form_search_api_index_form_validate_server()
  3. 4.x search_api_solr.module \search_api_solr_form_search_api_index_form_validate_server()
1 string reference to 'search_api_solr_form_search_api_index_form_validate_server'
search_api_solr_form_search_api_index_form_alter in ./search_api_solr.module
Implements hook_form_FORM_alter.

File

./search_api_solr.module, line 324

Code

function search_api_solr_form_search_api_index_form_validate_server(&$element, FormStateInterface $form_state, $form) {
  if ($server = Server::load($form_state
    ->getValue('server'))) {
    if ($server
      ->getBackend() instanceof SolrBackendInterface) {

      /** @var \Drupal\Core\Entity\EntityFormInterface $form_object */
      $form_object = $form_state
        ->getFormObject();
      $this_index = $form_object
        ->getEntity();
      $indexes = $server
        ->getIndexes();
      $index_count = 0;
      foreach ($indexes as $index) {
        if ($index
          ->status()) {
          if (!$this_index
            ->isNew() && $this_index
            ->id() == $index
            ->id()) {
            continue;
          }
          ++$index_count;
        }
      }
      if ($index_count > 0 && $form_state
        ->getValue('status')) {
        \Drupal::messenger()
          ->addWarning(t("You're storing multiple indexes on the same Solr index (aka core). Take care if you use advanced Solr features like spell checking, suggesters, terms, autocomplete and others directly, because they aren't aware of these multiple indexes by default. Use Search API family modules like Autocomplete module instead which will help you to avoid issues."));
      }
    }
  }
}