You are here

public function CampaignMonitor::getListDetails in Campaign Monitor 8

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.

Parameters

string $listId: The Campaign Monitor list ID.

Return value

mixed array | FALSE An array with the information or FALSE on failure.

2 calls to CampaignMonitor::getListDetails()
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::updateList in src/CampaignMonitor.php
Update remote list information. The options array should have the fields "Title", "UnsubscribePage", "ConfirmedOptIn" and "ConfirmationSuccessPage". If you do not wish to set these use an empty string.

File

src/CampaignMonitor.php, line 308
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

CampaignMonitor

Namespace

Drupal\campaignmonitor

Code

public function getListDetails($listId) {

  // If lists have not been loaded yet, get them as they build the basic
  // cache.
  if (empty($this->lists)) {
    $this
      ->getLists();
  }

  // Test that the listId is valid.
  if (!isset($this->lists[$listId])) {
    $this
      ->addError(WATCHDOG_ERROR, t('Unknown list id @listID.', [
      '@listID' => $listId,
    ]));
    return FALSE;
  }

  // If list details are not set, create list object and fetch the information
  // from the Campaign Monitor servers.
  if (!isset($this->lists[$listId]['details'])) {
    if ($obj = $this
      ->createListObj($listId)) {
      $result = $obj
        ->get();
      if ($result
        ->was_successful()) {

        // Convert the return object into a keyed array.
        $this->lists[$listId]['details'] = [];
        foreach ($result->response as $key => $value) {
          if (!in_array($key, [
            'ListID',
            'Title',
          ])) {
            $this->lists[$listId]['details'][$key] = $value;
          }
        }

        // Update the cache with list details.
        \Drupal::cache()
          ->set('campaignmonitor_lists', $this->lists);
      }
      else {
        $this
          ->addError(WATCHDOG_ERROR, $result->response->Message, $result->http_status_code);
        return FALSE;
      }
    }
    else {
      return FALSE;
    }
  }
  return $this->lists[$listId]['details'];
}