You are here

protected function LikeDislikePermissions::addLikeAndDislikePermission in Like & Dislike 8

Adds vote types permissions for given entity type and bundles.

Parameters

array &$permissions: An array of created permissions.

\Drupal\votingapi\VoteTypeInterface[] $vote_types: An array of voting types.

string $entity_type_id: The entity type ID.

array $bundles: An array of bundles. Empty in case entity has no bundles.

1 call to LikeDislikePermissions::addLikeAndDislikePermission()
LikeDislikePermissions::buildPermissions in src/LikeDislikePermissions.php
Builds a list of like_and_dislike related permissions.

File

src/LikeDislikePermissions.php, line 98

Class

LikeDislikePermissions
Provides dynamic permissions for nodes of different types.

Namespace

Drupal\like_and_dislike

Code

protected function addLikeAndDislikePermission(array &$permissions, array $vote_types, $entity_type_id, array $bundles) {
  $entity_type = $this->entityTypeManager
    ->getDefinition($entity_type_id, FALSE);

  // The entity type has no bundles other than the default one.
  if (empty($bundles)) {

    /** @var \Drupal\votingapi\VoteTypeInterface $vote_type */
    foreach ($vote_types as $vote_type) {
      $permissions["add or remove {$vote_type->id()} votes on {$entity_type_id}"] = [
        'title' => $this
          ->t('%entity_type_name: add/remove %vote_type_name', [
          '%entity_type_name' => $entity_type
            ->getLabel(),
          '%vote_type_name' => $vote_type
            ->label(),
        ]),
      ];
    }
  }
  else {
    foreach ($bundles as $bundle) {
      $bundle_info = $this->bundleInfoService
        ->getBundleInfo($entity_type_id)[$bundle];

      /** @var \Drupal\votingapi\VoteTypeInterface $vote_type */
      foreach ($vote_types as $vote_type) {
        $permissions["add or remove {$vote_type->id()} votes on {$bundle} of {$entity_type_id}"] = [
          'title' => $this
            ->t('%entity_type (%bundle): add/remove %vote_type', [
            '%entity_type' => $entity_type
              ->getLabel(),
            '%vote_type' => $vote_type
              ->label(),
            '%bundle' => $bundle_info['label'],
          ]),
        ];
      }
    }
  }
}