function mailchimp_get_api_object in Mailchimp 8
Same name and namespace in other branches
- 7.5 mailchimp.module \mailchimp_get_api_object()
- 7.2 mailchimp.module \mailchimp_get_api_object()
- 7.3 mailchimp.module \mailchimp_get_api_object()
- 7.4 mailchimp.module \mailchimp_get_api_object()
- 2.x mailchimp.module \mailchimp_get_api_object()
Instantiates a Mailchimp library object.
Return value
\Mailchimp Drupal Mailchimp library object.
29 calls to mailchimp_get_api_object()
- MailchimpAdminSettingsForm::buildForm in src/
Form/ MailchimpAdminSettingsForm.php - Form constructor.
- MailchimpAPITest::testApi in tests/
src/ Functional/ MailchimpAPITest.php - Tests that the test API has been loaded.
- MailchimpCampaignController::stats in modules/
mailchimp_campaign/ src/ Controller/ MailchimpCampaignController.php - View a Mailchimp campaign stats.
- MailchimpListsWebhookSettingsForm::submitForm in modules/
mailchimp_lists/ src/ Form/ MailchimpListsWebhookSettingsForm.php - Form submission handler.
- mailchimp_apikey_ready_access in ./
mailchimp.module - Access callback for mailchimp submodule menu items.
File
- ./
mailchimp.module, line 53 - Mailchimp module.
Code
function mailchimp_get_api_object($classname = 'Mailchimp') {
$mailchimp =& drupal_static(__FUNCTION__);
if (isset($mailchimp) && $mailchimp instanceof $classname) {
return $mailchimp;
}
$config = \Drupal::config('mailchimp.settings');
if ($config
->get('test_mode')) {
$classname = '\\Mailchimp\\Tests\\' . $classname;
}
else {
$classname = '\\Mailchimp\\' . $classname;
}
if (!class_exists($classname)) {
$msg = t('Failed to load Mailchimp PHP library. Please refer to the installation requirements.');
\Drupal::logger('mailchimp')
->error($msg);
\Drupal::messenger()
->addError($msg);
return NULL;
}
$api_key = $config
->get('api_key');
if (!strlen($api_key)) {
\Drupal::logger('mailchimp')
->error('Mailchimp Error: API Key cannot be blank.');
return NULL;
}
$http_options = [
'timeout' => $config
->get('api_timeout'),
'headers' => [
'User-Agent' => _mailchimp_get_user_agent(),
],
];
$mailchimp = new $classname($api_key, 'apikey', $http_options);
return $mailchimp;
}