You are here

class ViewUnpublishedPermissions in view_unpublished 8

Provides dynamic permissions for viewing unpublished nodes per type.

Hierarchy

Expanded class hierarchy of ViewUnpublishedPermissions

File

src/ViewUnpublishedPermissions.php, line 11

Namespace

Drupal\view_unpublished
View source
class ViewUnpublishedPermissions {
  use StringTranslationTrait;

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

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

  /**
   * Returns a list of view unpublished permissions for a given node type.
   *
   * @param \Drupal\node\Entity\NodeType $type
   *   The node type.
   *
   * @return array
   *   An associative array of permission names and descriptions.
   */
  protected function buildPermissions(NodeType $type) {
    $type_id = $type
      ->id();
    $type_params = [
      '%type_name' => $type
        ->label(),
    ];
    return [
      "view any unpublished {$type_id} content" => [
        'title' => $this
          ->t('%type_name: View any unpublished content', $type_params),
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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.
ViewUnpublishedPermissions::buildPermissions protected function Returns a list of view unpublished permissions for a given node type.
ViewUnpublishedPermissions::permissions public function Returns an array of view unpublished permissions per node type.