You are here

class ContactPermissions in RedHen CRM 8

Hierarchy

Expanded class hierarchy of ContactPermissions

File

modules/redhen_contact/src/ContactPermissions.php, line 8

Namespace

Drupal\redhen_contact
View source
class ContactPermissions {
  use StringTranslationTrait;

  /**
   * Returns an array of RedHen contact type permissions.
   *
   * @return array
   *    Returns an array of permissions.
   */
  public function ContactTypePermissions() {
    $perms = [];

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

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

}

Members

Namesort descending Modifiers Type Description Overrides
ContactPermissions::buildPermissions protected function Builds a standard list of permissions for a given contact type.
ContactPermissions::ContactTypePermissions public function Returns an array of RedHen contact 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.