You are here

class PostPermissions in Open Social 10.3.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_post/src/Service/PostPermissions.php \Drupal\social_post\Service\PostPermissions
  2. 8.8 modules/social_features/social_post/src/Service/PostPermissions.php \Drupal\social_post\Service\PostPermissions
  3. 10.0.x modules/social_features/social_post/src/Service/PostPermissions.php \Drupal\social_post\Service\PostPermissions
  4. 10.1.x modules/social_features/social_post/src/Service/PostPermissions.php \Drupal\social_post\Service\PostPermissions
  5. 10.2.x modules/social_features/social_post/src/Service/PostPermissions.php \Drupal\social_post\Service\PostPermissions

Provides dynamic permissions for posts of different types.

Hierarchy

Expanded class hierarchy of PostPermissions

1 string reference to 'PostPermissions'
social_post.services.yml in modules/social_features/social_post/social_post.services.yml
modules/social_features/social_post/social_post.services.yml
1 service uses PostPermissions
social_post.permission_generator in modules/social_features/social_post/social_post.services.yml
Drupal\social_post\Service\PostPermissions

File

modules/social_features/social_post/src/Service/PostPermissions.php, line 12

Namespace

Drupal\social_post\Service
View source
class PostPermissions implements PostPermissionsInterface {
  use StringTranslationTrait;

  /**
   * The post type storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $storage;

  /**
   * PostPermissions constructor.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\Core\StringTranslation\TranslationInterface $translation
   *   The string translation service.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, TranslationInterface $translation) {
    $this->storage = $entity_type_manager
      ->getStorage('post_type');
    $this
      ->setStringTranslation($translation);
  }

  /**
   * {@inheritdoc}
   */
  public function permissions() {
    $permissions = [];

    /** @var \Drupal\social_post\Entity\PostTypeInterface $type */
    foreach ($this->storage
      ->loadMultiple() as $type_id => $type) {
      $permissions["add {$type_id} post entities"] = [
        'title' => $this
          ->t('%type_name: Create new Post entities', [
          '%type_name' => $type
            ->label(),
        ]),
      ];
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PostPermissions::$storage protected property The post type storage.
PostPermissions::permissions public function Generate post permissions for all post types. Overrides PostPermissionsInterface::permissions
PostPermissions::__construct public function PostPermissions constructor.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
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.