class RatePermissions in Rate 8
Same name and namespace in other branches
- 8.2 src/RatePermissions.php \Drupal\rate\RatePermissions
Class to return permissions based on entity type for rate module.
@package Drupal\rate
Hierarchy
- class \Drupal\rate\RatePermissions implements ContainerInjectionInterface uses StringTranslationTrait
Expanded class hierarchy of RatePermissions
File
- src/
RatePermissions.php, line 16
Namespace
Drupal\rateView source
class RatePermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* The config factory wrapper to fetch settings.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $config;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs Permissions object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager) {
$this->config = $config_factory
->get('rate.settings');
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('entity_type.manager'));
}
/**
* Get permissions for Rate module.
*
* @return array
* Permissions array.
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RatePermissions:: |
protected | property | The config factory wrapper to fetch settings. | |
RatePermissions:: |
protected | property | The entity type manager. | |
RatePermissions:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
RatePermissions:: |
public | function | Get permissions for Rate module. | |
RatePermissions:: |
public | function | Constructs Permissions object. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |