public function SubscriptionManager::getChangesList in Simplenews 8
Same name and namespace in other branches
- 8.2 src/Subscription/SubscriptionManager.php \Drupal\simplenews\Subscription\SubscriptionManager::getChangesList()
Converts an array of subscription changes into descriptions.
Parameters
\Drupal\simplenews\SubscriberInterface $subscriber: Simplenews subscriber object.
array $changes: (Optional) Array of changes, each is an array with the keys action and newsletter_id. Defaults to $subscriber->getChanges(), which contains the currently saved changes for the subscriber.
string $langcode: (Optional) Specify the language of the description strings, defaults to the current language.
Return value
string[] Array of description strings describing the changes.
Overrides SubscriptionManagerInterface::getChangesList
File
- src/
Subscription/ SubscriptionManager.php, line 217
Class
- SubscriptionManager
- Default subscription manager.
Namespace
Drupal\simplenews\SubscriptionCode
public function getChangesList(SubscriberInterface $subscriber, $changes = NULL, $langcode = NULL) {
if (empty($langcode)) {
$language = $this->languageManager
->getCurrentLanguage();
$langcode = $language
->getId();
}
if (empty($changes)) {
$changes = $subscriber
->getChanges();
}
$changes_list = array();
foreach ($changes as $newsletter_id => $action) {
$subscribed = $subscriber
->isSubscribed($newsletter_id);
// Get text for each possible combination.
if ($action == 'subscribe' && !$subscribed) {
$line = $this->config
->get('subscription.confirm_combined_line_subscribe_unsubscribed');
}
elseif ($action == 'subscribe' && $subscribed) {
$line = $this->config
->get('subscription.confirm_combined_line_subscribe_subscribed');
}
elseif ($action == 'unsubscribe' && !$subscribed) {
$line = $this->config
->get('subscription.confirm_combined_line_unsubscribe_unsubscribed');
}
elseif ($action == 'unsubscribe' && $subscribed) {
$line = $this->config
->get('subscription.confirm_combined_line_unsubscribe_subscribed');
}
$newsletter_context = array(
'simplenews_subscriber' => $subscriber,
'newsletter' => simplenews_newsletter_load($newsletter_id),
);
$changes_list[$newsletter_id] = $this->token
->replace($line, $newsletter_context, array(
'sanitize' => FALSE,
));
}
return $changes_list;
}