diff --git a/search_api.install b/search_api.install index 7993da6..1b5b7a1 100644 --- a/search_api.install +++ b/search_api.install @@ -4,6 +4,7 @@ * @file * Install, update and uninstall functions for the Search API module. */ + use Drupal\search_api\Entity\Server; /** @@ -118,10 +119,11 @@ function search_api_requirements($phase) { ), ); } + $servers = Server::loadMultiple(); $unavailable_servers = array(); foreach ($servers as $server) { - if (!$server->isAvailable()) { + if ($server->status() && !$server->isAvailable()) { $unavailable_servers[] = $server->label(); } } @@ -129,11 +131,15 @@ function search_api_requirements($phase) { $requirements += array( 'search_api_server_unavailable' => array( 'title' => t('Search API'), - 'value' => t('The servers: @servers are down.', array('@servers' => implode(',', $unavailable_servers))), + 'value' => \Drupal::translation()->formatPlural( + count($unavailable_servers), + 'The search server "@servers" is currently not available', + 'The following search servers are not available: @servers', + array('@servers' => implode(', ', $unavailable_servers)) + ), 'severity' => REQUIREMENT_ERROR ) ); - } return $requirements; diff --git a/search_api.theme.inc b/search_api.theme.inc index 1bc2378..708e740 100644 --- a/search_api.theme.inc +++ b/search_api.theme.inc @@ -132,17 +132,9 @@ function theme_search_api_server($variables) { $class = 'error'; $info = t('Invalid or missing backend plugin: %backend_id', array('%backend_id' => $server->getBackendId())); } - // Append the row and reset variables. - $label = t('Backend class'); - $rows[] = Utility::deepCopy($row); - $class = ''; - - // Add backend availability information. - $info = $server->isAvailable() ? t('Server is available.') : t('Server is not available.'); - $class = $server->isAvailable() ? 'ok' : 'error'; // Append the row and reset variables. - $label = t('Backend availability'); + $label = t('Backend class'); $rows[] = Utility::deepCopy($row); $class = ''; diff --git a/src/IndexListBuilder.php b/src/IndexListBuilder.php index 3bed36a..e2aafd9 100644 --- a/src/IndexListBuilder.php +++ b/src/IndexListBuilder.php @@ -100,11 +100,15 @@ class IndexListBuilder extends ConfigEntityListBuilder { $row = parent::buildRow($entity); $status = $entity->status(); - if ($entity instanceof ServerInterface && !$entity->isAvailable()) { + $status_server = TRUE; + $status_label = $status ? $this->t('Enabled') : $this->t('Disabled'); + + if ($entity instanceof ServerInterface && $entity->status() && !$entity->isAvailable()) { $status = FALSE; + $status_server = FALSE; + $status_label = $this->t('Unavailable'); } - $status_label = $status ? $this->t('Enabled') : $this->t('Disabled'); $status_icon = array( '#theme' => 'image', '#uri' => $status ? 'core/misc/icons/73b355/check.svg' : 'core/misc/icons/e32700/error.svg', @@ -114,7 +118,7 @@ class IndexListBuilder extends ConfigEntityListBuilder { '#title' => $status_label, ); - return array( + $row = array( 'data' => array( 'type' => array( 'data' => $entity instanceof ServerInterface ? $this->t('Server') : $this->t('Index'), @@ -139,9 +143,14 @@ class IndexListBuilder extends ConfigEntityListBuilder { Html::cleanCssIdentifier($entity->getEntityTypeId() . '-' . $entity->id()), $status ? 'search-api-list-enabled' : 'search-api-list-disabled', $entity instanceof ServerInterface ? 'search-api-list-server' : 'search-api-list-index', - $entity instanceof ServerInterface && !$entity->isAvailable() ? 'color-error' : '', ), ); + + if (!$status_server) { + $row['class'][] = 'color-error'; + } + + return $row; } /** diff --git a/src/Tests/IntegrationTest.php b/src/Tests/IntegrationTest.php index c52e8d9..a127dec 100644 --- a/src/Tests/IntegrationTest.php +++ b/src/Tests/IntegrationTest.php @@ -80,6 +80,7 @@ class IntegrationTest extends WebTestBase { $this->drupalLogin($this->adminUser); $this->createServer(); + $this->checkServerAvailability(); $this->createIndex(); $this->checkContentEntityTracking(); @@ -151,11 +152,6 @@ class IntegrationTest extends WebTestBase { $this->drupalGet('admin/config/search/search-api'); $this->assertHtmlEscaped($server_name); $this->assertHtmlEscaped($server_description); - - // Test that the server view page has a list of useful server information. - $this->assertText($this->t('Backend class')); - $this->assertText($this->t('Backend availability')); - $this->assertText($this->t('Server is available.')); } /** @@ -232,6 +228,24 @@ class IntegrationTest extends WebTestBase { } /** + * Tests the server availability. + */ + protected function checkServerAvailability() { + $this->drupalGet('admin/config/search/search-api/server/' . $this->serverId . '/edit'); + + $this->drupalGet('admin/config/search/search-api'); + $this->assertResponse(200); + $this->assertRaw($this->t('Enabled')); + + \Drupal::state()->set('search_api_test_backend.available', FALSE); + $this->drupalGet('admin/config/search/search-api'); + $this->assertResponse(200); + $this->assertRaw($this->t('Unavailable')); + + \Drupal::state()->set('search_api_test_backend.available', TRUE); + } + + /** * Tests whether the tracking information is properly maintained. * * Will especially test the bundle option of the content entity datasource. diff --git a/tests/search_api_test_backend/src/Plugin/search_api/backend/TestBackend.php b/tests/search_api_test_backend/src/Plugin/search_api/backend/TestBackend.php index cd044f3..7c23e7d 100644 --- a/tests/search_api_test_backend/src/Plugin/search_api/backend/TestBackend.php +++ b/tests/search_api_test_backend/src/Plugin/search_api/backend/TestBackend.php @@ -160,6 +160,13 @@ class TestBackend extends BackendPluginBase { } /** + * {@inheritdoc} + */ + public function isAvailable() { + return \Drupal::state()->get('search_api_test_backend.available', TRUE); + } + + /** * Throws an exception if set in the Drupal state for the given method. * * Also records (successful) calls to these methods.