/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $list = $form_state->get('list'); $webhook_actions = $form_state->getValue('webhook_actions'); $actions = array(); foreach ($webhook_actions as $webhook_id => $enable) { $actions[$webhook_id] = $enable === 1; } $result = FALSE; if (count($actions) > 0) { $webhook_url = mailchimp_webhook_url(); $webhooks = mailchimp_webhook_get($list['id']); if (!empty($webhooks)) { foreach ($webhooks as $webhook) { if ($webhook['url'] == $webhook_url) { // Delete current webhook. mailchimp_webhook_delete($list['id'], mailchimp_webhook_url()); } } } // Add webhook with enabled actions. $result = mailchimp_webhook_add($list['id'], mailchimp_webhook_url(), $actions); } if ($result) { drupal_set_message(t('Webhooks for list "%name" have been updated.', array('%name' => $list['name']))); } else { drupal_set_message(t('Unable to update webhooks for list "%name".', array('%name' => $list['name'])), 'warning'); } $form_state->setRedirect('mailchimp_lists.overview'); }
/** * Tests deletion of a webhook. */ public function testDeleteWebhook() { $list_id = DrupalMailchimpLists::TEST_LIST_A; $url = 'http://example.org/web-hook-new'; $actions = array(); $sources = array(); mailchimp_webhook_add($list_id, $url, $actions, $sources); $webhook_deleted = mailchimp_webhook_delete($list_id, $url); $this->assertTrue($webhook_deleted, 'Tested webhook deletion.'); $found_webhook = FALSE; $webhooks = mailchimp_webhook_get($list_id); foreach ($webhooks as $webhook) { if ($webhook['url'] == $url) { $found_webhook = TRUE; } } $this->assertFalse($found_webhook, 'Tested removal of webhook.'); }