You are here

public function SearchApiAlgoliaBackend::viewSettings in Search API Algolia 8

Same name and namespace in other branches
  1. 3.0.x 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()

Returns additional, backend-specific information about this server.

This information will be then added to the server's "View" tab in some way. In the default theme implementation the data is output in a table with two columns along with other, generic information about the server.

Return value

array An array of additional server information, with each piece of information being an associative array with the following keys:

  • label: The human-readable label for this data.
  • info: The information, as HTML.
  • status: (optional) The status associated with this information. One of "info", "ok", "warning" or "error". Defaults to "info".

Overrides BackendPluginBase::viewSettings

File

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

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()
    ->listIndexes();
  $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;
}