public function ContributeManager::getMembership in Contribute 8
Get membership status.
Return value
array An associative array containing membership status.
Overrides ContributeManagerInterface::getMembership
File
- src/
ContributeManager.php, line 235
Class
- ContributeManager
- Class ContributeManager.
Namespace
Drupal\contributeCode
public function getMembership() {
$account_type = $this
->getAccountType();
$account_id = $this
->getAccountId() ?: 'anonymous';
$cid = 'contribute.membership.' . md5("{$account_type}.{$account_id}");
$cache = $this->cache
->get($cid);
if ($cache) {
return $cache->data;
}
// Note: Avoiding using the Drupal Association's APIs because they don't
// allow you to query by user or organization name.
// @see https://assoc.drupal.org/api/association_members.json
// @see https://assoc.drupal.org/api/membership/org_partner_memberships.json
$membership = [];
$membership['status'] = FALSE;
if ($account_id != 'anonymous') {
switch ($account_type) {
case 'organization':
if ($badge = $this
->getOrganizationBadge()) {
$membership = [
'status' => TRUE,
'badge' => $badge,
];
}
break;
case 'user':
if ($badge = $this
->getUserBadge()) {
$membership = [
'status' => TRUE,
'badge' => $badge,
];
}
break;
}
}
if ($membership['status']) {
$membership['value'] = $this
->t('<strong>You Rock!</strong> Thank you for purchasing a Drupal Association membership.');
}
else {
$t_args = [
':href_association' => 'https://www.drupal.org/association',
':href_individual' => 'https://www.drupal.org/association/individual-membership',
':href_organization' => 'https://www.drupal.org/association/organization-membership',
':href_donate' => 'https://www.drupal.org/association/donate',
];
$membership['value'] = [
'#markup' => $this
->t('The <a href=":href_association">Drupal Association</a> is dedicated to fostering and supporting the Drupal software project.', $t_args),
];
switch ($account_type) {
case 'organization':
$membership['value']['#markup'] .= '</br></br>' . $this
->t('Organization members are active contributors in the Drupal community. By making your organization or company a member, your team funds the community grants program and you support our work on drupal.org, DrupalCons, and other projects. Together, we unite our global open source community to build and promote Drupal.');
$membership['description'] = [
'#type' => 'link',
'#title' => $this
->t('Become an organization member'),
'#url' => Url::fromUri('https://www.drupal.org/association/organization-membership'),
'#attributes' => [
'class' => [
'button',
'button--small',
'button--primary',
'contribute-status-report-community-info__button',
],
],
];
break;
case 'user':
$membership['value']['#markup'] .= '</br></br>' . $this
->t('As a member, you build our momentum while supporting the Drupal community.') . ' ' . $this
->t('Members fund the community grants program and support our team as we work on Drupal.org, DrupalCons, and other projects. Together, we unite our global open source community to build and promote Drupal.');
$membership['description'] = [
'#type' => 'link',
'#title' => $this
->t('Become an individual member'),
'#url' => Url::fromUri('https://www.drupal.org/association/individual-membership'),
'#attributes' => [
'class' => [
'button',
'button--small',
'button--primary',
'contribute-status-report-community-info__button',
],
],
];
break;
default:
$membership['value']['#markup'] .= ' ' . $this
->t('You can join as an <a href=":href_individual">individual</a> or an <a href=":href_organization">organization member</a>, or <a href=":href_donate">donate</a> directly any amount.', $t_args);
$membership['description'] = [
'#type' => 'link',
'#title' => $this
->t('Support our work'),
'#url' => Url::fromUri('https://www.drupal.org/association/support'),
'#attributes' => [
'class' => [
'button',
'button--small',
'contribute-status-report-community-info__button',
],
],
];
break;
}
}
// Cache membership information.
$this->cache
->set($cid, $membership, strtotime('+1 hour'), [
'contribute',
]);
return $membership;
}