class ConfigSubscriber in Search API Solr 8.2
Same name and namespace in other branches
- 8.3 src/EventSubscriber/ConfigSubscriber.php \Drupal\search_api_solr\EventSubscriber\ConfigSubscriber
- 4.x src/EventSubscriber/ConfigSubscriber.php \Drupal\search_api_solr\EventSubscriber\ConfigSubscriber
Provides a ConfigSubscriber that adds language-specific Solr Field Types.
Whenever a new language is enabled this EventSubscriber installs all available Solr Field Types for that language.
Hierarchy
- class \Drupal\search_api_solr\EventSubscriber\ConfigSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of ConfigSubscriber
1 string reference to 'ConfigSubscriber'
1 service uses ConfigSubscriber
File
- src/
EventSubscriber/ ConfigSubscriber.php, line 16
Namespace
Drupal\search_api_solr\EventSubscriberView source
class ConfigSubscriber implements EventSubscriberInterface {
/**
* @var \Drupal\Core\Config\ConfigInstallerInterface
*/
protected $configInstaller;
/**
* @param \Drupal\Core\Config\ConfigInstallerInterface $configInstaller
* The Config Installer.
*/
public function __construct(ConfigInstallerInterface $configInstaller) {
$this->configInstaller = $configInstaller;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[ConfigEvents::SAVE][] = [
'onConfigSave',
];
return $events;
}
/**
* Installs all available Solr Field Types for a new language.
*
* @param \Drupal\Core\Config\ConfigCrudEvent $event
*/
public function onConfigSave(ConfigCrudEvent $event) {
$saved_config = $event
->getConfig();
if (preg_match('@^language\\.entity\\.(.+)@', $saved_config
->getName(), $matches) && $matches[1] != 'und') {
$restrict_by_dependency = [
'module' => 'search_api_solr',
];
// installOptionalConfig will not replace existing configs and it contains
// a dependency check so we need not perform any checks ourselves.
$this->configInstaller
->installOptionalConfig(NULL, $restrict_by_dependency);
}
// @todo alert to trigger new config when an index is added => context
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigSubscriber:: |
protected | property | ||
ConfigSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
ConfigSubscriber:: |
public | function | Installs all available Solr Field Types for a new language. | |
ConfigSubscriber:: |
public | function |