public function MailingListController::members in Mailgun 8
Return a list of the mailing list members.
Parameters
string $list_address: Mailgun list address.
Return value
array Page build array.
1 string reference to 'MailingListController::members'
- mailgun_mailing_lists.routing.yml in modules/
mailgun_mailing_lists/ mailgun_mailing_lists.routing.yml - modules/mailgun_mailing_lists/mailgun_mailing_lists.routing.yml
File
- modules/
mailgun_mailing_lists/ src/ Controller/ MailingListController.php, line 62
Class
- MailingListController
- Provides page callbacks for Mailgun Mailing Lists module.
Namespace
Drupal\mailgun_mailing_lists\ControllerCode
public function members($list_address) {
try {
$rows = [];
$members = $this->mailgunClient
->mailingList()
->member()
->index($list_address)
->getItems();
if (!empty($members)) {
foreach ($members as $member) {
$rows[] = [
'address' => $member
->getAddress(),
'subscribed' => $member
->isSubscribed() ? $this
->t('Yes') : $this
->t('No'),
];
}
return [
'#theme' => 'table',
'#rows' => $rows,
'#header' => [
$this
->t('Address'),
$this
->t('Subscribed'),
],
];
}
else {
return [
'#markup' => $this
->t('No members yet.'),
];
}
} catch (HttpClientException $e) {
$message = $this
->t('Could not retrieve the members list: @message.', [
'@message' => $e
->getMessage(),
]);
$this->logger
->error($message);
return [
'#markup' => $message,
];
}
}