You are here

public function SearchApiAlgoliaBackend::viewSettings in Search API Algolia 3.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php \Drupal\search_api_algolia\Plugin\search_api\backend\SearchApiAlgoliaBackend::viewSettings()
  2. 2.0.x src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php \Drupal\search_api_algolia\Plugin\search_api\backend\SearchApiAlgoliaBackend::viewSettings()

File

src/Plugin/search_api/backend/SearchApiAlgoliaBackend.php, line 180

Class

SearchApiAlgoliaBackend
Class SearchApiAlgoliaBackend.

Namespace

Drupal\search_api_algolia\Plugin\search_api\backend

Code

public function viewSettings() {
  try {
    $this
      ->connect();
  } catch (\Exception $e) {
    $this
      ->getLogger()
      ->warning('Could not connect to Algolia backend.');
  }
  $info = [];

  // Application ID.
  $info[] = [
    'label' => $this
      ->t('Application ID'),
    'info' => $this
      ->getApplicationId(),
  ];

  // API Key.
  $info[] = [
    'label' => $this
      ->t('API Key'),
    'info' => $this
      ->getApiKey(),
  ];

  // Available indexes.
  $indexes = $this
    ->getAlgolia()
    ->listIndices();
  $indexes_list = [];
  if (isset($indexes['items'])) {
    foreach ($indexes['items'] as $index) {
      $indexes_list[] = $index['name'];
    }
  }
  $info[] = [
    'label' => $this
      ->t('Available Algolia indexes'),
    'info' => implode(', ', $indexes_list),
  ];
  return $info;
}