public static function Database::create in Search API 8
Creates an instance of the plugin.
Parameters
\Symfony\Component\DependencyInjection\ContainerInterface $container: The container to pull out services used in the plugin.
array $configuration: A configuration array containing information about the plugin instance.
string $plugin_id: The plugin ID for the plugin instance.
mixed $plugin_definition: The plugin implementation definition.
Return value
static Returns an instance of this plugin.
Overrides BackendPluginBase::create
1 call to Database::create()
- BackendTest::testNonDefaultDatabase in modules/
search_api_db/ tests/ src/ Kernel/ BackendTest.php - Tests whether a server on a non-default database is handled correctly.
File
- modules/
search_api_db/ src/ Plugin/ search_api/ backend/ Database.php, line 197
Class
- Database
- Indexes and searches items using the database.
Namespace
Drupal\search_api_db\Plugin\search_api\backendCode
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
/** @var static $backend */
$backend = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$backend
->setModuleHandler($container
->get('module_handler'));
$backend
->setConfigFactory($container
->get('config.factory'));
$backend
->setDataTypePluginManager($container
->get('plugin.manager.search_api.data_type'));
$backend
->setLogger($container
->get('logger.channel.search_api_db'));
$backend
->setKeyValueStore($container
->get('keyvalue')
->get(self::INDEXES_KEY_VALUE_STORE_ID));
$backend
->setDateFormatter($container
->get('date.formatter'));
$backend
->setEventDispatcher($container
->get('event_dispatcher'));
$backend
->setDataTypeHelper($container
->get('search_api.data_type_helper'));
// For a new backend plugin, the database might not be set yet. In that case
// we of course also don't need a DBMS compatibility handler.
$database = $backend
->getDatabase();
if ($database) {
$dbms_compatibility_handler = $container
->get('search_api_db.database_compatibility');
// Make sure that we actually provide a handler for the right database,
// otherwise create the right service manually. (This is the case if the
// user didn't pick the default database.)
if ($dbms_compatibility_handler
->getDatabase() != $database) {
$database_type = $database
->databaseType();
$service_id = "{$database_type}.search_api_db.database_compatibility";
if ($container
->has($service_id)) {
/** @var \Drupal\search_api_db\DatabaseCompatibility\DatabaseCompatibilityHandlerInterface $dbms_compatibility_handler */
$dbms_compatibility_handler = $container
->get($service_id);
$dbms_compatibility_handler = $dbms_compatibility_handler
->getCloneForDatabase($database);
}
else {
$dbms_compatibility_handler = new GenericDatabase($database, $container
->get('transliteration'));
}
}
$backend
->setDbmsCompatibilityHandler($dbms_compatibility_handler);
}
return $backend;
}