Skip to content
Snippets Groups Projects

Issue #3326924: The provided API key is invalid

+ 182
182
@@ -145,74 +145,80 @@ class AdminSettingsForm extends ConfigFormBase {
if (!$this->mailchimpTransactionalAPI->isLibraryInstalled()) {
$this->messenger()->addWarning($this->t('The Mailchimp Transactional PHP library is not installed. Please see installation directions in README.md'));
}
elseif ($key) {
$mail_system_path = Url::fromRoute('mailsystem.settings');
$usage = [];
foreach ($this->mailchimpTransactional->getMailSystems() as $system) {
if ($this->mailConfigurationUsesMailchimpTransactionalMail($system)) {
$system['sender'] = $this->getPluginLabel($system['sender']);
$system['formatter'] = $this->getPluginLabel($system['formatter']);
$usage[] = $system;
}
}
if (!empty($usage)) {
$usage_array = [
'#theme' => 'table',
'#header' => [
$this->t('Key'),
$this->t('Sender'),
$this->t('Formatter'),
],
'#rows' => $usage,
];
$form['mailchimp_transactional_status'] = [
'#type' => 'markup',
'#markup' => $this->t(
'Mailchimp Transactional is currently configured to be used by the
following Module Keys. To change these settings or configure
additional systems to use Mailchimp Transactional, use
<a href=":link">Mail System</a>.<br/><br/>@table',
[
':link' => $mail_system_path->toString(),
'@table' => $this->renderer->render($usage_array),
]),
];
}
elseif (!$form_state->get('rebuild')) {
$this->messenger()->addWarning($this->t(
'PLEASE NOTE: Mailchimp Transactional is not currently configured
for use by Drupal. In order to route your email through Mailchimp
Transactional, you must configure at least one MailSystemInterface
(other than mailchimp_transactional) to use "Mailchimp Transactional
mailer" in <a href=":link">Mail System</a>, or you will only be able
to send Test emails through Mailchimp Transactional.',
[':link' => $mail_system_path->toString()]
));
$hasValidKey = $key && !$this->mailchimpTransactionalAPI->isApiKeyValid($key);
if ($hasValidKey) {
$this->messenger()->addWarning($this->t('The provided Mailchimp Transactional API key is invalid'));
}
$mail_system_path = Url::fromRoute('mailsystem.settings');
$usage = [];
foreach ($this->mailchimpTransactional->getMailSystems() as $system) {
if ($this->mailConfigurationUsesMailchimpTransactionalMail($system)) {
$system['sender'] = $this->getPluginLabel($system['sender']);
$system['formatter'] = $this->getPluginLabel($system['formatter']);
$usage[] = $system;
}
$form['email_options'] = [
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#title' => $this->t('Email options'),
];
$form['email_options']['mailchimp_transactional_from'] = [
'#title' => $this->t('From address'),
'#type' => 'textfield',
'#description' => $this->t(
'The sender email address. If this address has not been verified,
messages will be queued and not sent until it is. This address will appear
in the "from" field, and any emails sent through Mailchimp Transactional
with a "from" address will have that address moved to the Reply-To field.'
),
'#default_value' => $config->get('mailchimp_transactional_from_email'),
}
if (!empty($usage)) {
$usage_array = [
'#theme' => 'table',
'#header' => [
$this->t('Key'),
$this->t('Sender'),
$this->t('Formatter'),
],
'#rows' => $usage,
];
$form['email_options']['mailchimp_transactional_from_name'] = [
'#type' => 'textfield',
'#title' => $this->t('From name'),
'#default_value' => $config->get('mailchimp_transactional_from_name'),
'#description' => $this->t('Optionally enter a from name to be used.'),
$form['mailchimp_transactional_status'] = [
'#type' => 'markup',
'#markup' => $this->t(
'Mailchimp Transactional is currently configured to be used by the
following Module Keys. To change these settings or configure
additional systems to use Mailchimp Transactional, use
<a href=":link">Mail System</a>.<br/><br/>@table',
[
':link' => $mail_system_path->toString(),
'@table' => $this->renderer->render($usage_array),
]),
];
}
elseif (!$form_state->get('rebuild')) {
$this->messenger()->addWarning($this->t(
'PLEASE NOTE: Mailchimp Transactional is not currently configured
for use by Drupal. In order to route your email through Mailchimp
Transactional, you must configure at least one MailSystemInterface
(other than mailchimp_transactional) to use "Mailchimp Transactional
mailer" in <a href=":link">Mail System</a>, or you will only be able
to send Test emails through Mailchimp Transactional.',
[':link' => $mail_system_path->toString()]
));
}
$form['email_options'] = [
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#title' => $this->t('Email options'),
];
$form['email_options']['mailchimp_transactional_from'] = [
'#title' => $this->t('From address'),
'#type' => 'textfield',
'#description' => $this->t(
'The sender email address. If this address has not been verified,
messages will be queued and not sent until it is. This address will appear
in the "from" field, and any emails sent through Mailchimp Transactional
with a "from" address will have that address moved to the Reply-To field.'
),
'#default_value' => $config->get('mailchimp_transactional_from_email'),
];
$form['email_options']['mailchimp_transactional_from_name'] = [
'#type' => 'textfield',
'#title' => $this->t('From name'),
'#default_value' => $config->get('mailchimp_transactional_from_name'),
'#description' => $this->t('Optionally enter a from name to be used.'),
];
$sub_accounts_options = [];
if ($hasValidKey) {
$sub_accounts = $this->mailchimpTransactionalAPI->getSubAccounts();
$sub_accounts_options = [];
if (!empty($sub_accounts)) {
$sub_accounts_options = ['_none' => '-- Select --'];
foreach ($sub_accounts as $account) {
@@ -221,125 +227,124 @@ class AdminSettingsForm extends ConfigFormBase {
}
}
}
elseif ($config->get('mailchimp_transactional_subaccount')) {
$config->set('mailchimp_transactional_subaccount', FALSE)->save();
}
if (!empty($sub_accounts_options)) {
$form['email_options']['mailchimp_transactional_subaccount'] = [
'#type' => 'select',
'#title' => $this->t('Subaccount'),
'#options' => $sub_accounts_options,
'#default_value' => $config->get('mailchimp_transactional_subaccount'),
'#description' => $this->t('Choose a subaccount to send through.'),
];
}
$formats = filter_formats();
$options = ['' => $this->t('-- Select --')];
foreach ($formats as $v => $format) {
$options[$v] = $format->get('name');
}
$form['email_options']['mailchimp_transactional_filter_format'] = [
}
if ($sub_accounts_options !== []) {
$form['email_options']['mailchimp_transactional_subaccount'] = [
'#type' => 'select',
'#title' => $this->t('Input format'),
'#description' => $this->t('If selected, the input format to apply to the message body before sending to the Mailchimp Transactional API.'),
'#options' => $options,
'#default_value' => [$config->get('mailchimp_transactional_filter_format')],
];
$form['send_options'] = [
'#title' => $this->t('Send options'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
];
$form['send_options']['mailchimp_transactional_track_opens'] = [
'#title' => $this->t('Track opens'),
'#type' => 'checkbox',
'#description' => $this->t('Whether or not to turn on open tracking for messages.'),
'#default_value' => $config->get('mailchimp_transactional_track_opens'),
];
$form['send_options']['mailchimp_transactional_track_clicks'] = [
'#title' => $this->t('Track clicks'),
'#type' => 'checkbox',
'#description' => $this->t('Whether or not to turn on click tracking for messages.'),
'#default_value' => $config->get('mailchimp_transactional_track_clicks'),
];
$form['send_options']['mailchimp_transactional_url_strip_qs'] = [
'#title' => $this->t('Strip query string'),
'#type' => 'checkbox',
'#description' => $this->t('Whether or not to strip the query string from URLs when aggregating tracked URL data.'),
'#default_value' => $config->get('mailchimp_transactional_url_strip_qs'),
];
$form['send_options']['mailchimp_transactional_mail_key_blacklist'] = [
'#title' => $this->t('Content logging blacklist'),
'#type' => 'textarea',
'#description' => $this->t('Comma delimited list of Drupal mail keys to exclude content logging for. CAUTION: Removing the default password reset key may expose a security risk.'),
'#default_value' => $config->get('mailchimp_transactional_mail_key_blacklist'),
'#title' => $this->t('Subaccount'),
'#options' => $sub_accounts_options,
'#default_value' => $config->get('mailchimp_transactional_subaccount'),
'#description' => $this->t('Choose a subaccount to send through.'),
];
}
$formats = filter_formats();
$options = ['' => $this->t('-- Select --')];
foreach ($formats as $v => $format) {
$options[$v] = $format->get('name');
}
$form['email_options']['mailchimp_transactional_filter_format'] = [
'#type' => 'select',
'#title' => $this->t('Input format'),
'#description' => $this->t('If selected, the input format to apply to the message body before sending to the Mailchimp Transactional API.'),
'#options' => $options,
'#default_value' => [$config->get('mailchimp_transactional_filter_format')],
];
$form['send_options'] = [
'#title' => $this->t('Send options'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
];
$form['send_options']['mailchimp_transactional_track_opens'] = [
'#title' => $this->t('Track opens'),
'#type' => 'checkbox',
'#description' => $this->t('Whether or not to turn on open tracking for messages.'),
'#default_value' => $config->get('mailchimp_transactional_track_opens'),
];
$form['send_options']['mailchimp_transactional_track_clicks'] = [
'#title' => $this->t('Track clicks'),
'#type' => 'checkbox',
'#description' => $this->t('Whether or not to turn on click tracking for messages.'),
'#default_value' => $config->get('mailchimp_transactional_track_clicks'),
];
$form['send_options']['mailchimp_transactional_url_strip_qs'] = [
'#title' => $this->t('Strip query string'),
'#type' => 'checkbox',
'#description' => $this->t('Whether or not to strip the query string from URLs when aggregating tracked URL data.'),
'#default_value' => $config->get('mailchimp_transactional_url_strip_qs'),
];
$form['send_options']['mailchimp_transactional_mail_key_blacklist'] = [
'#title' => $this->t('Content logging blacklist'),
'#type' => 'textarea',
'#description' => $this->t('Comma delimited list of Drupal mail keys to exclude content logging for. CAUTION: Removing the default password reset key may expose a security risk.'),
'#default_value' => $config->get('mailchimp_transactional_mail_key_blacklist'),
];
$form['send_options']['mailchimp_transactional_log_defaulted_sends'] = [
'#title' => $this->t('Log sends from module/key pairs that are not registered independently in mailsystem.'),
'#type' => 'checkbox',
'#description' => $this->t('If you select Mailchimp Transactional as the site-wide default email sender in %mailsystem and check this box, any messages that are sent through Mailchimp Transactional using module/key pairs that are not specifically registered in mailsystem will cause a message to be written to the system log (type: Mailchimp Transactional, severity: info). Enable this to identify keys and modules for automated emails for which you would like to have more granular control. It is not recommended to leave this box checked for extended periods, as it slows Mailchimp Transactional and can clog your logs.',
[
'%mailsystem' => Link::fromTextAndUrl($this->t('Mail System'), $mail_system_path)->toString(),
]),
'#default_value' => $config->get('mailchimp_transactional_log_defaulted_sends'),
];
$form['send_options']['mailchimp_transactional_log_defaulted_sends'] = [
'#title' => $this->t('Log sends from module/key pairs that are not registered independently in mailsystem.'),
'#type' => 'checkbox',
'#description' => $this->t('If you select Mailchimp Transactional as the site-wide default email sender in %mailsystem and check this box, any messages that are sent through Mailchimp Transactional using module/key pairs that are not specifically registered in mailsystem will cause a message to be written to the system log (type: Mailchimp Transactional, severity: info). Enable this to identify keys and modules for automated emails for which you would like to have more granular control. It is not recommended to leave this box checked for extended periods, as it slows Mailchimp Transactional and can clog your logs.',
[
'%mailsystem' => Link::fromTextAndUrl($this->t('Mail System'), $mail_system_path)->toString(),
]),
'#default_value' => $config->get('mailchimp_transactional_log_defaulted_sends'),
];
$form['analytics'] = [
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#title' => $this->t('Google analytics'),
];
$form['analytics']['mailchimp_transactional_analytics_domains'] = [
'#title' => $this->t('Google analytics domains'),
'#type' => 'textfield',
'#description' => $this->t('One or more domains for which any matching URLs will automatically have Google Analytics parameters appended to their query string. Separate each domain with a comma.'),
'#default_value' => $config->get('mailchimp_transactional_analytics_domains'),
];
$form['analytics']['mailchimp_transactional_analytics_campaign'] = [
'#title' => $this->t('Google analytics campaign'),
'#type' => 'textfield',
'#description' => $this->t("The value to set for the utm_campaign tracking parameter. If this isn't provided the messages from address will be used instead."),
'#default_value' => $config->get('mailchimp_transactional_analytics_campaign'),
];
$form['asynchronous_options'] = [
'#title' => $this->t('Asynchronous options'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#attributes' => [
'id' => ['mailchimp-transactional-async-options'],
],
];
$form['asynchronous_options']['mailchimp_transactional_process_async'] = [
'#title' => $this->t('Queue outgoing messages'),
'#type' => 'checkbox',
'#description' => $this->t('When set, emails will not be immediately sent. Instead, they will be placed in a queue and sent when cron is triggered.'),
'#default_value' => $config->get('mailchimp_transactional_process_async'),
];
$form['asynchronous_options']['mailchimp_transactional_batch_log_queued'] = [
'#title' => $this->t('Log queued emails'),
'#type' => 'checkbox',
'#description' => $this->t('Do you want to create a log entry when an email is queued to be sent?'),
'#default_value' => $config->get('mailchimp_transactional_batch_log_queued'),
'#states' => [
'invisible' => [
':input[name="mailchimp_transactional_process_async"]' => ['checked' => FALSE],
],
$form['analytics'] = [
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#title' => $this->t('Google analytics'),
];
$form['analytics']['mailchimp_transactional_analytics_domains'] = [
'#title' => $this->t('Google analytics domains'),
'#type' => 'textfield',
'#description' => $this->t('One or more domains for which any matching URLs will automatically have Google Analytics parameters appended to their query string. Separate each domain with a comma.'),
'#default_value' => $config->get('mailchimp_transactional_analytics_domains'),
];
$form['analytics']['mailchimp_transactional_analytics_campaign'] = [
'#title' => $this->t('Google analytics campaign'),
'#type' => 'textfield',
'#description' => $this->t("The value to set for the utm_campaign tracking parameter. If this isn't provided the messages from address will be used instead."),
'#default_value' => $config->get('mailchimp_transactional_analytics_campaign'),
];
$form['asynchronous_options'] = [
'#title' => $this->t('Asynchronous options'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#attributes' => [
'id' => ['mailchimp-transactional-async-options'],
],
];
$form['asynchronous_options']['mailchimp_transactional_process_async'] = [
'#title' => $this->t('Queue outgoing messages'),
'#type' => 'checkbox',
'#description' => $this->t('When set, emails will not be immediately sent. Instead, they will be placed in a queue and sent when cron is triggered.'),
'#default_value' => $config->get('mailchimp_transactional_process_async'),
];
$form['asynchronous_options']['mailchimp_transactional_batch_log_queued'] = [
'#title' => $this->t('Log queued emails'),
'#type' => 'checkbox',
'#description' => $this->t('Do you want to create a log entry when an email is queued to be sent?'),
'#default_value' => $config->get('mailchimp_transactional_batch_log_queued'),
'#states' => [
'invisible' => [
':input[name="mailchimp_transactional_process_async"]' => ['checked' => FALSE],
],
];
$form['asynchronous_options']['mailchimp_transactional_queue_worker_timeout'] = [
'#title' => $this->t('Queue worker timeout'),
'#type' => 'textfield',
'#size' => '12',
'#description' => $this->t('Number of seconds to spend processing messages during cron. Zero or negative values are not allowed.'),
'#default_value' => $config->get('mailchimp_transactional_queue_worker_timeout'),
'#states' => [
'invisible' => [
':input[name="mailchimp_transactional_process_async"]' => ['checked' => FALSE],
],
],
];
$form['asynchronous_options']['mailchimp_transactional_queue_worker_timeout'] = [
'#title' => $this->t('Queue worker timeout'),
'#type' => 'textfield',
'#size' => '12',
'#description' => $this->t('Number of seconds to spend processing messages during cron. Zero or negative values are not allowed.'),
'#default_value' => $config->get('mailchimp_transactional_queue_worker_timeout'),
'#states' => [
'invisible' => [
':input[name="mailchimp_transactional_process_async"]' => ['checked' => FALSE],
],
];
}
],
];
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
'#type' => 'submit',
@@ -353,11 +358,6 @@ class AdminSettingsForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$api_key = $form_state->getValue('mailchimp_transactional_api_key');
if ($this->mailchimpTransactionalAPI->isApiKeyValid($api_key) == FALSE) {
$form_state->setErrorByName('mailchimp_transactional_api_key', $this->t('The provided API key is invalid'));
}
// Don't save the API key if it's overridden.
$config = $this->configFactory()->get('mailchimp_transactional.settings');
if ($config->hasOverrides('mailchimp_transactional_api_key')) {
Loading