CampaignMonitorUserManager.php in Campaign Monitor 8.2
Namespace
Drupal\campaignmonitor_userFile
modules/campaignmonitor_user/src/CampaignMonitorUserManager.phpView source
<?php
namespace Drupal\campaignmonitor_user;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\campaignmonitor\CampaignMonitorManager;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
/**
* Manager for Campaignmonitor subscriptions.
*/
class CampaignMonitorUserManager extends CampaignMonitorManager {
/**
* The campaignmonitor manager.
*
* @var \Drupal\campaignmonitor\CampaignMonitorManager
*/
protected $campaignMonitorManager;
/**
* Drupal\Core\Config\ConfigFactoryInterface definition.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The language manager service.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* The module manager service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $account;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The constructor.
*
* @param \Drupal\campaignmonitor\CampaignMonitorManager $campaignmonitor_manager
* The campaign monitor manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Session\AccountProxyInterface $account
* The account interface.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(CampaignMonitorManager $campaignmonitor_manager, ConfigFactoryInterface $config_factory, LanguageManagerInterface $language_manager, ModuleHandlerInterface $module_handler, AccountProxyInterface $account, EntityTypeManagerInterface $entity_type_manager) {
$this->campaignMonitorManager = $campaignmonitor_manager;
$this->languageManager = $language_manager;
$this->moduleHandler = $module_handler;
$this->configFactory = $config_factory;
// Get account information.
$this->config = $config_factory
->get('campaignmonitor.settings');
$this->account = $account;
$this->entityTypeManager = $entity_type_manager;
}
/**
* Helper function to get a user's subscriptions.
*
* @param string $email
* The user mail id.
* @param string $format
* Return value depends on format requested.
*
* @return array
* list names.
*/
public function getUserSubscriptions($email, $format = 'checkboxes') {
$lists = $this->campaignMonitorManager
->getLists();
// Build options for the form selector.
$options = [];
$default = [];
foreach ($lists as $list_id => $list) {
// Check if the list is selected to be shown.
// $list_options = $this->campaignMonitorManager
// ->getListSettings($list_id);.
if ($this->campaignMonitorManager
->isListEnabled($list_id)) {
// Check if the user is subscribed to the current list.
$default[$list_id] = 0;
if ($this->campaignMonitorManager
->isSubscribed($list_id, $email)) {
$default[$list_id] = $list_id;
$options[$list_id] = $list['name'];
}
}
}
switch ($format) {
case 'checkboxes':
return $default;
default:
return $options;
}
}
}
Classes
Name | Description |
---|---|
CampaignMonitorUserManager | Manager for Campaignmonitor subscriptions. |