You are here

class ReferencePermissions in Bibliography & Citation 8

Same name and namespace in other branches
  1. 2.0.x modules/bibcite_entity/src/ReferencePermissions.php \Drupal\bibcite_entity\ReferencePermissions

Provides dynamic permissions for References of different types.

Hierarchy

Expanded class hierarchy of ReferencePermissions

File

modules/bibcite_entity/src/ReferencePermissions.php, line 11

Namespace

Drupal\bibcite_entity
View source
class ReferencePermissions {
  use StringTranslationTrait;

  /**
   * Returns an array of Reference type permissions.
   *
   * @return array
   *   The Reference type permissions.
   *
   * @see \Drupal\user\PermissionHandlerInterface::getPermissions()
   */
  public function referenceTypePermissions() {
    $perms = [];

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

  /**
   * Returns a list of Reference permissions for a given type.
   *
   * @param \Drupal\bibcite_entity\Entity\ReferenceType $type
   *   The reference type.
   *
   * @return array
   *   An associative array of permission names and descriptions.
   */
  protected function buildPermissions(ReferenceType $type) {
    $type_id = $type
      ->id();
    $type_params = [
      '%type_name' => $type
        ->label(),
    ];
    return [
      "create {$type_id} bibcite_reference" => [
        'title' => $this
          ->t('%type_name: Create new Reference entity', $type_params),
      ],
      "edit own {$type_id} bibcite_reference" => [
        'title' => $this
          ->t('%type_name: Edit own Reference entity', $type_params),
      ],
      "edit any {$type_id} bibcite_reference" => [
        'title' => $this
          ->t('%type_name: Edit any Reference entity', $type_params),
      ],
      "delete own {$type_id} bibcite_reference" => [
        'title' => $this
          ->t('%type_name: Delete own Reference entity', $type_params),
      ],
      "delete any {$type_id} bibcite_reference" => [
        'title' => $this
          ->t('%type_name: Delete any Reference entity', $type_params),
      ],
      "view bibcite_reference {$type_id} revisions" => [
        'title' => $this
          ->t('%type_name: View revisions', $type_params),
        'description' => t('To view a revision, you also need permission to view the reference item.'),
      ],
      "revert bibcite_reference {$type_id} revisions" => [
        'title' => $this
          ->t('%type_name: Revert revisions', $type_params),
        'description' => t('To revert a revision, you also need permission to edit the reference item.'),
      ],
      "delete bibcite_reference {$type_id} revisions" => [
        'title' => $this
          ->t('%type_name: Delete revisions', $type_params),
        'description' => $this
          ->t('To delete a revision, you also need permission to delete the reference item.'),
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ReferencePermissions::buildPermissions protected function Returns a list of Reference permissions for a given type.
ReferencePermissions::referenceTypePermissions public function Returns an array of Reference 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.