class FieldPermissions in Votingapi Widgets 8
Field permissions.
Hierarchy
- class \Drupal\votingapi_widgets\FieldPermissions implements ContainerInjectionInterface uses StringTranslationTrait
Expanded class hierarchy of FieldPermissions
File
- src/
FieldPermissions.php, line 13
Namespace
Drupal\votingapi_widgetsView source
class FieldPermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* The FieldPermissionsService.
*
* @var \Drupal\field_permissions\FieldPermissionsService
*/
protected $fieldManager;
/**
* Constructs a FieldPermissionsService instance.
*/
public function __construct(EntityFieldManager $field_manager) {
$this->fieldManager = $field_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_field.manager'));
}
/**
* Implements permissions callback for field_permissions.permissions.yml.
*
* @return array
* Add custom permissions.
*/
public function permissions() {
$map = $this->fieldManager
->getFieldMapByFieldType('voting_api_field');
$perms = [];
foreach ($map as $entity_type => $info) {
foreach ($info as $field_name => $field_info) {
foreach ($field_info['bundles'] as $bundle) {
$perms['vote on ' . $entity_type . ':' . $bundle . ':' . $field_name] = [
'title' => $this
->t('Vote on type @type from bundle @bundle in field @field', [
'@type' => $entity_type,
'@bundle' => $bundle,
'@field' => $field_name,
]),
];
$perms['edit own vote on ' . $entity_type . ':' . $bundle . ':' . $field_name] = [
'title' => $this
->t('Edit vote on type @type from bundle @bundle in field @field', [
'@type' => $entity_type,
'@bundle' => $bundle,
'@field' => $field_name,
]),
];
$perms['clear own vote on ' . $entity_type . ':' . $bundle . ':' . $field_name] = [
'title' => $this
->t('Clear vote on type @type from bundle @bundle in field @field', [
'@type' => $entity_type,
'@bundle' => $bundle,
'@field' => $field_name,
]),
];
$perms['edit voting status on ' . $entity_type . ':' . $bundle . ':' . $field_name] = [
'title' => $this
->t('Open or close voting on type @type from bundle @bundle in field @field', [
'@type' => $entity_type,
'@bundle' => $bundle,
'@field' => $field_name,
]),
];
}
}
}
return $perms;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FieldPermissions:: |
protected | property | The FieldPermissionsService. | |
FieldPermissions:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
FieldPermissions:: |
public | function | Implements permissions callback for field_permissions.permissions.yml. | |
FieldPermissions:: |
public | function | Constructs a FieldPermissionsService instance. | |
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. |