You are here

ViewProfilesPermsPermissions.php in View profiles permissions 8

Same filename and directory in other branches
  1. 2.0.x src/ViewProfilesPermsPermissions.php

File

src/ViewProfilesPermsPermissions.php
View source
<?php

namespace Drupal\view_profiles_perms;

use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\user\RoleInterface;

/**
 * Provides the permissions for view_profile_perms module.
 */
class ViewProfilesPermsPermissions {
  use StringTranslationTrait;

  /**
   * Get view profiles permissions.
   *
   * @return array
   *   Permissions array.
   */
  public function permissions() {

    // Generate permissions for each user role except authenticated and
    // anonymous.
    $permissions = [];

    /* @var $roles \Drupal\user\RoleInterface[] */
    $roles = user_roles(TRUE);
    unset($roles[RoleInterface::AUTHENTICATED_ID]);
    if (count($roles) < 1) {
      return $permissions;
    }
    foreach ($roles as $role) {
      $role_name = $role
        ->label();
      $role_id = $role
        ->id();
      $permissions["access {$role_id} users profiles"] = [
        'title' => $this
          ->t("Access %role_name users profiles", [
          '%role_name' => $role_name,
        ]),
      ];
    }
    return $permissions;
  }

}

Classes

Namesort descending Description
ViewProfilesPermsPermissions Provides the permissions for view_profile_perms module.