Skip to content

Commit

Permalink
Merge pull request #365 from UN-OCHA/develop
Browse files Browse the repository at this point in the history
Develop -> Main
  • Loading branch information
lazysoundsystem committed Jun 8, 2022
2 parents 78a8dbe + 340f975 commit 94bb493
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
}
}

$active_subscriptions = [];
$subscriptions = $form_state->getValue('country_updates');
foreach ($subscriptions as $sid => $value) {
if ($sid === '_none') {
Expand All @@ -179,9 +180,12 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
}
else {
$this->subscribe($form_state->getValue('uid'), $sid);
$active_subscriptions[] = $sid;
}
}

$this->unsubscribeOtherCountries($form_state->getValue('uid'), $active_subscriptions);

// Show the user a message.
$this->messenger()->addStatus($this->t('Subscriptions successfully updated.'));
}
Expand Down Expand Up @@ -235,4 +239,28 @@ public function unsubscribe($uid, $sid) {
->execute();
}

/**
* Remove a user subscription.
*
* @param int $uid
* User id.
* @param array $sids
* Subscription id.
*/
public function unsubscribeOtherCountries($uid, array $sids) {
if (empty($sids)) {
$this->database->delete('reliefweb_subscriptions_subscriptions')
->condition('sid', 'country_updates_%', 'LIKE')
->condition('uid', $uid)
->execute();
}
else {
$this->database->delete('reliefweb_subscriptions_subscriptions')
->condition('sid', 'country_updates_%', 'LIKE')
->condition('sid', $sids, 'NOT IN')
->condition('uid', $uid)
->execute();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -541,3 +541,17 @@ legend.form-required::after {
form:not(.rw-entity-form-altered) .form-actions.form-item {
margin-top: var(--cd-flow-space, 2.5rem);
}

/**
* Unsubscribe form.
*
* These rules are place here because this CSS is loaded globally.
*/
.unsubscribe-form .form-checkboxes .form-type-checkbox {
display: block;
}

/* Cancel button on unsubscribe form */
.unsubscribe-form > .button + a {
margin-left: 1rem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* Style the form in the page where users can subscribe to ReliefWeb
* notifications.
*/
.subscription-form .form-checkboxes .form-type-checkbox,
.unsubscribe-form .form-checkboxes .form-type-checkbox {
.subscription-form .form-checkboxes .form-type-checkbox {
display: block;
}

Expand Down Expand Up @@ -34,10 +33,6 @@
.subscription-form .form-actions.form-item {
margin-top: 24px;
}
/* Cancel button on unsubscribe form */
.unsubscribe-form > .button + a {
margin-left: 1rem;
}

/**
* User dashboard.
Expand Down

0 comments on commit 94bb493

Please sign in to comment.