You are here

function acquia_connector_toolbar in Acquia Connector 8.2

Same name and namespace in other branches
  1. 8 acquia_connector.module \acquia_connector_toolbar()
  2. 3.x acquia_connector.module \acquia_connector_toolbar()

Implements hook_toolbar().

File

./acquia_connector.module, line 97
Acquia Connector module.

Code

function acquia_connector_toolbar() {
  $link = [
    '#type' => 'link',
    '#attributes' => [
      'class' => [
        'toolbar-icon',
      ],
    ],
  ];
  $subscription = new Subscription();
  if ($subscription
    ->isActive()) {
    $subscription_data = \Drupal::state()
      ->get('acquia_subscription_data');
    if (is_array($subscription_data['expiration_date']) && isset($subscription_data['active']) && $subscription_data['active'] !== FALSE) {
      $link['#title'] = t('Subscription active (expires @date)', [
        '@date' => \Drupal::service('date.formatter')
          ->format(strtotime($subscription_data['expiration_date']['value']), 'custom', 'Y/n/j'),
      ]);
      $link['#attributes']['class'][] = 'acquia-active-subscription';
      $link['#url'] = Url::fromUri('https://cloud.acquia.com/app/develop/applications/' . $subscription_data['uuid']);
    }
  }
  if (empty($link['#url'])) {
    $link['#title'] = t('Subscription not active');
    $link['#attributes']['class'][] = 'acquia-inactive-subscription';
    $link['#url'] = Url::fromUri('https://cloud.acquia.com');
  }
  return [
    'acquia_connector' => [
      '#type' => 'toolbar_item',
      'tab' => $link,
      '#weight' => 200,
      '#cache' => [
        'contexts' => [
          'user.roles:authenticated',
        ],
      ],
      '#attached' => [
        'library' => [
          'acquia_connector/acquia_connector.icons',
        ],
      ],
    ],
  ];
}