class CampaignMonitorListsController in Campaign Monitor 8.2
Same name and namespace in other branches
- 8 src/Controller/CampaignMonitorListsController.php \Drupal\campaignmonitor\Controller\CampaignMonitorListsController
Campaign Monitor Lists controller.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\campaignmonitor\Controller\CampaignMonitorListsController implements ContainerInjectionInterface
Expanded class hierarchy of CampaignMonitorListsController
File
- src/
Controller/ CampaignMonitorListsController.php, line 17
Namespace
Drupal\campaignmonitor\ControllerView source
class CampaignMonitorListsController extends ControllerBase implements ContainerInjectionInterface {
/**
* The campaignmonitor manager.
*
* @var \Drupal\campaignmonitor\CampaignMonitorManager
*/
protected $campaignMonitorManager;
/**
* Drupal\Core\Config\ConfigFactoryInterface definition.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* TaxonomyViewsIntegratorManager constructor.
*
* @param \Drupal\campaignmonitor\CampaignMonitorManager $campaignmonitor_manager
* The campaign monitor manager service.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
*/
public function __construct(CampaignMonitorManager $campaignmonitor_manager, ConfigFactoryInterface $config_factory) {
$this->campaignMonitorManager = $campaignmonitor_manager;
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
$campaignmonitor_manager = $container
->get('campaignmonitor.manager');
return new static($campaignmonitor_manager, $container
->get('config.factory'));
}
/**
* {@inheritdoc}
*/
public function overview() {
$content = [];
$lists_admin_url = Url::fromUri('https://waxeye.createsend.com/subscribers/', [
'attributes' => [
'target' => '_blank',
],
]);
$lists_empty_message = $this
->t("You don't have any lists configured in your\n Campaign Monitor account, (or you haven't configured your API key correctly on\n the Global Settings tab). Head over to @link and create some lists, then\n come back here and click 'Refresh lists from Campaign Monitor'", [
'@link' => Link::fromTextAndUrl($this
->t('Campaign Monitor'), $lists_admin_url)
->toString(),
]);
$content['lists_table'] = [
'#type' => 'table',
'#header' => [
$this
->t('Name'),
$this
->t('List ID'),
$this
->t('Subscribed'),
$this
->t('Operations'),
],
'#empty' => $lists_empty_message,
];
$cm_lists = $this->campaignMonitorManager
->getLists();
// $total_webhook_events = count(campaignmonitor_default_webhook_events());
foreach ($cm_lists as $key => $cm_list) {
$stats = $this->campaignMonitorManager
->getListStats($key);
$edit_link = Link::fromTextAndUrl($this
->t('Edit'), Url::fromUri('internal:/admin/config/services/campaignmonitor/list/' . $key . '/edit'))
->toString();
$delete_link = Link::fromTextAndUrl($this
->t('Delete'), Url::fromUri('internal:/admin/config/services/campaignmonitor/list/' . $key . '/delete'))
->toString();
$operations = [
'Edit' => $edit_link,
'Delete' => $delete_link,
];
$list_options = $this->campaignMonitorManager
->getListSettings($key);
if (isset($list_options['status']['enabled']) && !$list_options['status']['enabled']) {
// Add enable operation.
$link = Link::fromTextAndUrl($this
->t('Enable'), Url::fromUri('internal:/admin/config/services/campaignmonitor/list/' . $key . '/enable'))
->toString();
$operations['enable'] = $link;
}
else {
// Add disable operation.
$link = Link::fromTextAndUrl($this
->t('Disable'), Url::fromUri('internal:/admin/config/services/campaignmonitor/list/' . $key . '/disable'))
->toString();
$operations['disable'] = $link;
}
/*$enabled_webhook_events =
count(campaignmonitor_enabled_webhook_events($cm_list->id));
$webhook_url =
Url::fromRoute('campaignmonitor.webhook', ['list_id' => $cm_list->id]);
$webhook_link = Link::fromTextAndUrl('update', $webhook_url);
$webhook_status =
$enabled_webhook_events . ' of ' . $total_webhook_events .
' enabled (' . $webhook_link->toString() . ')';
$list_url = Url::fromUri(
'https://admin.campaignmonitor.com/lists/dashboard/overview?id=' .
$cm_list->id,
['attributes' => ['target' => '_blank']]);*/
$content['lists_table'][$key]['name'] = [
'#markup' => $cm_list['name'],
];
$content['lists_table'][$key]['id'] = [
'#markup' => $key,
];
$content['lists_table'][$key]['stats'] = [
'#markup' => $stats['TotalActiveSubscribers'] . ' / ' . $stats['TotalUnsubscribes'],
];
$content['lists_table'][$key]['operations'] = [
'#markup' => implode(' ', $operations),
];
}
$refresh_url = Url::fromRoute('campaignmonitor.refresh_lists', [
'destination' => 'admin/config/services/campaignmonitor/lists',
]);
$content['refresh'] = [
'#type' => 'container',
];
$content['refresh']['refresh_link'] = [
'#title' => 'Refresh lists from CampaignMonitor',
'#type' => 'link',
'#url' => $refresh_url,
];
return $content;
}
/**
* Enable the list.
*/
public function listEnable($list_id) {
$this
->verifyAccess();
$this
->listToggleEnable($list_id);
$this
->messenger()
->addStatus('list enabled');
return new RedirectResponse('/admin/config/services/campaignmonitor/lists');
}
/**
* Disable the list.
*/
public function listDisable($list_id) {
$this
->verifyAccess();
$this
->listToggleEnable($list_id);
$this
->messenger()
->addStatus('list disabled');
return new RedirectResponse('/admin/config/services/campaignmonitor/lists');
}
/**
* Enables the toggling of list.
*/
private function listToggleEnable($list_id) {
// Get local list information and update enabled state.
$list_options = $this->campaignMonitorManager
->getListSettings($list_id);
$enable = 0;
if (isset($list_options['status']['enabled'])) {
$enable = $list_options['status']['enabled'] == 1 ? 0 : 1;
}
$list_options['status']['enabled'] = $enable;
$list_config = $this->configFactory
->getEditable('campaignmonitor.settings.list');
$list_key = $this->campaignMonitorManager
->listKey($list_id);
$list_config
->set($list_key, $list_options)
->save();
// Clear blocks cache.
// _block_rehash();
}
/**
* Callback to clear config cache.
*/
public function clearListCache() {
$this->campaignMonitorManager
->clearCache();
$this
->messenger()
->addStatus('Campaign Monitor caches cleared');
return new RedirectResponse('/admin/config/services/campaignmonitor/lists');
}
/**
* Verify that a token is set for CSRF protection.
*/
public function verifyAccess() {
// If (!isset($_GET['token']) || !drupal_valid_token($_GET['token'])) {
// drupal_not_found();
// module_invoke_all('exit');
// exit();
// }
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CampaignMonitorListsController:: |
protected | property | The campaignmonitor manager. | |
CampaignMonitorListsController:: |
protected | property |
Drupal\Core\Config\ConfigFactoryInterface definition. Overrides ControllerBase:: |
|
CampaignMonitorListsController:: |
public | function | Callback to clear config cache. | |
CampaignMonitorListsController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
CampaignMonitorListsController:: |
public | function | Disable the list. | |
CampaignMonitorListsController:: |
public | function | Enable the list. | |
CampaignMonitorListsController:: |
private | function | Enables the toggling of list. | |
CampaignMonitorListsController:: |
public | function | ||
CampaignMonitorListsController:: |
public | function | Verify that a token is set for CSRF protection. | |
CampaignMonitorListsController:: |
public | function | TaxonomyViewsIntegratorManager constructor. | |
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity manager. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The form builder. | 2 |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity manager service. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
ControllerBase:: |
protected | function | Returns the state storage service. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |