RatePermissions.php in Rate 8
File
src/RatePermissions.php
View source
<?php
namespace Drupal\rate;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
class RatePermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
protected $config;
protected $entityTypeManager;
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager) {
$this->config = $config_factory
->get('rate.settings');
$this->entityTypeManager = $entity_type_manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('entity_type.manager'));
}
public function permissions() {
$permissions = [];
$enabled_types_widgets = $this->config
->get('enabled_types_widgets');
if (!empty($enabled_types_widgets)) {
foreach ($enabled_types_widgets as $entity_type_id => $entity_types) {
foreach ($entity_types as $bundle => $settings) {
if ($bundle == $entity_type_id) {
$perm_index = 'cast rate vote on ' . $entity_type_id . ' of ' . $bundle;
$permissions[$perm_index] = [
'title' => $this
->t('Can vote on :type', [
':type' => $entity_type_id,
]),
];
}
else {
$perm_index = 'cast rate vote on ' . $entity_type_id . ' of ' . $bundle;
$permissions[$perm_index] = [
'title' => $this
->t('Can vote on :type type of :bundle', [
':bundle' => $bundle,
':type' => $entity_type_id,
]),
];
}
}
}
}
return $permissions;
}
}
Classes
Name |
Description |
RatePermissions |
Class to return permissions based on entity type for rate module. |