NotificationPluginManager.php in Search API Saved Searches 8
File
src/Notification/NotificationPluginManager.php
View source
<?php
namespace Drupal\search_api_saved_searches\Notification;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\search_api_saved_searches\SavedSearchesException;
use Drupal\search_api_saved_searches\SavedSearchTypeInterface;
class NotificationPluginManager extends DefaultPluginManager implements NotificationPluginManagerInterface {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/search_api_saved_searches/notification', $namespaces, $module_handler, 'Drupal\\search_api_saved_searches\\Notification\\NotificationPluginInterface', 'Drupal\\search_api_saved_searches\\Annotation\\SearchApiSavedSearchesNotification');
$this
->setCacheBackend($cache_backend, 'search_api_saved_searches_notification');
$this
->alterInfo('search_api_saved_searches_notification_info');
}
public function createPlugin(SavedSearchTypeInterface $type, $plugin_id, array $configuration = NULL) {
try {
$configuration['#saved_search_type'] = $type;
return $this
->createInstance($plugin_id, $configuration);
} catch (PluginException $e) {
throw new SavedSearchesException("Unknown notification plugin with ID '{$plugin_id}'");
}
}
public function createPlugins(SavedSearchTypeInterface $type, array $plugin_ids = NULL, array $configurations = []) {
if ($plugin_ids === NULL) {
$plugin_ids = array_keys($this
->getDefinitions());
}
$plugins = [];
$type_settings = $type
->get('notification_settings');
foreach ($plugin_ids as $plugin_id) {
$configuration = [];
if (isset($configurations[$plugin_id])) {
$configuration = $configurations[$plugin_id];
}
elseif (isset($type_settings[$plugin_id])) {
$configuration = $type_settings[$plugin_id];
}
$plugins[$plugin_id] = $this
->createPlugin($type, $plugin_id, $configuration);
}
return $plugins;
}
}