You are here

class ContactPermissionsContactPageAccess in Contact Permissions 8

Same name and namespace in other branches
  1. 8.2 src/Access/ContactPermissionsContactPageAccess.php \Drupal\contact_permissions\Access\ContactPermissionsContactPageAccess

Access check for contact_personal_page route.

Hierarchy

Expanded class hierarchy of ContactPermissionsContactPageAccess

1 string reference to 'ContactPermissionsContactPageAccess'
contact_permissions.services.yml in ./contact_permissions.services.yml
contact_permissions.services.yml
1 service uses ContactPermissionsContactPageAccess
access_check.contact_personal in ./contact_permissions.services.yml
Drupal\contact_permissions\Access\ContactPermissionsContactPageAccess

File

src/Access/ContactPermissionsContactPageAccess.php, line 13

Namespace

Drupal\contact_permissions\Access
View source
class ContactPermissionsContactPageAccess extends ContactPageAccess {

  /**
   * {@inheritdoc}
   */
  public function access(UserInterface $user, AccountInterface $account) {

    /* \Drupal\Core\Access\AccessResult $access */
    $access = parent::access($user, $account);
    if (!$access
      ->isAllowed() && $access
      ->getReason() == "The 'access user contact forms' permission is required.") {
      foreach ($user
        ->getRoles() as $role_id) {
        $permission_access = AccessResult::allowedIfHasPermission($account, "use {$role_id} personal contact forms");
        if ($permission_access
          ->isAllowed()) {
          $access = $permission_access;
          break;
        }
      }
    }
    return $access
      ->andif(AccessResult::allowedIfHasPermission($user, 'have a personal contact form'));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContactPageAccess::$configFactory protected property The contact settings config object.
ContactPageAccess::$userData protected property The user data service.
ContactPageAccess::__construct public function Constructs a ContactPageAccess instance.
ContactPermissionsContactPageAccess::access public function Checks access to the given user's contact page. Overrides ContactPageAccess::access