RecipientHandlerManager.php in Simplenews 8.2
File
src/RecipientHandler/RecipientHandlerManager.php
View source
<?php
namespace Drupal\simplenews\RecipientHandler;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\simplenews\Entity\Newsletter;
class RecipientHandlerManager extends DefaultPluginManager {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/simplenews/RecipientHandler', $namespaces, $module_handler, 'Drupal\\simplenews\\RecipientHandler\\RecipientHandlerInterface', 'Drupal\\simplenews\\RecipientHandler\\Annotation\\RecipientHandler');
$this
->alterInfo('simplenews_recipient_handler_info');
$this
->setCacheBackend($cache_backend, 'simplenews_recipient_handler_info_plugins');
}
public function getOptions($newsletter_id = NULL) {
$handlers = $this
->getDefinitions();
$options = [];
foreach ($handlers as $handler => $settings) {
$options[$handler] = Xss::filter($settings['title']);
}
if ($newsletter_id && ($newsletter = Newsletter::load($newsletter_id))) {
$allowed_handlers = array_filter($newsletter->allowed_handlers);
if ($allowed_handlers) {
$options = array_intersect_key($options, $allowed_handlers);
}
}
return $options;
}
}