You are here

class RngContactPermissions in RNG Contact 8

Provides dynamic permissions for rng_contact.

Hierarchy

Expanded class hierarchy of RngContactPermissions

File

src/RngContactPermissions.php, line 11

Namespace

Drupal\rng_contact
View source
class RngContactPermissions {
  use StringTranslationTrait;

  /**
   * Provides permissions for contact types.
   *
   * @return array
   *   An array of permissions.
   */
  public function rngContactTypes() {
    $permissions = [];
    foreach (RngContactType::loadMultiple() as $contact_type) {

      /** @var \Drupal\rng_contact\Entity\RngContactTypeInterface $contact_type */
      $id = $contact_type
        ->id();
      $t_args = [
        '%name' => $contact_type
          ->label(),
      ];
      $permissions["create {$id} rng_contact"] = [
        'title' => $this
          ->t('%name: Create new contact', $t_args),
      ];
      $permissions["view own {$id} rng_contact"] = [
        'title' => $this
          ->t('%name: View own contacts', $t_args),
      ];
      $permissions["view any {$id} rng_contact"] = [
        'title' => $this
          ->t('%name: View any contacts', $t_args),
      ];
      $permissions["update own {$id} rng_contact"] = [
        'title' => $this
          ->t('%name: Edit own contacts', $t_args),
      ];
      $permissions["update any {$id} rng_contact"] = [
        'title' => $this
          ->t('%name: Edit any contacts', $t_args),
      ];
      $permissions["delete own {$id} rng_contact"] = [
        'title' => $this
          ->t('%name: Delete own contacts', $t_args),
      ];
      $permissions["delete any {$id} rng_contact"] = [
        'title' => $this
          ->t('%name: Delete any contacts', $t_args),
      ];
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RngContactPermissions::rngContactTypes public function Provides permissions for contact types.
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.