class CampaignMonitorListsController in Campaign Monitor 8
Same name and namespace in other branches
- 8.2 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
Expanded class hierarchy of CampaignMonitorListsController
File
- src/
Controller/ CampaignMonitorListsController.php, line 13
Namespace
Drupal\campaignmonitor\ControllerView source
class CampaignMonitorListsController extends ControllerBase {
/**
* {@inheritdoc}
*/
public function overview() {
$content = [];
$lists_admin_url = Url::fromUri('https://waxeye.createsend.com/subscribers/', [
'attributes' => [
'target' => '_blank',
],
]);
$lists_empty_message = t('You don\'t have any lists configured in your
Campaign Monitor account, (or you haven\'t configured your API key correctly on
the Global Settings tab). Head over to @link and create some lists, then
come back here and click "Refresh lists from Campaign Monitor"', [
'@link' => Link::fromTextAndUrl(t('Campaign Monitor'), $lists_admin_url)
->toString(),
]);
$content['lists_table'] = [
'#type' => 'table',
'#header' => [
t('Name'),
t('List ID'),
t('Subscribed'),
t('Operations'),
],
'#empty' => $lists_empty_message,
];
$cm_lists = campaignmonitor_get_lists();
// $total_webhook_events = count(campaignmonitor_default_webhook_events());
foreach ($cm_lists as $key => $cm_list) {
$details = campaignmonitor_get_list_details($key);
$stats = campaignmonitor_get_list_stats($key);
$edit_link = Link::fromTextAndUrl(t('Edit'), Url::fromUri('internal:/admin/config/services/campaignmonitor/list/' . $key . '/edit'))
->toString();
$delete_link = Link::fromTextAndUrl(t('Delete'), Url::fromUri('internal:/admin/config/services/campaignmonitor/list/' . $key . '/delete'))
->toString();
$operations = [
'Edit' => $edit_link,
'Delete' => $delete_link,
];
$list_options = campaignmonitor_get_list_settings($key);
if (isset($list_options['status']['enabled']) && !$list_options['status']['enabled']) {
// Add enable operation.
$class = 'campaignmonitor-list-disabled';
$link = Link::fromTextAndUrl(t('Enable'), Url::fromUri('internal:/admin/config/services/campaignmonitor/list/' . $key . '/enable'))
->toString();
$operations['enable'] = $link;
}
else {
// Add disable operation.
$class = 'campaignmonitor-list-enabled';
$link = Link::fromTextAndUrl(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', array('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, array('attributes' => array('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,
];
$create_url = Url::fromRoute('campaignmonitor.list_create_form', [
'destination' => 'admin/config/services/campaignmonitor/lists',
]);
$content['create'] = [
'#type' => 'container',
];
$content['create']['create_link'] = [
'#title' => 'Create a new list',
'#type' => 'link',
'#url' => $create_url,
];
return $content;
}
/**
*
*/
public function listEnable($list_id) {
$this
->verifyAccess();
$this
->listToggleEnable($list_id);
drupal_set_message('list enabled');
return new RedirectResponse('/admin/config/services/campaignmonitor/lists');
}
/**
*
*/
public function listDisable($list_id) {
$this
->verifyAccess();
$this
->listToggleEnable($list_id);
drupal_set_message('list disabled');
return new RedirectResponse('/admin/config/services/campaignmonitor/lists');
}
/**
*
*/
private function listToggleEnable($list_id) {
// Get local list information and update enabled state.
$list_options = campaignmonitor_get_list_settings($list_id);
$enable = 0;
if (isset($list_options['status']['enabled'])) {
$enable = $list_options['status']['enabled'] == 1 ? 0 : 1;
}
$list_options['status']['enabled'] = $enable;
campaignmonitor_set_list_settings($list_id, $list_options);
// Clear blocks cache.
// _block_rehash();
}
/**
* Callback to clear config cache.
*/
public function clearListCache() {
$caches = [
'cache.config',
'cache.data',
];
campaignmonitor_clear_cache($caches);
drupal_set_message('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:: |
public | function | Callback to clear config cache. | |
CampaignMonitorListsController:: |
public | function | ||
CampaignMonitorListsController:: |
public | function | ||
CampaignMonitorListsController:: |
private | function | ||
CampaignMonitorListsController:: |
public | function | ||
CampaignMonitorListsController:: |
public | function | Verify that a token is set for CSRF protection. | |
ControllerBase:: |
protected | property | The configuration factory. | |
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:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
40 |
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. |