class ConfigEventsSubscriber in Open Social 8.8
Same name and namespace in other branches
- 8.9 modules/social_features/social_profile/modules/social_profile_privacy/src/EventSubscriber/ConfigEventsSubscriber.php \Drupal\social_profile_privacy\EventSubscriber\ConfigEventsSubscriber
- 8.7 modules/social_features/social_profile/modules/social_profile_privacy/src/EventSubscriber/ConfigEventsSubscriber.php \Drupal\social_profile_privacy\EventSubscriber\ConfigEventsSubscriber
- 10.3.x modules/social_features/social_profile/modules/social_profile_privacy/src/EventSubscriber/ConfigEventsSubscriber.php \Drupal\social_profile_privacy\EventSubscriber\ConfigEventsSubscriber
- 10.0.x modules/social_features/social_profile/modules/social_profile_privacy/src/EventSubscriber/ConfigEventsSubscriber.php \Drupal\social_profile_privacy\EventSubscriber\ConfigEventsSubscriber
- 10.1.x modules/social_features/social_profile/modules/social_profile_privacy/src/EventSubscriber/ConfigEventsSubscriber.php \Drupal\social_profile_privacy\EventSubscriber\ConfigEventsSubscriber
- 10.2.x modules/social_features/social_profile/modules/social_profile_privacy/src/EventSubscriber/ConfigEventsSubscriber.php \Drupal\social_profile_privacy\EventSubscriber\ConfigEventsSubscriber
Class ConfigEventSubscriber.
@package Drupal\social_profile_privacy\EventSubscriber
Hierarchy
- class \Drupal\social_profile_privacy\EventSubscriber\ConfigEventsSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of ConfigEventsSubscriber
1 string reference to 'ConfigEventsSubscriber'
- social_profile_privacy.services.yml in modules/
social_features/ social_profile/ modules/ social_profile_privacy/ social_profile_privacy.services.yml - modules/social_features/social_profile/modules/social_profile_privacy/social_profile_privacy.services.yml
1 service uses ConfigEventsSubscriber
- social_profile_privacy.config_events_subscriber in modules/
social_features/ social_profile/ modules/ social_profile_privacy/ social_profile_privacy.services.yml - Drupal\social_profile_privacy\EventSubscriber\ConfigEventsSubscriber
File
- modules/
social_features/ social_profile/ modules/ social_profile_privacy/ src/ EventSubscriber/ ConfigEventsSubscriber.php, line 17
Namespace
Drupal\social_profile_privacy\EventSubscriberView source
class ConfigEventsSubscriber implements EventSubscriberInterface {
/**
* The Drupal module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The Drupal entity type handler.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* A way for this module to log messages.
*
* @var \Drupal\Core\Logger\LoggerChannelInterface
*/
protected $logger;
/**
* ConfigEventsSubscriber constructor.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The Drupal module handler service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The Drupal entity type handler.
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_channel_factory
* A way for this module to log messages.
*/
public function __construct(ModuleHandlerInterface $module_handler, EntityTypeManagerInterface $entity_type_manager, LoggerChannelFactoryInterface $logger_channel_factory) {
$this->moduleHandler = $module_handler;
$this->entityTypeManager = $entity_type_manager;
$this->logger = $logger_channel_factory
->get('social_profile_privacy');
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
ConfigEvents::SAVE => 'configSave',
];
}
/**
* React to a config object being saved.
*
* @param \Drupal\Core\Config\ConfigCrudEvent $event
* Config crud event.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @throws \Drupal\search_api\SearchApiException
*/
public function configSave(ConfigCrudEvent $event) {
// A list of configuration changes that trigger an index update.
$triggers = [
'social_profile_privacy.settings' => 'limit_search_and_mention',
'social_profile_fields.settings' => 'profile_profile_field_profile_nick_name',
];
// If the config that changed is part of our trigger list and the value that
// changed is one we're interested in, perform the re-index.
$config_name = $event
->getConfig()
->getName();
if (isset($triggers[$config_name]) && $event
->isChanged($triggers[$config_name])) {
$this
->invalidateSearchIndices();
}
}
/**
* Invalidates the search indices for every index that uses profile data.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @throws \Drupal\search_api\SearchApiException
*/
protected function invalidateSearchIndices() : void {
// If the search api module is not installed we have nothing to do.
if (!$this->moduleHandler
->moduleExists('search_api')) {
return;
}
// We load all indexes, we assume there will never be hundreds of search
// indexes which would create its own problems for a site.
$indexes = $this->entityTypeManager
->getStorage('search_api_index')
->loadMultiple();
/** @var \Drupal\search_api\IndexInterface $index */
foreach ($indexes as $index) {
// Check if the search index has profile entities as data source.
if ($index
->isValidDatasource('entity:profile')) {
// Mark any indexed items based on profile entities as having changed so
// they are re-indexed.
$index
->getTrackerInstance()
->trackAllItemsUpdated('entity:profile');
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigEventsSubscriber:: |
protected | property | The Drupal entity type handler. | |
ConfigEventsSubscriber:: |
protected | property | A way for this module to log messages. | |
ConfigEventsSubscriber:: |
protected | property | The Drupal module handler service. | |
ConfigEventsSubscriber:: |
public | function | React to a config object being saved. | |
ConfigEventsSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
ConfigEventsSubscriber:: |
protected | function | Invalidates the search indices for every index that uses profile data. | |
ConfigEventsSubscriber:: |
public | function | ConfigEventsSubscriber constructor. |