NO BUG: New Mailchimp API key not recognised

As of September 2024, using Bricks 1.10.3, it is still not displaying the Groups in the builder. The groups are correctly being pulled when you hit Save in the Bricks > Settings > API keys section into the bricks_mailchimp_lists option field, but they don’t show up in the backend.

They are probably supposed to load asynchronously, looking at the source code of form.php:

'options'     => [], // Populate in builder via 'mailchimpList' (PanelControl.vue)

So what I did was to add a bricks/elements/form/controls filter that populates the options from the database. Using this filter will populate the Groups and they will be used when sending a subscription request to MailChimp.

add_filter('bricks/elements/form/controls', function($controls) {
	if (isset($controls['mailchimpGroups']) && isset($controls['mailchimpGroups']['options']) && is_array($controls['mailchimpGroups']['options']) && empty($controls['mailchimpGroups']['options'])) {
		$mailchimp_groups = [];
		foreach (Bricks\Integrations\Form\Actions\Mailchimp::get_list_options() as $list) {
			if (isset($list['groups']) && is_array($list['groups']) && !empty($list['groups'])) {
				$mailchimp_groups += $list['groups'];
			}
		}

		$controls['mailchimpGroups']['options'] = $mailchimp_groups;
	}

    return $controls;
});