You are here

public function SubscriptionController::tabAccess in Message Subscribe 8

Access controller for subscription management tabs.

Parameters

\Drupal\Core\Session\AccountInterface $user: The user account session.

\Drupal\flag\FlagInterface $flag: (optional) The flag for which to display the view.

Return value

\Drupal\Core\Access\AccessResultInterface Returns TRUE if access is granted.

1 string reference to 'SubscriptionController::tabAccess'
message_subscribe_ui.routing.yml in message_subscribe_ui/message_subscribe_ui.routing.yml
message_subscribe_ui/message_subscribe_ui.routing.yml

File

message_subscribe_ui/src/Controller/SubscriptionController.php, line 93

Class

SubscriptionController
Default controller for the message_subscribe_ui module.

Namespace

Drupal\message_subscribe_ui\Controller

Code

public function tabAccess(AccountInterface $user, FlagInterface $flag = NULL) {
  if (!$flag) {

    // We are inside /message-subscribe so get the first flag.
    $flags = $this->subscribers
      ->getFlags();
    $flag = reset($flags);
  }
  if (!$flag) {

    // No flag, or flag is disabled.
    return AccessResult::forbidden();
  }
  if (!$flag
    ->status()) {

    // The flag is disabled.
    return AccessResult::forbidden();
  }
  if ($this->currentUser
    ->hasPermission('administer message subscribe')) {
    return AccessResult::allowed();
  }
  if (!$flag
    ->actionAccess('unflag', $user) || $user
    ->id() != $this->currentUser
    ->id()) {
    return AccessResult::forbidden();
  }
  return AccessResult::allowed();
}