You are here

class NodeOptionPremiumPermissions in Node Option Premium 8

Provides dynamic permissions for nodes of different types for promoted.

Hierarchy

Expanded class hierarchy of NodeOptionPremiumPermissions

File

src/NodeOptionPremiumPermissions.php, line 11

Namespace

Drupal\nopremium
View source
class NodeOptionPremiumPermissions {
  use StringTranslationTrait;

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

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

  /**
   * Returns a list of node 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 full {$type_id} premium content" => [
        'title' => $this
          ->t('%type_name: View full premium content', $type_params),
      ],
      "override {$type_id} premium content" => [
        'title' => $this
          ->t('%type_name: Override premium option', $type_params),
      ],
    ];
  }

}

Members

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