You are here

function apigee_edge_teams_preprocess in Apigee Edge 8

Implements hook_preprocess().

File

modules/apigee_edge_teams/apigee_edge_teams.module, line 191
Copyright 2018 Google Inc.

Code

function apigee_edge_teams_preprocess(&$variables, $hook) {
  if (!in_array($hook, [
    'menu_local_action',
    'menu_local_task',
  ])) {
    return;
  }

  /** @var \Drupal\Core\Url $url */
  $url = $variables['link']['#url'];
  if (!in_array($url
    ->getRouteName(), TeamInactiveStatusSubscriber::getDisabledRoutes())) {
    return;
  }
  $team = \Drupal::routeMatch()
    ->getParameter('team');
  if (!$team || $team
    ->getStatus() !== TeamInterface::STATUS_INACTIVE) {
    return;
  }

  // If a team is inactive, for the local tasks and local actions, set the url
  // to <none>.
  $variables['link']['#url'] = Url::fromRoute('<none>', [], [
    'absolute' => TRUE,
  ]);

  // Add a title attribute.
  $variables['link']['#options']['attributes']['title'] = t('This @team is inactive.', [
    '@team' => \Drupal::entityTypeManager()
      ->getDefinition('team')
      ->getSingularLabel(),
  ]);

  // Add a disabled class.
  $variables['link']['#options']['attributes']['class'][] = 'team-disabled-action';
  $variables['#attached']['library'][] = 'apigee_edge_teams/disabled_action';
}