Commit 9e01591c authored by borisson_'s avatar borisson_ Committed by borisson_

Issue #2877989 by borisson_: Module depends on a search api service and it shouldn't

parent b71005a2
......@@ -6,7 +6,7 @@ use Drupal\Component\Utility\Unicode;
use Drupal\Core\Language\LanguageInterface;
use Drupal\search_api\Item\Field;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Tests\TaxonomyTestTrait;
use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\Tests\facets\Functional\FacetsTestBase;
......
......@@ -49,4 +49,23 @@ class FacetSourcePluginManager extends DefaultPluginManager {
}
}
/**
* {@inheritdoc}
*/
protected function findDefinitions() {
$defs = parent::findDefinitions();
// Definitions that are based on search api when search api is not enabled
// should not exist, so make sure we do exactly that, we do this in
// ::findDefinitions because this one is called before the result is saved.
$defs = array_filter($defs, function($item) {
if ($item['id'] === 'search_api' && !$this->moduleHandler->moduleExists('search_api')) {
return FALSE;
}
return TRUE;
});
return $defs;
}
}
......@@ -87,6 +87,13 @@ class SearchApiDisplay extends FacetSourcePluginBase implements SearchApiFacetSo
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
// If the Search API module is not enabled, we should just return an empty
// object. This allows us to have this class in the module without having a
// dependency on the Search API module.
if (!$container->get('module_handler')->moduleExists('search_api')) {
return new \stdClass();
}
return new static(
$configuration,
$plugin_id,
......
......@@ -6,8 +6,8 @@ use Drupal\Component\Utility\Unicode;
use Drupal\Core\Language\LanguageInterface;
use Drupal\search_api\Item\Field;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Tests\TaxonomyTestTrait;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait;
/**
* Tests the hierarchical facets implementation.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment