You are here

public function ContributeManager::getContribution in Contribute 8

Get contribution status.

Return value

array An associative array containing contribution status.

Overrides ContributeManagerInterface::getContribution

File

src/ContributeManager.php, line 347

Class

ContributeManager
Class ContributeManager.

Namespace

Drupal\contribute

Code

public function getContribution() {
  $account_type = $this
    ->getAccountType();
  $account_id = $this
    ->getAccountId() ?: 'anonymous';
  $cid = 'contribute.contribution.' . md5("{$account_type}.{$account_id}");
  $cache = $this->cache
    ->get($cid);
  if ($cache) {
    return $cache->data;
  }
  $contribution = [];
  $contribution['status'] = FALSE;
  if ($account_id != 'anonymous') {
    switch ($account_type) {
      case 'organization':
        $organization = $this
          ->getOrganization();
        $contribution['status'] = $organization && (!empty($organization['field_contributions']['value']) || !empty($organization['field_org_issue_credit_count']));
        break;
      case 'user':
        $user = $this
          ->getUser();
        $contribution['status'] = $user && (!empty($user['field_contributed']) || !empty($user['field_drupal_contributions']['value']));
        break;
    }
  }
  if ($contribution['status']) {
    $contribution['value'] = $this
      ->t('<strong>You are a Rockstar!</strong> Thank you for contributing back to Drupal.');
  }
  else {
    $t_args = [
      ':href_about' => 'https://www.drupal.org/about',
    ];
    $contribution['value'] = [
      '#markup' => $this
        ->t('<a href=":href_about">Drupal is an open source project</a>, we don’t have employees to provide Drupal improvements and support. <strong>We depend on our diverse community of passionate volunteers to move the project forward</strong> by working on not just web development and user support but also many other contributions and interests.', $t_args),
    ];
    $contribution['description'] = [
      '#type' => 'link',
      '#title' => $this
        ->t('Ways to get involved'),
      '#url' => Url::fromUri('https://www.drupal.org/contribute'),
      '#attributes' => [
        'class' => [
          'button',
          'button--small',
          'contribute-status-report-community-info__button',
        ],
      ],
    ];
    if ($account_type) {
      $contribution['description']['#attributes']['class'][] = 'button--primary';
    }
  }

  // Cache contribution information.
  $this->cache
    ->set($cid, $contribution, strtotime('+1 hour'), [
    'contribute',
  ]);
  return $contribution;
}