public function CampaignMonitor::getLists in Campaign Monitor 8
Gets all lists from Campaign Monitor found under the client ID given during object creation. The list is returned as a keyed array and cached in the cache table, so it may not always return the newest information.
The array has the format below. Be aware that the same cache is used for the getListDetails() and getCustomFields() functions. This means that the information returned by this function may contain an extended list of information if any of these functions have been called.
$list[$id] = array( 'name' => 'List name', );
Return value
array | FALSE An array of lists available from Campaign Monitor or FALSE on failure.
3 calls to CampaignMonitor::getLists()
- CampaignMonitor::getCustomFields in src/
CampaignMonitor.php - Fetch custom fields for a given list, then store this information locally in the list cache. The information is stored as a keyed array on the list array under the "CustomFields" key.
- CampaignMonitor::getExtendedList in src/
CampaignMonitor.php - Get all information available about a given list. This is done by calling getLists(), getListDetails() and getCustomFields(), hence building the local list cache.
- CampaignMonitor::getListDetails in src/
CampaignMonitor.php - Gets list details from Campaign Monitor. This information is retrieved from the local cache and may be outdated. It fetches the unsubscribe link, confirmation success page and confirmed opt-in options.
File
- src/
CampaignMonitor.php, line 262 - Implementation of the CampaignMonitor class, which is a wrapper class for Campaign Monitor v3 API. It's implemented as a Singleton class and instances are created using the account variables and the static function getConnector(). An example:.
Class
Namespace
Drupal\campaignmonitorCode
public function getLists() {
if (empty($this->lists)) {
$cid = 'mymodule_example:' . \Drupal::languageManager()
->getCurrentLanguage()
->getId();
if ($cache = \Drupal::cache()
->get('campaignmonitor_lists')) {
// Cache information found.
$this->lists = $cache->data;
}
else {
// Create list object and get the lists, then save the lists in the
// local cache.
if ($obj = $this
->createClientObj()) {
$result = $obj
->get_lists();
if ($result
->was_successful()) {
foreach ($result->response as $list) {
$this->lists[$list->ListID] = [
'name' => $list->Name,
];
}
\Drupal::cache()
->set('campaignmonitor_lists', $this->lists);
}
else {
$this
->addError(WATCHDOG_ERROR, $result->response->Message, $result->http_status_code);
}
}
else {
return [];
}
}
}
return $this->lists;
}