You are here

class ProfilePermissions in Profile 2 8

Defines a class containing permission callbacks.

Hierarchy

Expanded class hierarchy of ProfilePermissions

File

src/ProfilePermissions.php, line 16
Contains \Drupal\profile\ProfilePermissions.

Namespace

Drupal\profile
View source
class ProfilePermissions {
  use StringTranslationTrait;

  /**
   * Returns an array of profile type permissions.
   *
   * @return array
   */
  public function profileTypePermissions() {
    $perms = array();

    // Generate profile permissions for all profile types.
    foreach (ProfileType::loadMultiple() as $type) {
      $perms += $this
        ->buildPermissions($type);
    }
    return $perms;
  }

  /**
   * Builds a standard list of permissions for a given profile type.
   *
   * @param \Drupal\profile\Entity\ProfileType $profile_type
   *   The machine name of the profile type.
   *
   * @return array
   *   An array of permission names and descriptions.
   */
  protected function buildPermissions(ProfileType $profile_type) {
    $type_id = $profile_type
      ->id();
    $type_params = array(
      '%type' => $profile_type
        ->label(),
    );
    return array(
      "add own {$type_id} profile" => array(
        'title' => $this
          ->t('%type: Add own profile', $type_params),
      ),
      "add any {$type_id} profile" => array(
        'title' => $this
          ->t('%type: Add any profile', $type_params),
      ),
      "view own {$type_id} profile" => array(
        'title' => $this
          ->t('%type: View own profile', $type_params),
      ),
      "view any {$type_id} profile" => array(
        'title' => $this
          ->t('%type: View any profile', $type_params),
      ),
      "edit own {$type_id} profile" => array(
        'title' => $this
          ->t('%type: Edit own profile', $type_params),
      ),
      "edit any {$type_id} profile" => array(
        'title' => $this
          ->t('%type: Edit any profile', $type_params),
      ),
      "delete own {$type_id} profile" => array(
        'title' => $this
          ->t('%type: Delete own profile', $type_params),
      ),
      "delete any {$type_id} profile" => array(
        'title' => $this
          ->t('%type: Delete any profile', $type_params),
      ),
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ProfilePermissions::buildPermissions protected function Builds a standard list of permissions for a given profile type.
ProfilePermissions::profileTypePermissions public function Returns an array of profile type permissions.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.