You are here

public function CampaignMonitor::getCustomFields in Campaign Monitor 7

Gets custom fields.

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.

Parameters

string $list_id: The Campaign Monitor list ID.

Return value

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

1 call to CampaignMonitor::getCustomFields()
CampaignMonitor::getExtendedList in lib/campaignmonitor.class.inc
Get all information available about a given list.

File

lib/campaignmonitor.class.inc, line 483
Implementation of the CampaignMonitor class.

Class

CampaignMonitor
Implementation of the CampaignMonitor class.

Code

public function getCustomFields($list_id) {

  // If the 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[$list_id])) {
    $this
      ->addError(WATCHDOG_ERROR, t('Unknown list id @listID.', [
      '@listID' => $list_id,
    ]));
    return FALSE;
  }

  // If custom fields are not set on the list, then create the list object and
  // fetch custom fields into a keyed array.
  if (!isset($this->lists[$list_id]['CustomFields'])) {
    if ($obj = $this
      ->createListObj($list_id)) {
      $result = $obj
        ->get_custom_fields();
      if ($result
        ->was_successful()) {
        $this->lists[$list_id]['CustomFields'] = [];
        foreach ($result->response as $field) {
          foreach ($field as $name => $details) {
            $this->lists[$list_id]['CustomFields'][$field->Key][$name] = $details;
          }
        }

        // Update cache with list details.
        cache_set('campaignmonitor_lists', $this->lists, 'cache');
      }
      else {
        $this
          ->addError(WATCHDOG_ERROR, $result->response->Message, $result->http_status_code);
      }
    }
    else {
      return FALSE;
    }
  }
  return $this->lists[$list_id]['CustomFields'];
}